@scriptc/compiler 0.3.1 → 0.3.2

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 (280) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +342 -16
  2. package/dist/backend/executable-features.js +1 -0
  3. package/dist/backend/executable-features.js.map +1 -1
  4. package/dist/backend/literals.d.ts +7 -0
  5. package/dist/backend/literals.js +32 -0
  6. package/dist/backend/literals.js.map +1 -1
  7. package/dist/backend/literals.test.js +17 -1
  8. package/dist/backend/literals.test.js.map +1 -1
  9. package/dist/backend/llvm/alloc.d.ts +15 -4
  10. package/dist/backend/llvm/alloc.js +39 -15
  11. package/dist/backend/llvm/alloc.js.map +1 -1
  12. package/dist/backend/llvm/alloc.test.js +15 -1
  13. package/dist/backend/llvm/alloc.test.js.map +1 -1
  14. package/dist/backend/llvm/appended-array-literals.d.ts +2 -0
  15. package/dist/backend/llvm/appended-array-literals.js +109 -0
  16. package/dist/backend/llvm/appended-array-literals.js.map +1 -0
  17. package/dist/backend/llvm/appended-array-literals.test.d.ts +1 -0
  18. package/dist/backend/llvm/appended-array-literals.test.js +90 -0
  19. package/dist/backend/llvm/appended-array-literals.test.js.map +1 -0
  20. package/dist/backend/llvm/call-lifetimes.d.ts +4 -1
  21. package/dist/backend/llvm/call-lifetimes.js +51 -3
  22. package/dist/backend/llvm/call-lifetimes.js.map +1 -1
  23. package/dist/backend/llvm/classes.js +10 -2
  24. package/dist/backend/llvm/classes.js.map +1 -1
  25. package/dist/backend/llvm/classes.test.js +2 -2
  26. package/dist/backend/llvm/dense-array-access.js +17 -12
  27. package/dist/backend/llvm/dense-array-access.js.map +1 -1
  28. package/dist/backend/llvm/dense-array-access.test.js +15 -2
  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 +11 -2
  32. package/dist/backend/llvm/dyn.js.map +1 -1
  33. package/dist/backend/llvm/emitter.d.ts +43 -2
  34. package/dist/backend/llvm/emitter.js +306 -32
  35. package/dist/backend/llvm/emitter.js.map +1 -1
  36. package/dist/backend/llvm/expr-async.js +122 -6
  37. package/dist/backend/llvm/expr-async.js.map +1 -1
  38. package/dist/backend/llvm/expr-callbacks.d.ts +8 -0
  39. package/dist/backend/llvm/expr-callbacks.js +81 -1
  40. package/dist/backend/llvm/expr-callbacks.js.map +1 -1
  41. package/dist/backend/llvm/expr-calls.d.ts +12 -1
  42. package/dist/backend/llvm/expr-calls.js +126 -54
  43. package/dist/backend/llvm/expr-calls.js.map +1 -1
  44. package/dist/backend/llvm/expr-containers.d.ts +7 -0
  45. package/dist/backend/llvm/expr-containers.js +38 -7
  46. package/dist/backend/llvm/expr-containers.js.map +1 -1
  47. package/dist/backend/llvm/expr-context.d.ts +2 -0
  48. package/dist/backend/llvm/expr-control.d.ts +8 -0
  49. package/dist/backend/llvm/expr-control.js +103 -69
  50. package/dist/backend/llvm/expr-control.js.map +1 -1
  51. package/dist/backend/llvm/expr-dynamic.js +2 -2
  52. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  53. package/dist/backend/llvm/expr-primitives.d.ts +7 -0
  54. package/dist/backend/llvm/expr-primitives.js +30 -26
  55. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  56. package/dist/backend/llvm/expr-records.js +11 -1
  57. package/dist/backend/llvm/expr-records.js.map +1 -1
  58. package/dist/backend/llvm/expr-stream-bridges.d.ts +8 -0
  59. package/dist/backend/llvm/expr-stream-bridges.js +77 -8
  60. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  61. package/dist/backend/llvm/expr-stream-bridges.test.js +49 -1
  62. package/dist/backend/llvm/expr-stream-bridges.test.js.map +1 -1
  63. package/dist/backend/llvm/int32-abi.d.ts +18 -2
  64. package/dist/backend/llvm/int32-abi.js +23 -2
  65. package/dist/backend/llvm/int32-abi.js.map +1 -1
  66. package/dist/backend/llvm/int32-abi.test.js +75 -1
  67. package/dist/backend/llvm/int32-abi.test.js.map +1 -1
  68. package/dist/backend/llvm/lib-dispatch.js +7 -0
  69. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  70. package/dist/backend/llvm/lib-filesystem.js +58 -0
  71. package/dist/backend/llvm/lib-filesystem.js.map +1 -1
  72. package/dist/backend/llvm/lib-shared.js +76 -9
  73. package/dist/backend/llvm/lib-shared.js.map +1 -1
  74. package/dist/backend/llvm/local-array-reads.js +5 -3
  75. package/dist/backend/llvm/local-array-reads.js.map +1 -1
  76. package/dist/backend/llvm/local-union-storage.d.ts +24 -2
  77. package/dist/backend/llvm/local-union-storage.js +127 -12
  78. package/dist/backend/llvm/local-union-storage.js.map +1 -1
  79. package/dist/backend/llvm/local-union-storage.test.js +106 -1
  80. package/dist/backend/llvm/local-union-storage.test.js.map +1 -1
  81. package/dist/backend/llvm/record-results.d.ts +26 -0
  82. package/dist/backend/llvm/record-results.js +252 -0
  83. package/dist/backend/llvm/record-results.js.map +1 -0
  84. package/dist/backend/llvm/reference-effects.js +2 -0
  85. package/dist/backend/llvm/reference-effects.js.map +1 -1
  86. package/dist/backend/llvm/reference-writes.js +15 -9
  87. package/dist/backend/llvm/reference-writes.js.map +1 -1
  88. package/dist/backend/llvm/regions.d.ts +67 -0
  89. package/dist/backend/llvm/regions.js +309 -0
  90. package/dist/backend/llvm/regions.js.map +1 -0
  91. package/dist/backend/llvm/regions.test.d.ts +1 -0
  92. package/dist/backend/llvm/regions.test.js +173 -0
  93. package/dist/backend/llvm/regions.test.js.map +1 -0
  94. package/dist/backend/llvm/shapes.d.ts +34 -7
  95. package/dist/backend/llvm/shapes.js +31 -16
  96. package/dist/backend/llvm/shapes.js.map +1 -1
  97. package/dist/backend/llvm/shapes.test.js +7 -6
  98. package/dist/backend/llvm/shapes.test.js.map +1 -1
  99. package/dist/backend/llvm/split-loops.js +1 -1
  100. package/dist/backend/llvm/split-loops.js.map +1 -1
  101. package/dist/backend/llvm/stack-objects.d.ts +29 -0
  102. package/dist/backend/llvm/stack-objects.js +130 -0
  103. package/dist/backend/llvm/stack-objects.js.map +1 -0
  104. package/dist/backend/llvm/stack-objects.test.d.ts +1 -0
  105. package/dist/backend/llvm/stack-objects.test.js +252 -0
  106. package/dist/backend/llvm/stack-objects.test.js.map +1 -0
  107. package/dist/backend/llvm/string-reads.d.ts +4 -1
  108. package/dist/backend/llvm/string-reads.js +89 -9
  109. package/dist/backend/llvm/string-reads.js.map +1 -1
  110. package/dist/backend/llvm/switch-dispatch.js +5 -4
  111. package/dist/backend/llvm/switch-dispatch.js.map +1 -1
  112. package/dist/backend/llvm/walkers.d.ts +2 -0
  113. package/dist/backend/llvm/walkers.js +4 -2
  114. package/dist/backend/llvm/walkers.js.map +1 -1
  115. package/dist/backend/may-throw.js +1 -0
  116. package/dist/backend/may-throw.js.map +1 -1
  117. package/dist/backend/native/contracts.d.ts +5 -0
  118. package/dist/backend/native/executable.js +16 -1
  119. package/dist/backend/native/executable.js.map +1 -1
  120. package/dist/backend/native/library.js +1 -1
  121. package/dist/backend/native/library.js.map +1 -1
  122. package/dist/backend/native/runtime-inputs.d.ts +1 -1
  123. package/dist/backend/native/runtime-inputs.js +2 -0
  124. package/dist/backend/native/runtime-inputs.js.map +1 -1
  125. package/dist/backend/native-link-info-core.d.ts +1 -0
  126. package/dist/backend/native-link-info-core.js.map +1 -1
  127. package/dist/backend/runtime-abi.d.ts +2 -2
  128. package/dist/backend/runtime-abi.js +2 -2
  129. package/dist/backend/runtime-pack-core.d.ts +1 -0
  130. package/dist/backend/runtime-pack-core.js +1 -0
  131. package/dist/backend/runtime-pack-core.js.map +1 -1
  132. package/dist/backend/runtime-pack-targets.test.js +1 -1
  133. package/dist/backend/runtime-pack.test.js +1 -1
  134. package/dist/backend/target-diagnostics.js +14 -0
  135. package/dist/backend/target-diagnostics.js.map +1 -1
  136. package/dist/backend/target-diagnostics.test.js +13 -0
  137. package/dist/backend/target-diagnostics.test.js.map +1 -1
  138. package/dist/executable/executable-cache.d.ts +1 -0
  139. package/dist/executable/executable-cache.js.map +1 -1
  140. package/dist/frontend/experimental-import.d.ts +12 -0
  141. package/dist/frontend/experimental-import.js +63 -0
  142. package/dist/frontend/experimental-import.js.map +1 -0
  143. package/dist/frontend/lowering/builtin-calls.d.ts +6 -1
  144. package/dist/frontend/lowering/builtin-calls.js +36 -0
  145. package/dist/frontend/lowering/builtin-calls.js.map +1 -1
  146. package/dist/frontend/lowering/builtins/console.d.ts +16 -6
  147. package/dist/frontend/lowering/builtins/console.js +33 -9
  148. package/dist/frontend/lowering/builtins/console.js.map +1 -1
  149. package/dist/frontend/lowering/builtins/errors.js +20 -0
  150. package/dist/frontend/lowering/builtins/errors.js.map +1 -1
  151. package/dist/frontend/lowering/builtins/json.d.ts +2 -2
  152. package/dist/frontend/lowering/builtins/json.js +13 -4
  153. package/dist/frontend/lowering/builtins/json.js.map +1 -1
  154. package/dist/frontend/lowering/builtins/module-calls.js +16 -1
  155. package/dist/frontend/lowering/builtins/module-calls.js.map +1 -1
  156. package/dist/frontend/lowering/builtins/numbers.d.ts +1 -0
  157. package/dist/frontend/lowering/builtins/numbers.js +17 -0
  158. package/dist/frontend/lowering/builtins/numbers.js.map +1 -1
  159. package/dist/frontend/lowering/builtins/operating-system.d.ts +18 -0
  160. package/dist/frontend/lowering/builtins/operating-system.js +361 -1
  161. package/dist/frontend/lowering/builtins/operating-system.js.map +1 -1
  162. package/dist/frontend/lowering/builtins/process.js +15 -3
  163. package/dist/frontend/lowering/builtins/process.js.map +1 -1
  164. package/dist/frontend/lowering/builtins/promises.js +109 -2
  165. package/dist/frontend/lowering/builtins/promises.js.map +1 -1
  166. package/dist/frontend/lowering/builtins/text-codecs.d.ts +3 -4
  167. package/dist/frontend/lowering/builtins/text-codecs.js +3 -4
  168. package/dist/frontend/lowering/builtins/text-codecs.js.map +1 -1
  169. package/dist/frontend/lowering/checked-promise-all.d.ts +10 -3
  170. package/dist/frontend/lowering/checked-promise-all.js +52 -6
  171. package/dist/frontend/lowering/checked-promise-all.js.map +1 -1
  172. package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +6 -3
  173. package/dist/frontend/lowering/class-dynamic-dispatch.js +54 -31
  174. package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
  175. package/dist/frontend/lowering/containers/array-callbacks.js +34 -4
  176. package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
  177. package/dist/frontend/lowering/containers/array-construction.js +8 -4
  178. package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
  179. package/dist/frontend/lowering/containers/array-pipelines.js +1 -1
  180. package/dist/frontend/lowering/containers/array-pipelines.js.map +1 -1
  181. package/dist/frontend/lowering/containers/string-and-regexp.js +91 -0
  182. package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
  183. package/dist/frontend/lowering/cycle-initialization.d.ts +18 -2
  184. package/dist/frontend/lowering/cycle-initialization.js +166 -12
  185. package/dist/frontend/lowering/cycle-initialization.js.map +1 -1
  186. package/dist/frontend/lowering/deferred-module-initializers.js +7 -2
  187. package/dist/frontend/lowering/deferred-module-initializers.js.map +1 -1
  188. package/dist/frontend/lowering/deferred-module-initializers.test.js +28 -0
  189. package/dist/frontend/lowering/deferred-module-initializers.test.js.map +1 -1
  190. package/dist/frontend/lowering/expressions/object-literals.js +5 -56
  191. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
  192. package/dist/frontend/lowering/generator-delegation.d.ts +8 -0
  193. package/dist/frontend/lowering/generator-delegation.js +231 -10
  194. package/dist/frontend/lowering/generator-delegation.js.map +1 -1
  195. package/dist/frontend/lowering/lifetime-regions.d.ts +11 -0
  196. package/dist/frontend/lowering/lifetime-regions.js +216 -0
  197. package/dist/frontend/lowering/lifetime-regions.js.map +1 -0
  198. package/dist/frontend/lowering/lower-array-sort.d.ts +28 -2
  199. package/dist/frontend/lowering/lower-array-sort.js +100 -3
  200. package/dist/frontend/lowering/lower-array-sort.js.map +1 -1
  201. package/dist/frontend/lowering/lower-array-sort.test.js +99 -2
  202. package/dist/frontend/lowering/lower-array-sort.test.js.map +1 -1
  203. package/dist/frontend/lowering/lower-calls.js +72 -102
  204. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  205. package/dist/frontend/lowering/lower-classes.d.ts +4 -3
  206. package/dist/frontend/lowering/lower-classes.js +116 -2
  207. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  208. package/dist/frontend/lowering/lower-console.d.ts +13 -0
  209. package/dist/frontend/lowering/lower-console.js +460 -4
  210. package/dist/frontend/lowering/lower-console.js.map +1 -1
  211. package/dist/frontend/lowering/lower-event-emitter.d.ts +6 -0
  212. package/dist/frontend/lowering/lower-event-emitter.js +124 -38
  213. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
  214. package/dist/frontend/lowering/lower-exprs.js +137 -22
  215. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  216. package/dist/frontend/lowering/lower-generators.d.ts +15 -7
  217. package/dist/frontend/lowering/lower-generators.js +183 -99
  218. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  219. package/dist/frontend/lowering/lower-inspect.d.ts +8 -1
  220. package/dist/frontend/lowering/lower-inspect.js +119 -18
  221. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  222. package/dist/frontend/lowering/lower-modules.js +20 -14
  223. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  224. package/dist/frontend/lowering/lower-stdlib.d.ts +4 -0
  225. package/dist/frontend/lowering/lower-stdlib.js +35 -1
  226. package/dist/frontend/lowering/lower-stdlib.js.map +1 -1
  227. package/dist/frontend/lowering/lower-stmts.js +66 -11
  228. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  229. package/dist/frontend/lowering/lowerer.d.ts +22 -1
  230. package/dist/frontend/lowering/lowerer.js +116 -8
  231. package/dist/frontend/lowering/lowerer.js.map +1 -1
  232. package/dist/frontend/lowering/regex-span-reads.d.ts +12 -0
  233. package/dist/frontend/lowering/regex-span-reads.js +164 -0
  234. package/dist/frontend/lowering/regex-span-reads.js.map +1 -0
  235. package/dist/frontend/lowering/surfaces.js +112 -10
  236. package/dist/frontend/lowering/surfaces.js.map +1 -1
  237. package/dist/frontend/lowering/var-hoisting.d.ts +3 -0
  238. package/dist/frontend/lowering/var-hoisting.js +261 -0
  239. package/dist/frontend/lowering/var-hoisting.js.map +1 -0
  240. package/dist/frontend/pipeline.js +5 -3
  241. package/dist/frontend/pipeline.js.map +1 -1
  242. package/dist/frontend/program.d.ts +3 -2
  243. package/dist/frontend/program.js +23 -5
  244. package/dist/frontend/program.js.map +1 -1
  245. package/dist/frontend/program.test.js +13 -0
  246. package/dist/frontend/program.test.js.map +1 -1
  247. package/dist/frontend/type-mapper.d.ts +13 -1
  248. package/dist/frontend/type-mapper.js +146 -13
  249. package/dist/frontend/type-mapper.js.map +1 -1
  250. package/dist/index.js +1 -0
  251. package/dist/index.js.map +1 -1
  252. package/dist/ir/builtin-effects.js +29 -2
  253. package/dist/ir/builtin-effects.js.map +1 -1
  254. package/dist/ir/builtin-signatures.d.ts +1 -1
  255. package/dist/ir/builtin-signatures.js +145 -15
  256. package/dist/ir/builtin-signatures.js.map +1 -1
  257. package/dist/ir/function-references.test.js +1 -0
  258. package/dist/ir/function-references.test.js.map +1 -1
  259. package/dist/ir/int32-slots.js +1 -0
  260. package/dist/ir/int32-slots.js.map +1 -1
  261. package/dist/ir/intrinsic-signatures.js +2 -0
  262. package/dist/ir/intrinsic-signatures.js.map +1 -1
  263. package/dist/ir/ir.d.ts +65 -20
  264. package/dist/ir/ir.js +5 -0
  265. package/dist/ir/ir.js.map +1 -1
  266. package/dist/ir/runtime-features.d.ts +1 -0
  267. package/dist/ir/runtime-features.js +35 -1
  268. package/dist/ir/runtime-features.js.map +1 -1
  269. package/dist/ir/scalar-records.js +1 -2
  270. package/dist/ir/scalar-records.js.map +1 -1
  271. package/dist/ir/validate.js +150 -25
  272. package/dist/ir/validate.js.map +1 -1
  273. package/dist/ir/validate.test.js +65 -0
  274. package/dist/ir/validate.test.js.map +1 -1
  275. package/dist/library/ir-policy.js +1 -0
  276. package/dist/library/ir-policy.js.map +1 -1
  277. package/dist/native/sanitizer.test.js +1 -0
  278. package/dist/native/sanitizer.test.js.map +1 -1
  279. package/package.json +20 -20
  280. package/surface-manifest.json +159 -1
@@ -55,6 +55,8 @@ export function validateModule(mod) {
55
55
  const moduleLoc = { file: mod.sourceFile, start: 0, end: 0 };
56
56
  if (mod.workers !== undefined && typeof mod.workers !== "boolean")
57
57
  errors.push({ message: "worker execution mode must be a boolean", loc: moduleLoc });
58
+ if (mod.lifetimeRegions !== undefined && mod.lifetimeRegions !== true)
59
+ errors.push({ message: "lifetimeRegions must be true when present", loc: moduleLoc });
58
60
  if (mod.workers && mod.lib !== undefined)
59
61
  errors.push({
60
62
  message: "worker execution requires a native static executable",
@@ -359,6 +361,10 @@ export function validateModule(mod) {
359
361
  if (cls.jsLength !== undefined && (!Number.isSafeInteger(cls.jsLength) || cls.jsLength < 0)) {
360
362
  errors.push({ message: `class ${cls.name}: invalid constructor length`, loc: cls.loc });
361
363
  }
364
+ if (cls.prototypeNames !== undefined &&
365
+ new Set(cls.prototypeNames).size !== cls.prototypeNames.length) {
366
+ errors.push({ message: `class ${cls.name}: duplicate prototype member names`, loc: cls.loc });
367
+ }
362
368
  if (cls.tracksOwnFields &&
363
369
  (cls.runtime ||
364
370
  cls.fields.find((field) => field.name === DYN_CLASS_PROPERTIES)?.type.kind !== "dyn")) {
@@ -854,11 +860,11 @@ export function validateModule(mod) {
854
860
  }
855
861
  }
856
862
  for (const fn of mod.functions) {
857
- validateFunction(fn, functionsByName, ffiByName, classesByName, recordsById, recordValidation, unionsById, globalsById, classValidation, errors, mod.workers === true);
863
+ validateFunction(fn, functionsByName, ffiByName, classesByName, recordsById, recordValidation, unionsById, globalsById, classValidation, errors, mod.workers === true, mod.lifetimeRegions === true);
858
864
  }
859
865
  return errors;
860
866
  }
861
- function validateFunction(fn, functions, ffiByName, classes, records, recordValidation, unions, globals, classValidation, errors, workers) {
867
+ function validateFunction(fn, functions, ffiByName, classes, records, recordValidation, unions, globals, classValidation, errors, workers, lifetimeRegions) {
862
868
  const locals = new Map(fn.locals.map((l) => [l.id, l]));
863
869
  const err = (message, loc) => errors.push({ message: `in ${fn.name}: ${message}`, loc });
864
870
  const asyncCaches = [
@@ -1458,6 +1464,7 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
1458
1464
  allowed.add("return");
1459
1465
  allowed.add("throw");
1460
1466
  allowed.add("runtimeFence");
1467
+ allowed.add("tryCatch");
1461
1468
  }
1462
1469
  if (e.diverges) {
1463
1470
  const last = e.stmts[e.stmts.length - 1];
@@ -1781,10 +1788,15 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
1781
1788
  if (want)
1782
1789
  expectType(a, want, `regexIntrinsic ${e.method} arg ${i}`);
1783
1790
  });
1784
- if (e.method === "execGroups" && e.args[1]?.kind !== "numLit") {
1785
- err("regexIntrinsic execGroups mask must be a numeric literal", e.loc);
1786
- }
1787
- if (e.method === "match" || e.method === "exec" || e.method === "execGroups") {
1791
+ if ((e.method === "execGroups" || e.method === "execSpans" || e.method === "matchGroups") &&
1792
+ e.args.slice(1).some((mask) => mask.kind !== "numLit")) {
1793
+ err(`regexIntrinsic ${e.method} masks must be numeric literals`, e.loc);
1794
+ }
1795
+ if (e.method === "match" ||
1796
+ e.method === "exec" ||
1797
+ e.method === "execGroups" ||
1798
+ e.method === "execSpans" ||
1799
+ e.method === "matchGroups") {
1788
1800
  // The `string[] | null` union (program-dependent id) — checked
1789
1801
  // by arms, like the libCall case checks process.envGet.
1790
1802
  const def = e.type.kind === "union" ? unions.get(e.type.unionId) : undefined;
@@ -2119,9 +2131,15 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
2119
2131
  : e.method === "shift"
2120
2132
  ? { argTypes: [], result: e.type } // union-checked below
2121
2133
  : e.method === "sortValues"
2122
- ? { argTypes: [F64, null], result: VOID }
2134
+ ? {
2135
+ argTypes: [F64, null, F64, null],
2136
+ result: VOID,
2137
+ }
2123
2138
  : e.method === "sortDense"
2124
- ? { argTypes: [null, BOOL], result: BOOL }
2139
+ ? {
2140
+ argTypes: [null, BOOL, F64, null],
2141
+ result: BOOL,
2142
+ }
2125
2143
  : { argTypes: [], result: F64 }; // length
2126
2144
  if ((e.method === "sortPrimitive" || e.method === "toSortedPrimitive") &&
2127
2145
  elem.kind !== "string" &&
@@ -2142,6 +2160,25 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
2142
2160
  err(`arrIntrinsic ${e.method} comparator must be (elem, elem) => number`, e.loc);
2143
2161
  if (e.method === "sortDense" && e.args[1]?.kind !== "boolLit")
2144
2162
  err("arrIntrinsic sortDense owned flag must be a boolean literal", e.loc);
2163
+ // A recognized comparator's key order: [order] for numbers,
2164
+ // [order, key reader] for record and class elements.
2165
+ const order = e.args[2];
2166
+ if (order) {
2167
+ if (order.kind !== "numLit" || (order.value !== 1 && order.value !== -1))
2168
+ err(`arrIntrinsic ${e.method} key order must be the literal 1 or -1`, e.loc);
2169
+ const key = e.args[3]?.type;
2170
+ if (elem.kind === "f64"
2171
+ ? key !== undefined
2172
+ : elem.kind !== "record" && elem.kind !== "object")
2173
+ err(`arrIntrinsic ${e.method} key order on ${elem.kind} elements`, e.loc);
2174
+ if (elem.kind !== "f64" &&
2175
+ (!key ||
2176
+ key.kind !== "func" ||
2177
+ key.params.length !== 1 ||
2178
+ !typeEquals(key.params[0], elem) ||
2179
+ key.ret.kind !== "f64"))
2180
+ err(`arrIntrinsic ${e.method} key reader must be (elem) => number`, e.loc);
2181
+ }
2145
2182
  }
2146
2183
  if (e.method === "getNumber" && elem.kind !== "f64") {
2147
2184
  err(`arrIntrinsic getNumber requires f64 elements, got ${elem.kind}`, e.loc);
@@ -2188,7 +2225,13 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
2188
2225
  // slice's indices and splice's count are optional (omitted args
2189
2226
  // omitted from the IR — backends fill the defaults); everything
2190
2227
  // else is exact.
2191
- const minArgs = e.method === "slice" ? 0 : e.method === "splice" ? 1 : sig.argTypes.length;
2228
+ const minArgs = e.method === "slice"
2229
+ ? 0
2230
+ : e.method === "splice"
2231
+ ? 1
2232
+ : e.method === "sortValues" || e.method === "sortDense"
2233
+ ? 2
2234
+ : sig.argTypes.length;
2192
2235
  if (e.args.length < minArgs || e.args.length > sig.argTypes.length) {
2193
2236
  err(`arrIntrinsic ${e.method}: ${e.args.length} args, expected ${sig.argTypes.length}`, e.loc);
2194
2237
  }
@@ -2787,25 +2830,13 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
2787
2830
  const want = recordValidation.get(shape.id).initializationFields;
2788
2831
  const seen = new Set();
2789
2832
  for (const f of e.fields) {
2790
- if (f.drop || f.overflow)
2833
+ if (f.overflow)
2791
2834
  checkExpr(f.value);
2792
2835
  else
2793
2836
  checkSlotValue(f.value);
2794
2837
  if (seen.has(f.name))
2795
2838
  err(`recordLit initializes field "${f.name}" twice`, e.loc);
2796
2839
  seen.add(f.name);
2797
- if (f.drop) {
2798
- // A mapping-dropped field (the PromiseSettledResult honest
2799
- // subset): evaluated, never stored — it must NOT name a
2800
- // declared field (that would silently drop a real store),
2801
- // and its value may be any type, void included.
2802
- if (f.overflow)
2803
- err(`recordLit drop entry "${f.name}" flagged overflow too`, e.loc);
2804
- if (want.has(f.name)) {
2805
- err(`recordLit drop entry "${f.name}" shadows a declared field of shape ${shape.id}`, e.loc);
2806
- }
2807
- continue;
2808
- }
2809
2840
  if (f.overflow) {
2810
2841
  // Overflow entries exist only on index-signature shapes, name
2811
2842
  // no declared field, and carry the index-value type exactly
@@ -2827,7 +2858,7 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
2827
2858
  else
2828
2859
  expectType(f.value, ft, `recordLit field "${f.name}"`);
2829
2860
  }
2830
- if (e.fields.filter((f) => !f.overflow && !f.drop).length !== shape.fields.length) {
2861
+ if (e.fields.filter((f) => !f.overflow).length !== shape.fields.length) {
2831
2862
  err(`recordLit does not initialize every field of shape ${shape.id}`, e.loc);
2832
2863
  }
2833
2864
  break;
@@ -3397,6 +3428,24 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
3397
3428
  err("module.tdzCheck must be void", e.loc);
3398
3429
  return;
3399
3430
  }
3431
+ if (e.name === "region.create" ||
3432
+ e.name === "region.enter" ||
3433
+ e.name === "region.leave" ||
3434
+ e.name === "region.release") {
3435
+ if (!lifetimeRegions)
3436
+ err(`${e.name} outside a lifetimeRegions module`, e.loc);
3437
+ const takesId = e.name === "region.enter" || e.name === "region.release";
3438
+ if (e.args.length !== (takesId ? 1 : 0))
3439
+ err(`${e.name} takes ${takesId ? "one region id" : "no arguments"}`, e.loc);
3440
+ for (const a of e.args) {
3441
+ checkExpr(a);
3442
+ if (a.type.kind !== "f64")
3443
+ err(`${e.name} id must be f64`, e.loc);
3444
+ }
3445
+ if (e.type.kind !== (e.name === "region.create" ? "f64" : "void"))
3446
+ err(`${e.name} has type ${e.name === "region.create" ? "f64" : "void"}`, e.loc);
3447
+ return;
3448
+ }
3400
3449
  if (e.name === "threads.publish") {
3401
3450
  if (e.args.length !== 1)
3402
3451
  err("threads.publish takes exactly one argument", e.loc);
@@ -3440,6 +3489,26 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
3440
3489
  }
3441
3490
  return;
3442
3491
  }
3492
+ if (e.name === "promise.allSettled" || e.name === "promise.any") {
3493
+ if (e.args.length !== 1)
3494
+ err(`${e.name} takes exactly one argument`, e.loc);
3495
+ for (const a of e.args) {
3496
+ checkExpr(a);
3497
+ if (a.type.kind !== "array" || a.type.elem.kind !== "promise") {
3498
+ err(`${a.type.kind} argument to ${e.name} (needs an array of promises)`, a.loc);
3499
+ }
3500
+ else if (e.name === "promise.any" && !typeEquals(a.type.elem, e.type)) {
3501
+ err("promise.any result must be the entries' promise type", e.loc);
3502
+ }
3503
+ }
3504
+ if (e.type.kind !== "promise")
3505
+ err(`${e.name} must be promise-typed`, e.loc);
3506
+ else if (e.name === "promise.allSettled" &&
3507
+ (e.type.inner.kind !== "array" || e.type.inner.elem.kind !== "union")) {
3508
+ err("promise.allSettled result must be a promise of a settled-record union array", e.loc);
3509
+ }
3510
+ return;
3511
+ }
3443
3512
  if (e.name === "promise.reject") {
3444
3513
  // ONE argument: the %Error-rooted reason object (the rejection
3445
3514
  // payload shares the thrown-Error representation — the
@@ -3631,6 +3700,23 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
3631
3700
  }
3632
3701
  return true;
3633
3702
  }
3703
+ if (e.fn === "dyn.objEntryPairs") {
3704
+ // Result: the native [string, any][] the backend assembles from the
3705
+ // runtime's owned pair snapshot.
3706
+ const shape = e.type.kind === "array" && e.type.elem.kind === "record"
3707
+ ? records.get(e.type.elem.shapeId)
3708
+ : undefined;
3709
+ const field = (name) => shape?.fields.find((f) => f.name === name)?.type;
3710
+ const ok = shape !== undefined &&
3711
+ shape.tuple === true &&
3712
+ shape.indexValue === undefined &&
3713
+ shape.fields.length === 2 &&
3714
+ field("0")?.kind === "string" &&
3715
+ field("1")?.kind === "dyn";
3716
+ if (!ok)
3717
+ err(`libCall dyn.objEntryPairs must return a [string, any] tuple array`, e.loc);
3718
+ return true;
3719
+ }
3634
3720
  if (e.fn === "fetch.streamFrom") {
3635
3721
  const t = e.args[0]?.type;
3636
3722
  const ok = t?.kind === "string" ||
@@ -4557,6 +4643,15 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
4557
4643
  }
4558
4644
  return true;
4559
4645
  }
4646
+ if (e.fn === "error.aggregateSetErrors" || e.fn === "error.aggregateErrors") {
4647
+ // Receiver: exactly %AggregateError (subclassing is fenced — the
4648
+ // hidden runtime slot admits no other layout).
4649
+ const recv = e.args[0];
4650
+ if (!recv || recv.type.kind !== "object" || recv.type.className !== "%AggregateError") {
4651
+ err(`libCall ${e.fn} receiver must be %AggregateError`, e.loc);
4652
+ }
4653
+ return true;
4654
+ }
4560
4655
  if (e.fn === "error.newDom") {
4561
4656
  if (e.type.kind !== "object" || e.type.className !== "%DOMException") {
4562
4657
  err(`libCall error.newDom must return %DOMException, got ${e.type.kind}`, e.loc);
@@ -4792,6 +4887,7 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
4792
4887
  e.fn !== "emitter.setDefaultMax" &&
4793
4888
  e.fn !== "emitter.setDefaultMaxChk" &&
4794
4889
  e.fn !== "emitter.getDefaultMax" &&
4890
+ e.fn !== "emitter.errorMonitor" &&
4795
4891
  e.fn !== "emitter.checkListener") {
4796
4892
  // Receiver: an emitter-hierarchy object (the %EventEmitter class
4797
4893
  // itself, or a class whose base chain reaches it). emitter.new
@@ -4960,6 +5056,8 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
4960
5056
  }
4961
5057
  }
4962
5058
  }
5059
+ // The yield a `delegate` genResume is checking as its argument.
5060
+ let delegatedYield = null;
4963
5061
  function checkAsyncExpr(e) {
4964
5062
  switch (e.kind) {
4965
5063
  case "awaitExpr": {
@@ -4991,7 +5089,13 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
4991
5089
  }
4992
5090
  // The undefined next-channel has no C value form: such yields are
4993
5091
  // void-typed (statement position only — the frontend fences reads).
4994
- if (e.captureCompletion) {
5092
+ if (e.delegated) {
5093
+ if (delegatedYield !== e)
5094
+ err("delegated yield outside a delegate resume", e.loc);
5095
+ if (e.type.kind !== "void" || e.captureCompletion)
5096
+ err("invalid delegated yield", e.loc);
5097
+ }
5098
+ else if (e.captureCompletion) {
4995
5099
  if (fn.async ||
4996
5100
  e.type.kind !== "dyn" ||
4997
5101
  !typeEquals(e.captureCompletion.returnType, fn.returnType)) {
@@ -5014,6 +5118,26 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
5014
5118
  break;
5015
5119
  }
5016
5120
  const genT = e.gen.type;
5121
+ if (e.mode === "delegate") {
5122
+ if (e.arg !== null) {
5123
+ if (e.arg.kind === "yieldExpr" && e.arg.delegated)
5124
+ delegatedYield = e.arg;
5125
+ else
5126
+ err("genResume delegate argument is not a delegated yield", e.loc);
5127
+ checkExpr(e.arg);
5128
+ delegatedYield = null;
5129
+ }
5130
+ const outer = fn.generator;
5131
+ if (outer === undefined || fn.async || genT.async)
5132
+ err("genResume delegate outside a sync generator body", e.loc);
5133
+ else if (genT.nextT.kind !== "undefinedT" &&
5134
+ genT.nextT.kind !== "dyn" &&
5135
+ !typeEquals(genT.nextT, outer.nextT))
5136
+ err(`genResume delegate into a ${typeKey(genT.nextT)} next-channel from ${typeKey(outer.nextT)}`, e.loc);
5137
+ if (e.type.kind !== "bool" && e.type.kind !== "record")
5138
+ err(`genResume delegate result ${typeKey(e.type)}`, e.loc);
5139
+ break;
5140
+ }
5017
5141
  if (e.arg !== null)
5018
5142
  checkExpr(e.arg);
5019
5143
  if (e.mode === "step" || e.mode === "value" || e.mode === "close") {
@@ -5031,7 +5155,8 @@ function validateFunction(fn, functions, ffiByName, classes, records, recordVali
5031
5155
  if (e.type.kind !== "void")
5032
5156
  err(`genResume close result ${typeKey(e.type)}`, e.loc);
5033
5157
  }
5034
- else if (genT.yieldT.kind === "void" || !typeEquals(e.type, genT.yieldT)) {
5158
+ else if ((genT.yieldT.kind === "void" || !typeEquals(e.type, genT.yieldT)) &&
5159
+ (genT.retT.kind === "void" || !typeEquals(e.type, genT.retT))) {
5035
5160
  err(`genResume value ${typeKey(e.type)} != yield channel ${typeKey(genT.yieldT)}`, e.loc);
5036
5161
  }
5037
5162
  break;