@scriptc/compiler 0.0.17 → 0.0.19

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 (62) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +4 -4
  2. package/dist/backend/cc.d.ts +5 -0
  3. package/dist/backend/cc.js +2 -0
  4. package/dist/backend/cc.js.map +1 -1
  5. package/dist/backend/emission/emit-async.js +35 -2
  6. package/dist/backend/emission/emit-async.js.map +1 -1
  7. package/dist/backend/emission/emit-exprs.js +40 -4
  8. package/dist/backend/emission/emit-exprs.js.map +1 -1
  9. package/dist/backend/emission/emitter.js +69 -11
  10. package/dist/backend/emission/emitter.js.map +1 -1
  11. package/dist/backend/emission/may-throw.d.ts +3 -3
  12. package/dist/backend/emission/may-throw.js +15 -4
  13. package/dist/backend/emission/may-throw.js.map +1 -1
  14. package/dist/backend/llvm/emitter.js +199 -21
  15. package/dist/backend/llvm/emitter.js.map +1 -1
  16. package/dist/frontend/lib-contract.d.ts +1 -0
  17. package/dist/frontend/lib-contract.js +2 -2
  18. package/dist/frontend/lib-contract.js.map +1 -1
  19. package/dist/frontend/lowering/lower-builtins.js +4 -7
  20. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  21. package/dist/frontend/lowering/lower-calls.js +17 -9
  22. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  23. package/dist/frontend/lowering/lower-containers.d.ts +22 -17
  24. package/dist/frontend/lowering/lower-containers.js +628 -51
  25. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  26. package/dist/frontend/lowering/lower-exprs.js +19 -1
  27. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  28. package/dist/frontend/lowering/lower-island.js +55 -7
  29. package/dist/frontend/lowering/lower-island.js.map +1 -1
  30. package/dist/frontend/lowering/lower-modules.js +144 -10
  31. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  32. package/dist/frontend/lowering/lower-stmts.d.ts +8 -0
  33. package/dist/frontend/lowering/lower-stmts.js +408 -21
  34. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  35. package/dist/frontend/lowering/lowerer.d.ts +38 -0
  36. package/dist/frontend/lowering/lowerer.js +149 -2
  37. package/dist/frontend/lowering/lowerer.js.map +1 -1
  38. package/dist/frontend/lowering/surfaces.js +4 -0
  39. package/dist/frontend/lowering/surfaces.js.map +1 -1
  40. package/dist/index.js +97 -21
  41. package/dist/index.js.map +1 -1
  42. package/dist/ir/nodes.d.ts +46 -12
  43. package/dist/ir/nodes.js +41 -0
  44. package/dist/ir/nodes.js.map +1 -1
  45. package/dist/ir/serialize.d.ts +1 -1
  46. package/dist/ir/serialize.js +1 -1
  47. package/dist/ir/validate.js +98 -39
  48. package/dist/ir/validate.js.map +1 -1
  49. package/dist/library/int-infer.d.ts +6 -1
  50. package/dist/library/int-infer.js +306 -53
  51. package/dist/library/int-infer.js.map +1 -1
  52. package/dist/library/int-infer.test.js +271 -1
  53. package/dist/library/int-infer.test.js.map +1 -1
  54. package/dist/library/profile.d.ts +6 -5
  55. package/dist/library/profile.js.map +1 -1
  56. package/dist/library/sidecar-validate.js +4 -1
  57. package/dist/library/sidecar-validate.js.map +1 -1
  58. package/dist/library/sidecar.d.ts +32 -4
  59. package/dist/library/sidecar.js +264 -47
  60. package/dist/library/sidecar.js.map +1 -1
  61. package/package.json +2 -2
  62. package/surface-manifest.json +25 -1
@@ -1441,6 +1441,36 @@ export function validateModule(mod) {
1441
1441
  function validateFunction(fn, functions, ffiByName, classes, records, unions, globals, errors) {
1442
1442
  const locals = new Map(fn.locals.map((l) => [l.id, l]));
1443
1443
  const err = (message, loc) => errors.push({ message: `in ${fn.name}: ${message}`, loc });
1444
+ const asyncCaches = [
1445
+ ["asyncCacheGlobal", fn.asyncCacheGlobal],
1446
+ ["asyncCycleCacheGlobal", fn.asyncCycleCacheGlobal],
1447
+ ];
1448
+ for (const [field, cacheId] of asyncCaches) {
1449
+ if (cacheId === undefined)
1450
+ continue;
1451
+ if (fn.async !== true) {
1452
+ err(`an ${field} is only valid on an async function`, fn.loc);
1453
+ }
1454
+ if (fn.params.length !== 0 || (fn.captures?.length ?? 0) !== 0) {
1455
+ err("a cached async function must have no parameters or captures", fn.loc);
1456
+ }
1457
+ const cache = globals.get(cacheId);
1458
+ if (cache === undefined) {
1459
+ err(`async cache names undeclared global "${cacheId}"`, fn.loc);
1460
+ }
1461
+ else {
1462
+ const expected = { kind: "promise", inner: fn.returnType };
1463
+ if (!typeEquals(cache.type, expected)) {
1464
+ err(`async cache global "${cacheId}" has type ${typeKey(cache.type)}, expected ${typeKey(expected)}`, fn.loc);
1465
+ }
1466
+ if (!cache.mutable) {
1467
+ err(`async cache global "${cacheId}" is immutable`, fn.loc);
1468
+ }
1469
+ }
1470
+ }
1471
+ if (fn.asyncCycleCacheGlobal !== undefined && fn.asyncCacheGlobal === undefined) {
1472
+ err("an asyncCycleCacheGlobal requires a module asyncCacheGlobal", fn.loc);
1473
+ }
1444
1474
  // The class graph's two questions (upcast/downcast/instanceOf/virtualCall
1445
1475
  // legality): strict-descendant tests over the base links, and hierarchy
1446
1476
  // membership (a class that extends or is extended).
@@ -2178,35 +2208,43 @@ function validateFunction(fn, functions, ffiByName, classes, records, unions, gl
2178
2208
  ? { argTypes: [F64], minArgs: 1, result: F64 }
2179
2209
  : e.method === "slice" || e.method === "subarray"
2180
2210
  ? { argTypes: [F64, F64], minArgs: 0, result: bytesOf(recv.elem) }
2181
- : e.method === "setFrom"
2182
- ? { argTypes: [bytesOf(recv.elem), F64], minArgs: 1, result: VOID }
2183
- : e.method === "toString"
2184
- ? { argTypes: [STRING, F64, F64], minArgs: 1, result: STRING }
2185
- : e.method === "readNum"
2186
- ? { argTypes: [STRING, F64], minArgs: 2, result: F64 }
2187
- : e.method === "writeNum"
2188
- ? { argTypes: [STRING, F64, F64], minArgs: 3, result: F64 }
2189
- : e.method === "readNumVar"
2190
- ? { argTypes: [STRING, F64, F64], minArgs: 3, result: F64 }
2191
- : e.method === "writeNumVar"
2192
- ? { argTypes: [STRING, F64, F64, F64], minArgs: 4, result: F64 }
2193
- : e.method === "dataViewNew"
2194
- ? { argTypes: [F64, F64], minArgs: 0, result: BYTES_U8 }
2195
- : e.method.startsWith("dvSet")
2196
- ? {
2197
- // dvSet*: [offset, value], the 8-bit setters take no littleEndian.
2198
- argTypes: e.method === "dvSetUint8" || e.method === "dvSetInt8"
2199
- ? [F64, F64]
2200
- : [F64, F64, BOOL],
2201
- minArgs: 2,
2202
- result: VOID,
2203
- }
2204
- : {
2205
- // dvGet*: the 8-bit getters take no littleEndian.
2206
- argTypes: e.method === "dvGetUint8" || e.method === "dvGetInt8" ? [F64] : [F64, BOOL],
2207
- minArgs: 1,
2208
- result: F64,
2209
- });
2211
+ : e.method === "toReversed"
2212
+ ? { argTypes: [], minArgs: 0, result: bytesOf(recv.elem) }
2213
+ : e.method === "with"
2214
+ ? { argTypes: [F64, F64], minArgs: 2, result: bytesOf(recv.elem) }
2215
+ : e.method === "join"
2216
+ ? { argTypes: [STRING], minArgs: 1, result: STRING }
2217
+ : e.method === "toArray"
2218
+ ? { argTypes: [], minArgs: 0, result: arrayOf(F64) }
2219
+ : e.method === "setFrom"
2220
+ ? { argTypes: [bytesOf(recv.elem), F64], minArgs: 1, result: VOID }
2221
+ : e.method === "toString"
2222
+ ? { argTypes: [STRING, F64, F64], minArgs: 1, result: STRING }
2223
+ : e.method === "readNum"
2224
+ ? { argTypes: [STRING, F64], minArgs: 2, result: F64 }
2225
+ : e.method === "writeNum"
2226
+ ? { argTypes: [STRING, F64, F64], minArgs: 3, result: F64 }
2227
+ : e.method === "readNumVar"
2228
+ ? { argTypes: [STRING, F64, F64], minArgs: 3, result: F64 }
2229
+ : e.method === "writeNumVar"
2230
+ ? { argTypes: [STRING, F64, F64, F64], minArgs: 4, result: F64 }
2231
+ : e.method === "dataViewNew"
2232
+ ? { argTypes: [F64, F64], minArgs: 0, result: BYTES_U8 }
2233
+ : e.method.startsWith("dvSet")
2234
+ ? {
2235
+ // dvSet*: [offset, value], the 8-bit setters take no littleEndian.
2236
+ argTypes: e.method === "dvSetUint8" || e.method === "dvSetInt8"
2237
+ ? [F64, F64]
2238
+ : [F64, F64, BOOL],
2239
+ minArgs: 2,
2240
+ result: VOID,
2241
+ }
2242
+ : {
2243
+ // dvGet*: the 8-bit getters take no littleEndian.
2244
+ argTypes: e.method === "dvGetUint8" || e.method === "dvGetInt8" ? [F64] : [F64, BOOL],
2245
+ minArgs: 1,
2246
+ result: F64,
2247
+ });
2210
2248
  if (e.args.length < sig.minArgs || e.args.length > sig.argTypes.length) {
2211
2249
  err(`bytesIntrinsic ${e.method}: ${e.args.length} args`, e.loc);
2212
2250
  }
@@ -2242,11 +2280,17 @@ function validateFunction(fn, functions, ffiByName, classes, records, unions, gl
2242
2280
  ? { argTypes: [STRING], result: STRING }
2243
2281
  : e.method === "slice"
2244
2282
  ? { argTypes: [F64, F64], result: e.receiver.type }
2245
- : e.method === "splice"
2246
- ? { argTypes: [F64, F64], result: e.receiver.type }
2247
- : e.method === "shift"
2248
- ? { argTypes: [], result: e.type } // union-checked below
2249
- : { argTypes: [], result: F64 }; // length
2283
+ : e.method === "toReversed"
2284
+ ? { argTypes: [], result: e.receiver.type }
2285
+ : e.method === "toSpliced"
2286
+ ? { argTypes: [F64, F64, e.receiver.type], result: e.receiver.type }
2287
+ : e.method === "with"
2288
+ ? { argTypes: [F64, elem], result: e.receiver.type }
2289
+ : e.method === "splice"
2290
+ ? { argTypes: [F64, F64], result: e.receiver.type }
2291
+ : e.method === "shift"
2292
+ ? { argTypes: [], result: e.type } // union-checked below
2293
+ : { argTypes: [], result: F64 }; // length
2250
2294
  if (e.method === "join" &&
2251
2295
  elem.kind !== "f64" && elem.kind !== "string" && elem.kind !== "bool" &&
2252
2296
  !(elem.kind === "union" &&
@@ -3262,6 +3306,19 @@ function validateFunction(fn, functions, ffiByName, classes, records, unions, gl
3262
3306
  break;
3263
3307
  }
3264
3308
  case "intrinsic":
3309
+ if (e.name === "module.await") {
3310
+ if (e.args.length !== 1)
3311
+ err("module.await takes exactly one argument", e.loc);
3312
+ for (const a of e.args) {
3313
+ checkExpr(a);
3314
+ if (a.type.kind !== "promise" || a.type.inner.kind !== "void") {
3315
+ err(`${typeKey(a.type)} argument to module.await (needs promise<void>)`, a.loc);
3316
+ }
3317
+ }
3318
+ if (e.type.kind !== "void")
3319
+ err("module.await must be void", e.loc);
3320
+ break;
3321
+ }
3265
3322
  if (e.name === "promise.all") {
3266
3323
  // ONE argument: an array of promises whose inner type is the
3267
3324
  // result's array element (or void, collapsing to promise<void>).
@@ -3528,15 +3585,17 @@ function validateFunction(fn, functions, ffiByName, classes, records, unions, gl
3528
3585
  }
3529
3586
  break;
3530
3587
  }
3531
- if (e.fn === "http.requestCb" || e.fn === "http.requestUrlCb" || e.fn === "http.clientOnResponse" ||
3588
+ if (e.fn === "http.requestCb" || e.fn === "https.requestCb" ||
3589
+ e.fn === "http.requestUrlCb" || e.fn === "http.clientOnResponse" ||
3532
3590
  e.fn === "http.requestAgentCb" || e.fn === "https.requestAgentCb" ||
3533
3591
  e.fn === "https.requestUrlCb") {
3534
3592
  // The response listener: void, no params or exactly (res: httpReq).
3535
3593
  const cbT = e.args[e.fn === "http.requestCb" ? 7
3536
- : e.fn === "http.requestUrlCb" || e.fn === "https.requestUrlCb" ? 3
3537
- : e.fn === "http.requestAgentCb" ? 8
3538
- : e.fn === "https.requestAgentCb" ? 10
3539
- : 1]?.type;
3594
+ : e.fn === "https.requestCb" ? 9
3595
+ : e.fn === "http.requestUrlCb" || e.fn === "https.requestUrlCb" ? 3
3596
+ : e.fn === "http.requestAgentCb" ? 8
3597
+ : e.fn === "https.requestAgentCb" ? 10
3598
+ : 1]?.type;
3540
3599
  let ok = cbT?.kind === "func" && cbT.ret.kind === "void" && cbT.params.length <= 1;
3541
3600
  if (ok && cbT?.kind === "func" && cbT.params.length === 1) {
3542
3601
  ok = cbT.params[0].kind === "httpReq";