@scriptc/compiler 0.0.7 → 0.0.9

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 (94) 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 +155 -6
  5. package/dist/backend/emission/emit-exprs.js.map +1 -1
  6. package/dist/backend/emission/emit-island.js +9 -1
  7. package/dist/backend/emission/emit-island.js.map +1 -1
  8. package/dist/backend/emission/emit-stmts.js +3 -1
  9. package/dist/backend/emission/emit-stmts.js.map +1 -1
  10. package/dist/backend/emission/emit-types.d.ts +3 -0
  11. package/dist/backend/emission/emit-types.js +12 -0
  12. package/dist/backend/emission/emit-types.js.map +1 -1
  13. package/dist/backend/emission/emit-walkers.d.ts +7 -5
  14. package/dist/backend/emission/emit-walkers.js +45 -18
  15. package/dist/backend/emission/emit-walkers.js.map +1 -1
  16. package/dist/backend/emission/emitter.d.ts +1 -1
  17. package/dist/backend/emission/emitter.js +35 -10
  18. package/dist/backend/emission/emitter.js.map +1 -1
  19. package/dist/backend/emission/may-throw.js +4 -3
  20. package/dist/backend/emission/may-throw.js.map +1 -1
  21. package/dist/backend/llvm/emitter.js +300 -18
  22. package/dist/backend/llvm/emitter.js.map +1 -1
  23. package/dist/diagnostics/diagnostic.d.ts +98 -11
  24. package/dist/diagnostics/diagnostic.js +185 -25
  25. package/dist/diagnostics/diagnostic.js.map +1 -1
  26. package/dist/frontend/lib-contract.d.ts +24 -6
  27. package/dist/frontend/lib-contract.js +125 -44
  28. package/dist/frontend/lib-contract.js.map +1 -1
  29. package/dist/frontend/lowering/lower-assert.js +16 -0
  30. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  31. package/dist/frontend/lowering/lower-builtins.d.ts +11 -0
  32. package/dist/frontend/lowering/lower-builtins.js +127 -4
  33. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  34. package/dist/frontend/lowering/lower-calls.d.ts +77 -18
  35. package/dist/frontend/lowering/lower-calls.js +978 -44
  36. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  37. package/dist/frontend/lowering/lower-classes.d.ts +14 -1
  38. package/dist/frontend/lowering/lower-classes.js +112 -16
  39. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  40. package/dist/frontend/lowering/lower-containers.d.ts +4 -2
  41. package/dist/frontend/lowering/lower-containers.js +236 -44
  42. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  43. package/dist/frontend/lowering/lower-emitter.js +55 -1
  44. package/dist/frontend/lowering/lower-emitter.js.map +1 -1
  45. package/dist/frontend/lowering/lower-exprs.d.ts +26 -3
  46. package/dist/frontend/lowering/lower-exprs.js +507 -47
  47. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  48. package/dist/frontend/lowering/lower-island.d.ts +7 -0
  49. package/dist/frontend/lowering/lower-island.js +71 -10
  50. package/dist/frontend/lowering/lower-island.js.map +1 -1
  51. package/dist/frontend/lowering/lower-mixins.d.ts +1 -1
  52. package/dist/frontend/lowering/lower-mixins.js +1 -1
  53. package/dist/frontend/lowering/lower-modules.js +95 -4
  54. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  55. package/dist/frontend/lowering/lower-stmts.js +866 -56
  56. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  57. package/dist/frontend/lowering/lower-stream.js +28 -2
  58. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  59. package/dist/frontend/lowering/lowerer.d.ts +85 -17
  60. package/dist/frontend/lowering/lowerer.js +459 -37
  61. package/dist/frontend/lowering/lowerer.js.map +1 -1
  62. package/dist/frontend/lowering/surfaces.js +20 -3
  63. package/dist/frontend/lowering/surfaces.js.map +1 -1
  64. package/dist/frontend/npm-static-rewrite.d.ts +7 -2
  65. package/dist/frontend/npm-static-rewrite.js +566 -138
  66. package/dist/frontend/npm-static-rewrite.js.map +1 -1
  67. package/dist/frontend/npm-static.js +11 -2
  68. package/dist/frontend/npm-static.js.map +1 -1
  69. package/dist/frontend/program.js +5 -5
  70. package/dist/frontend/program.js.map +1 -1
  71. package/dist/frontend/shared.d.ts +6 -1
  72. package/dist/frontend/shared.js +46 -1
  73. package/dist/frontend/shared.js.map +1 -1
  74. package/dist/frontend/types.d.ts +28 -1
  75. package/dist/frontend/types.js +304 -10
  76. package/dist/frontend/types.js.map +1 -1
  77. package/dist/index.d.ts +2 -1
  78. package/dist/index.js +181 -26
  79. package/dist/index.js.map +1 -1
  80. package/dist/ir/nodes.d.ts +159 -9
  81. package/dist/ir/nodes.js +76 -6
  82. package/dist/ir/nodes.js.map +1 -1
  83. package/dist/ir/validate.js +93 -14
  84. package/dist/ir/validate.js.map +1 -1
  85. package/dist/library/profile.d.ts +17 -3
  86. package/dist/library/profile.js +38 -9
  87. package/dist/library/profile.js.map +1 -1
  88. package/dist/library/sidecar.js +162 -43
  89. package/dist/library/sidecar.js.map +1 -1
  90. package/dist/library/trap-teaching.d.ts +11 -0
  91. package/dist/library/trap-teaching.js +49 -0
  92. package/dist/library/trap-teaching.js.map +1 -0
  93. package/package.json +2 -2
  94. package/surface-manifest.json +46 -4
@@ -9,7 +9,7 @@ import { type ClassInfo } from "./lower-classes.js";
9
9
  * trailing-suffix call, and the frontend appends the interned undefined arm;
10
10
  * `rest` (always last) receives the surplus arguments packed into one array
11
11
  * literal at each call site. */
12
- export type ParamMode = "required" | "omittable" | "rest" | "dynRest";
12
+ export type ParamMode = "required" | "omittable" | "rest" | "dynRest" | "islandRest";
13
13
  /** One parameter of a signature, as call sites and callee prologues see it.
14
14
  * `type` is the ABI type — what the emitted C parameter carries: the
15
15
  * checker's `T | undefined` union for `x?: T`, a synthesized `T | undefined`
@@ -57,6 +57,12 @@ export interface GenericFnInfo {
57
57
  qualifiedName: string;
58
58
  /** Declaration-order type parameter symbols. */
59
59
  typeParams: ts.Symbol[];
60
+ /** Lazily computed (keyofConstrainedTypeParams): the type parameters
61
+ * declared `K extends keyof …`. Their bound LITERAL keys are semantic —
62
+ * the body's `o[k]` reads the named field — so instances key on the
63
+ * literal (no cross-literal sharing) and keep the checker types
64
+ * (tsBindings) the body resolves through. */
65
+ keyofTps?: Set<ts.Symbol>;
60
66
  /** Instantiation key (comma-joined typeKeys of the mapped param types +
61
67
  * `=>` + return typeKey) → instance. Key identity IS signature identity:
62
68
  * two call sites whose inferred types map to the same IR types share one
@@ -99,6 +105,11 @@ export interface GenericInstance {
99
105
  /** Type-parameter symbol → concrete IR type, consulted by mapType (via
100
106
  * typeParamResolver) while the instance body lowers. */
101
107
  bindings: Map<ts.Symbol, IrType>;
108
+ /** Call-keyed instances: type-parameter symbol → the bound CHECKER type
109
+ * (pre-widening), consulted while the body lowers where the IrType
110
+ * binding has already lost what the body needs — `T[K]` and `o[k]` reads
111
+ * whose K is bound to one literal key (typeParamTsBindings). */
112
+ tsBindings?: Map<ts.Symbol, ts.Type>;
102
113
  /** Rendered type arguments ("<number, string>") for diagnostics. */
103
114
  typeArgsText: string;
104
115
  /** Implicit instances only: param symbol → the call site's (widened)
@@ -242,28 +253,36 @@ export declare function genericCallInstance(L: Lowerer, expr: ts.CallExpression,
242
253
  * (`const f: (x: number) => number = identity`) reuse one compiled
243
254
  * instance. `makeBindings` runs only for a NEW key (binding inference
244
255
  * costs checker walks). */
245
- export declare function internGenericInstance(L: Lowerer, blame: ts.Node, info: GenericFnInfo, params: ParamShape[], returnType: IrType, makeBindings: () => Map<ts.Symbol, IrType>): GenericInstance;
256
+ export declare function internGenericInstance(L: Lowerer, blame: ts.Node, info: GenericFnInfo, params: ParamShape[], returnType: IrType, makeBindings: (tsBindings: Map<ts.Symbol, ts.Type>) => Map<ts.Symbol, IrType>, opts?: {
257
+ extraKey?: string;
258
+ tsBindings?: Map<ts.Symbol, ts.Type>;
259
+ }): GenericInstance;
260
+ /** The type parameters of `info` declared with a `keyof` CONSTRAINT
261
+ * (`K extends keyof T`) — the parameters whose bound literal is semantic
262
+ * (the body's `o[k]` reads the named field), computed once per info from
263
+ * the declaration's syntax. */
264
+ export declare function keyofConstrainedTypeParams(info: GenericFnInfo): Set<ts.Symbol>;
246
265
  /** Type-parameter symbol → concrete IR type for one instantiation.
247
266
  * Explicit type arguments bind directly; the rest come from structurally
248
267
  * matching each DECLARED param/return type (which mentions the type
249
268
  * parameters) against the checker's INSTANTIATED one — the latter is the
250
269
  * former with the substitution applied, so the shapes are parallel by
251
270
  * construction. A type parameter left unbound only matters if the body
252
- * mentions it, where mapType fails with SC2001 (carrying the
253
- * instantiation context). */
254
- export declare function inferTypeParamBindings(L: Lowerer, expr: ts.CallExpression, info: GenericFnInfo, rsig: ts.Signature): Map<ts.Symbol, IrType>;
271
+ * mentions it, where mapType fails and badType names the shape
272
+ * (carrying the instantiation context). */
273
+ export declare function inferTypeParamBindings(L: Lowerer, expr: ts.CallExpression, info: GenericFnInfo, rsig: ts.Signature, tsBindings?: Map<ts.Symbol, ts.Type>): Map<ts.Symbol, IrType>;
255
274
  /** Type parameters still unbound after unification take their declared
256
275
  * DEFAULT (`<T = number>`), mapped — the checker already substituted the
257
276
  * default into every resolved signature, so this only fills the bindings
258
277
  * an instance body's mapType consults. */
259
- export declare function bindDefaultTypeParams(L: Lowerer, typeParams: readonly ts.Symbol[], typeParamDecls: readonly ts.TypeParameterDeclaration[] | undefined, bindings: Map<ts.Symbol, IrType>): void;
278
+ export declare function bindDefaultTypeParams(L: Lowerer, typeParams: readonly ts.Symbol[], typeParamDecls: readonly ts.TypeParameterDeclaration[] | undefined, bindings: Map<ts.Symbol, IrType>, tsBindings?: Map<ts.Symbol, ts.Type>): void;
260
279
  /** The structural half of binding inference: unify the DECLARED signature
261
280
  * (whose types mention the type parameters) against a TARGET signature
262
281
  * with the substitution applied — a call's resolved signature, or the
263
282
  * completed signature a VALUE reference is pinned to (the contextual
264
283
  * type's one call signature). Mutates `bindings`; already-bound
265
284
  * parameters (explicit type arguments) win. */
266
- export declare function unifySignatureBindings(L: Lowerer, info: GenericFnInfo, rsig: ts.Signature, bindings: Map<ts.Symbol, IrType>): void;
285
+ export declare function unifySignatureBindings(L: Lowerer, info: GenericFnInfo, rsig: ts.Signature, bindings: Map<ts.Symbol, IrType>, tsBindings?: Map<ts.Symbol, ts.Type>): void;
267
286
  /** Lowers ONE monomorphic instance of a generic function: the same body
268
287
  * AST, re-lowered with the type parameters bound (threaded into every
269
288
  * mapType call via typeParamResolver — the checker keeps reporting the
@@ -354,6 +373,36 @@ export declare const TIMER_MODULE_MEMBERS: ReadonlySet<string>;
354
373
  * timer function (the caller's fence machinery takes over). */
355
374
  export declare function lowerTimersMemberCall(L: Lowerer, expr: ts.CallExpression, member: string, loc: SrcLoc): IrExpr | null;
356
375
  export declare function lowerCall(L: Lowerer, expr: ts.CallExpression): IrExpr;
376
+ /** The RUNTIME-ARITY spread call — `f(...args)`, the rest-forwarding idiom
377
+ * (`const f = (...args) => from(...args)`): a spread whose length is a
378
+ * runtime fact has no home in the compile-time completion, so the call
379
+ * rides a dynamic boundary instead. Two lanes, picked by the spread
380
+ * source's tier:
381
+ *
382
+ * - CHECKED-DYNAMIC (dyn spread sources — a JS rest binding, a dyn
383
+ * value): box the callee (dynFrom; a dyn callee is already boxed),
384
+ * convert every argument into dyn, and emit the spread-marked dynCall
385
+ * — the emitters build one fresh DOM argument array (spreads flatten
386
+ * left-to-right, non-iterables throw V8's TypeError) and apply through
387
+ * it; the boxed thunk delivers JS arity exactly. Result dyn, checked
388
+ * per use like every any-origin value.
389
+ * - ISLAND (a jsval spread source — the --dynamic rest binding is the
390
+ * engine's own arguments array): marshal the callee in and emit jsOp
391
+ * callSpread — the prelude helper's REAL `f(...pre, ...s)`, so
392
+ * iterator protocols and the not-iterable TypeError are the engine's
393
+ * own. One trailing spread after the fixed arguments is the modeled
394
+ * shape (exactly the forwarding idiom).
395
+ *
396
+ * Answers null when neither lane fits (typed .ts spreads keep
397
+ * completeArgs' rest packing and its fences). JS sources only — the
398
+ * same guard as the over-arity dynCall precedent. */
399
+ export declare function lowerSpreadArgsCall(L: Lowerer, expr: ts.CallExpression, callee: IrExpr, loc: SrcLoc): IrExpr | null;
400
+ /** True when a spread argument lands where the compile-time completion
401
+ * cannot take it — a FIXED parameter position, or a dynamic rest slot
402
+ * (dynRest/islandRest, whose packs are built per-argument): the shapes
403
+ * the runtime-arity lane (lowerSpreadArgsCall) serves. Typed `rest`
404
+ * slots keep completeArgs' same-element spread packing. */
405
+ export declare function spreadNeedsRuntimeArity(shapes: readonly ParamShape[], argNodes: readonly ts.Expression[]): boolean;
357
406
  /** The SHARED prototype names scr_dyn_invoke dispatches at runtime (the
358
407
  * subset of DOM_PROTO_METHOD_NAMES with a receiver-kind dispatch): the
359
408
  * runtime runs the real method for the receiver's kind, throws Node's
@@ -534,6 +583,15 @@ export declare function bindingNeverReassigned(L: Lowerer, sym: ts.Symbol, decl:
534
583
  * SHAPE only — whether the binding qualifies (module scope, never
535
584
  * reassigned) is bindingGenericFnInfoOf's business. */
536
585
  export declare function bindingGenericFnNodeOf(decl: ts.VariableDeclaration): ts.FunctionExpression | ts.ArrowFunction | null;
586
+ /** The CONTEXTUAL twin of bindingGenericFnNodeOf: `const g: Mapper = (x)
587
+ * => x` where `type Mapper = <T>(x: T) => T` — the initializer declares
588
+ * no type parameters of its own, but the ANNOTATION's one call signature
589
+ * does, and the checker types the arrow's parameters by those (`x: T`).
590
+ * Such a binding monomorphizes exactly like `const g = <T>(x: T) => x`;
591
+ * bindingGenericFnInfoOf reads the type parameters off the annotation's
592
+ * signature. Null when the shape doesn't match (a concrete annotation, a
593
+ * generic arrow — the syntactic probe's case, an overloaded alias). */
594
+ export declare function bindingContextualGenericFnNodeOf(L: Lowerer, decl: ts.VariableDeclaration): ts.FunctionExpression | ts.ArrowFunction | null;
537
595
  /** The interned GenericFnInfo for one generic arrow/function-expression
538
596
  * binding initializer, with the supportability fences applied ONCE per
539
597
  * declaration: the binding must sit at module scope (the compiled
@@ -550,6 +608,18 @@ export declare function bindingGenericFnNodeOf(decl: ts.VariableDeclaration): ts
550
608
  * (calls, pinned values, instantiation expressions, namespace and CJS
551
609
  * member paths) resolves it like a top-level generic declaration. */
552
610
  export declare function bindingGenericFnInfoOf(L: Lowerer, decl: ts.VariableDeclaration, fnNode: ts.FunctionExpression | ts.ArrowFunction): GenericFnInfo;
611
+ /** `const h = id` — a binding ALIASING a generic function (a top-level
612
+ * declaration, a registered generic binding, or another alias — resolved
613
+ * left to right in declaration order). The alias registers the SAME info
614
+ * under its own symbol, so calls (`h(3)`) and pinned values (`take(h)`)
615
+ * resolve exactly like the target's own name, and the binding itself has
616
+ * no runtime value (a generic function value cannot materialize). Claims
617
+ * only bindings whose OWN type still keeps type parameters — a
618
+ * concrete-annotated alias (`const h: (x: number) => number = id`) is a
619
+ * pinned VALUE, the existing lowerGenericFnValue story. Null when the
620
+ * shape doesn't match or the target isn't a registered generic; fences
621
+ * (reassignment, var redeclaration) report by name inside. */
622
+ export declare function bindingGenericFnAliasInfoOf(L: Lowerer, decl: ts.VariableDeclaration): GenericFnInfo | null;
553
623
  /** Static resolution stands in for the receiver's runtime value, so an
554
624
  * object-literal generic-method receiver must provably HOLD the defining
555
625
  * literal: a direct read of a binding whose initializer IS that literal
@@ -560,17 +630,6 @@ export declare function bindingGenericFnInfoOf(L: Lowerer, decl: ts.VariableDecl
560
630
  * structurally identical literal with a DIFFERENT body, which static
561
631
  * resolution would silently miss. */
562
632
  export declare function requireObjLitGenericReceiver(L: Lowerer, blame: ts.Node, recvExpr: ts.Expression, literal: ts.ObjectLiteralExpression, name: string): void;
563
- /** `o.m(args)` where `m` is an object-literal GENERIC method (own type
564
- * parameters — the member is excluded from the record shape, see
565
- * isGenericCallableMemberType): monomorphized per call site against the
566
- * DEFINING literal's declaration, exactly like top-level generic
567
- * functions. Resolution is static, so the receiver must provably BE the
568
- * defining literal: a const binding whose initializer is that literal,
569
- * read directly. The receiver read is pure and the compiled instance is
570
- * a plain module function (no `this`, fenced), so the call lowers to a
571
- * direct `call` of the instance with the receiver unevaluated. Claims
572
- * every call whose member is generic-callable — lowering it or fencing
573
- * with a named message. */
574
633
  export declare function lowerObjLitGenericMethodCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression): IrExpr | null;
575
634
  /** `obj.method(args)` — whole-program devirtualization decides the form:
576
635
  * a method some strict subclass of the receiver's STATIC class overrides