@scriptc/compiler 0.0.4 → 0.0.5

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 (59) hide show
  1. package/dist/backend/cc.d.ts +16 -0
  2. package/dist/backend/cc.js +88 -0
  3. package/dist/backend/cc.js.map +1 -1
  4. package/dist/backend/emission/emit-async.js +2 -2
  5. package/dist/backend/emission/emit-async.js.map +1 -1
  6. package/dist/backend/emission/emit-exprs.js +2 -2
  7. package/dist/backend/emission/emit-exprs.js.map +1 -1
  8. package/dist/backend/emission/emit-shapes.js +2 -2
  9. package/dist/backend/emission/emit-shapes.js.map +1 -1
  10. package/dist/backend/emission/emit-walkers.js +7 -8
  11. package/dist/backend/emission/emit-walkers.js.map +1 -1
  12. package/dist/backend/emission/emitter.d.ts +1 -0
  13. package/dist/backend/emission/emitter.js +108 -0
  14. package/dist/backend/emission/emitter.js.map +1 -1
  15. package/dist/backend/llvm/emitter.js +133 -4
  16. package/dist/backend/llvm/emitter.js.map +1 -1
  17. package/dist/diagnostics/diagnostic.d.ts +25 -0
  18. package/dist/diagnostics/diagnostic.js +86 -0
  19. package/dist/diagnostics/diagnostic.js.map +1 -1
  20. package/dist/frontend/lib-exports.d.ts +16 -0
  21. package/dist/frontend/lib-exports.js +35 -0
  22. package/dist/frontend/lib-exports.js.map +1 -0
  23. package/dist/frontend/lowering/lower-calls.js +2 -2
  24. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  25. package/dist/frontend/lowering/lower-classes.js +1 -1
  26. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  27. package/dist/frontend/lowering/lower-exprs.js +1 -1
  28. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  29. package/dist/frontend/lowering/lower-island.js +1 -1
  30. package/dist/frontend/lowering/lower-island.js.map +1 -1
  31. package/dist/frontend/lowering/lower-mixins.js +4 -2
  32. package/dist/frontend/lowering/lower-mixins.js.map +1 -1
  33. package/dist/frontend/lowering/lower-stmts.js +107 -0
  34. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  35. package/dist/frontend/lowering/lowerer.d.ts +15 -1
  36. package/dist/frontend/lowering/lowerer.js +48 -9
  37. package/dist/frontend/lowering/lowerer.js.map +1 -1
  38. package/dist/frontend/npm-static-rewrite.d.ts +3 -0
  39. package/dist/frontend/npm-static-rewrite.js +677 -0
  40. package/dist/frontend/npm-static-rewrite.js.map +1 -0
  41. package/dist/frontend/npm-static.d.ts +8 -1
  42. package/dist/frontend/npm-static.js +159 -18
  43. package/dist/frontend/npm-static.js.map +1 -1
  44. package/dist/frontend/program.d.ts +6 -0
  45. package/dist/frontend/program.js +51 -14
  46. package/dist/frontend/program.js.map +1 -1
  47. package/dist/index.d.ts +22 -0
  48. package/dist/index.js +253 -17
  49. package/dist/index.js.map +1 -1
  50. package/dist/ir/nodes.d.ts +43 -0
  51. package/dist/ir/nodes.js +142 -0
  52. package/dist/ir/nodes.js.map +1 -1
  53. package/dist/ir/validate.js +51 -0
  54. package/dist/ir/validate.js.map +1 -1
  55. package/dist/library/profile.d.ts +52 -0
  56. package/dist/library/profile.js +232 -0
  57. package/dist/library/profile.js.map +1 -0
  58. package/package.json +2 -2
  59. package/surface-manifest.json +1 -1
@@ -195,6 +195,12 @@ export interface LowerOptions {
195
195
  * resolution walk and CJS named-import link check): the program
196
196
  * compiles to that startup crash. */
197
197
  startupCrash?: StartupCrash | null;
198
+ /** LIBRARY mode's reachability roots: the profile-mapped exports of the
199
+ * entry module. Executable builds root at the entry's top level alone
200
+ * (an unreferenced export dead-strips); a library's exports are called from
201
+ * OUTSIDE the graph, so discovery seeds them alongside the init
202
+ * bodies. Names are the entry file's unqualified declaration names. */
203
+ libRoots?: readonly string[];
198
204
  }
199
205
  /** The Lowerer's pass configuration (see lowerToIr). */
200
206
  export interface LowererMode {
@@ -786,7 +792,7 @@ export declare class Lowerer {
786
792
  * demand-driven) and lifted lambdas lower inline with their enclosing
787
793
  * body; both fire edges through the same hooks and are not units
788
794
  * themselves. */
789
- discover(): Set<string>;
795
+ discover(extraRoots?: readonly string[]): Set<string>;
790
796
  /** Discovery hook (see discover): fires when lowering resolves a
791
797
  * reference to a lowerable body. Inert in the emit pass. */
792
798
  noteEdge(name: string): void;
@@ -1523,6 +1529,14 @@ export declare class Lowerer {
1523
1529
  * through arrows (function expressions/declarations reset `this` in JS;
1524
1530
  * their bodies never see an enclosing method's binding). */
1525
1531
  resolveThis(): IrLocal | null;
1532
+ /** READ-ONLY twin of resolveLocal for PROBES (isIslandExpr): answers
1533
+ * the nearest binding entry without boxing, threading, or predeclaring.
1534
+ * resolveKey mutates capture state as a side effect, and a speculative
1535
+ * island-ness query through a context that takes no captures (a plain
1536
+ * declared function between the origin and the reference) was an ICE —
1537
+ * the REAL lowering path still resolves (and diagnoses) the reference
1538
+ * itself. */
1539
+ peekLocal(ident: ts.Identifier): IrLocal | null;
1526
1540
  resolveKey(symbol: ts.Symbol, blame?: ts.Node): IrLocal | null;
1527
1541
  isSelfReference(ident: ts.Identifier): boolean;
1528
1542
  lowerStmts(stmts: readonly ts.Statement[]): IrStmt[];
@@ -17,7 +17,7 @@ import * as ts from "../ts7/adapter.js";
17
17
  import { anyOpRequiresDynamicDiag, blockedBindingUseDiag, checkerPanicDiag, isCheckerPanic, genericSignatureTypeDiag, indexSignatureTypeDiag, noLoweringDiag, recordShapeMismatchDiag, requiresDynamicApiDiag, requiresDynamicPackageDiag, requiresDynamicTypeDiag, unionMismatchDiag, unsupportedDiag, unsupportedTypeDiag, } from "../../diagnostics/diagnostic.js";
18
18
  import { arrayOf, BOOL, canAdaptDynFuncTo, canConvertToDyn, canCrossIslandBoundary, canExitIslandToType, canMarshalTypedFuncIntoIsland, DYN, F64, isJsonSafeType, isUndefinedArmedUnion, isUnitType, JSVAL, RUNTIME_ERROR_CLASSES, STRING, typeEquals, UNDEFINED_T, VOID } from "../../ir/nodes.js";
19
19
  import { provenanceActive } from "../provenance-registry.js";
20
- import { ambientDtsPath, canonicalBuiltinModule, cjsExportAssignmentOf, cjsExportDiscardReason, fallbackDtsPath, isCjsExportTableLiteral, isJsSourceFile, isNodeEsmFile, isNodeTypesPath, locOf, overridesDtsPath, requireSpecOf, resolveImport, workspacePackageOfPath, } from "../program.js";
20
+ import { ambientDtsPath, canonicalBuiltinModule, cjsExportAssignmentOf, cjsExportDiscardReason, fallbackDtsPath, isCjsExportTableLiteral, isJsSourceFile, isNodeEsmFile, isNodeTypesPath, locOf, overridesDtsPath, npmStaticDepSf7, requireSpecOf, resolveImport, workspacePackageOfPath, } from "../program.js";
21
21
  import { containsRecord, containsUnion, formatIrType, ISLAND_AMBIENT_TYPES, isUnitOnlyTsType, mapType, ShapeRegistry, typeKey, UnionRegistry, withUndefinedArm as withUndefinedArmCanonical, } from "../types.js";
22
22
  import { boundaryIntoIslandMsg, boundaryOutOfIslandMsg, builtinConstLit, builtinModuleConstOf, builtinFenceHintOf, builtinModuleFnOf, stdlibMemberFence, isStdlibMember, isStdlibSymbol, isStdlibGlobal, stdlibGlobalMember, nodeTypesOnlySymbol } from "./surfaces.js";
23
23
  import { splitFiles, collectProgram, collectNpmImports, collectJsonImports, moduleArtifacts, collectGlobals, declSymbolOf, defaultExportSymbolOf, lowerFileInit, lowerDefaultExport, buildMain, appendDynamicImportModules } from "./lower-modules.js";
@@ -148,7 +148,7 @@ export function lowerToIr(program, entry, moduleOrder, options = {}) {
148
148
  const dynamic = options.dynamic ?? false;
149
149
  const targetPlatform = options.targetPlatform ?? process.platform;
150
150
  const startupCrash = options.startupCrash ?? null;
151
- const reachable = new Lowerer(program, entry, moduleOrder, dynamic, { targetPlatform }).discover();
151
+ const reachable = new Lowerer(program, entry, moduleOrder, dynamic, { targetPlatform }).discover(options.libRoots);
152
152
  const emit = new Lowerer(program, entry, moduleOrder, dynamic, { reachable, targetPlatform, startupCrash });
153
153
  const result = emit.run();
154
154
  if (options.coverage !== true)
@@ -1079,9 +1079,13 @@ export class Lowerer {
1079
1079
  return null;
1080
1080
  }
1081
1081
  const spec = importDecl.moduleSpecifier.text;
1082
- if (!isRelativeSpecifier(spec))
1083
- return null;
1084
- const dep = resolveImport(this.program, importDecl.getSourceFile(), spec);
1082
+ // Bare specifiers resolve only for opted-in --npm-static packages —
1083
+ // their CJS entries take the same default-binding interop as a
1084
+ // relative require; every other bare import answers null and keeps
1085
+ // its own machinery.
1086
+ const dep = isRelativeSpecifier(spec)
1087
+ ? resolveImport(this.program, importDecl.getSourceFile(), spec)
1088
+ : npmStaticDepSf7(this.program, importDecl.getSourceFile(), spec);
1085
1089
  if (!dep || !isJsSourceFile(dep) || isNodeEsmFile(dep))
1086
1090
  return null;
1087
1091
  return dep;
@@ -1575,7 +1579,7 @@ export class Lowerer {
1575
1579
  * demand-driven) and lifted lambdas lower inline with their enclosing
1576
1580
  * body; both fire edges through the same hooks and are not units
1577
1581
  * themselves. */
1578
- discover() {
1582
+ discover(extraRoots) {
1579
1583
  const parts = this.splitFiles();
1580
1584
  this.collectProgram(parts);
1581
1585
  // Decorated classes analyze post-collection here too: the %init seeds
@@ -1683,6 +1687,12 @@ export class Lowerer {
1683
1687
  this.lowerFileInit(fp.sf, fp.topStmts, this.initNameOf.get(fp.sf));
1684
1688
  drainInstances();
1685
1689
  });
1690
+ // LIBRARY mode's extra reachability roots (LowerOptions.libRoots): the
1691
+ // profile-mapped exports are called from outside the graph, so they
1692
+ // seed the worklist beside the init bodies. Unknown names are inert
1693
+ // (the export-map resolution reports them as SC4002 later).
1694
+ for (const root of extraRoots ?? [])
1695
+ this.onEdge?.(root);
1686
1696
  while (queue.length > 0) {
1687
1697
  // A body-level poison outside the per-statement catches (a fenced
1688
1698
  // constructor/method parameter default lowered by declareParams):
@@ -5473,6 +5483,27 @@ export class Lowerer {
5473
5483
  resolveThis() {
5474
5484
  return this.resolveKey(THIS_BINDING);
5475
5485
  }
5486
+ /** READ-ONLY twin of resolveLocal for PROBES (isIslandExpr): answers
5487
+ * the nearest binding entry without boxing, threading, or predeclaring.
5488
+ * resolveKey mutates capture state as a side effect, and a speculative
5489
+ * island-ness query through a context that takes no captures (a plain
5490
+ * declared function between the origin and the reference) was an ICE —
5491
+ * the REAL lowering path still resolves (and diagnoses) the reference
5492
+ * itself. */
5493
+ peekLocal(ident) {
5494
+ let symbol = this.checker.getSymbolAtLocation(ident);
5495
+ if (ident.parent && ts.isShorthandPropertyAssignment(ident.parent) && ident.parent.name === ident) {
5496
+ symbol = this.checker.getShorthandAssignmentValueSymbol(ident.parent) ?? symbol;
5497
+ }
5498
+ if (!symbol)
5499
+ return null;
5500
+ for (let depth = this.fnStack.length - 1; depth >= 0; depth--) {
5501
+ const hit = this.bindingIn(this.fnStack[depth], symbol);
5502
+ if (hit)
5503
+ return hit;
5504
+ }
5505
+ return null;
5506
+ }
5476
5507
  resolveKey(symbol, blame) {
5477
5508
  const direct = this.bindingIn(this.ctx, symbol);
5478
5509
  if (direct)
@@ -5506,6 +5537,17 @@ export class Lowerer {
5506
5537
  const ctx = this.fnStack[j];
5507
5538
  let entry = ctx.captureBySymbol.get(symbol);
5508
5539
  if (!entry) {
5540
+ // A context that takes NO captures (a plain declared function —
5541
+ // monomorphized/implicit instances lower this way) cannot carry
5542
+ // the binding through: the shape is a module binding whose only
5543
+ // storage is the init function's LOCAL (a typed-but-unmappable
5544
+ // const — the file-scope `new Map()` ledger idiom) read from
5545
+ // inside a nested instance. Fence it — in JS the statement
5546
+ // defers to its runtime trap like every collection failure;
5547
+ // asserting here was an ICE on ordinary npm-static JS.
5548
+ if (ctx.captures === null) {
5549
+ this.unsupported("SC1090", blame ?? this.checker.declarationsOf(symbol)[0] ?? this.entry, `the binding '${origin.name}' captured through a plain nested function (the declaration has no static storage a capture can thread — bind the value through a typed const, or read it in the declaring scope)`);
5550
+ }
5509
5551
  const count = ctx.localCounters.get(origin.name) ?? 0;
5510
5552
  ctx.localCounters.set(origin.name, count + 1);
5511
5553
  entry = {
@@ -5520,9 +5562,6 @@ export class Lowerer {
5520
5562
  };
5521
5563
  ctx.locals.push(entry);
5522
5564
  ctx.captureBySymbol.set(symbol, entry);
5523
- if (ctx.captures === null) {
5524
- throw new Error("lowerer bug: capture threading through a non-lifted function");
5525
- }
5526
5565
  ctx.captures.push({ localId: entry.id, name: entry.name, type: entry.type });
5527
5566
  ctx.captureSources.push(parentEntry.id);
5528
5567
  }