@geastack/compiler 1.0.49 → 1.0.63

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 (125) hide show
  1. package/README.md +57 -19
  2. package/dist/cli.js +2 -1
  3. package/dist/compiler.js +8 -2
  4. package/dist/conversion/derive.js +5 -0
  5. package/dist/conversion/native-field-view.d.ts +7 -0
  6. package/dist/conversion/native-field-view.js +50 -0
  7. package/dist/conversion/native-record-products.js +1 -0
  8. package/dist/conversion/native-view-origins.d.ts +1 -1
  9. package/dist/conversion/native-view-origins.js +5 -4
  10. package/dist/conversion/nodes.d.ts +9 -0
  11. package/dist/conversion/nodes.js +18 -0
  12. package/dist/conversion/record-view.d.ts +25 -1
  13. package/dist/conversion/record-view.js +61 -2
  14. package/dist/conversion/structural-plan.js +7 -6
  15. package/dist/ir/borrowed-field-reads.d.ts +30 -0
  16. package/dist/ir/borrowed-field-reads.js +218 -0
  17. package/dist/ir/borrowed-window-cells.d.ts +35 -0
  18. package/dist/ir/borrowed-window-cells.js +117 -0
  19. package/dist/ir/call-dispatch.js +21 -4
  20. package/dist/ir/callable-class-flow.js +269 -43
  21. package/dist/ir/captures.js +18 -1
  22. package/dist/ir/certify.js +14 -1
  23. package/dist/ir/construction-only-fields.d.ts +15 -1
  24. package/dist/ir/construction-only-fields.js +71 -3
  25. package/dist/ir/dead-logical-merge.d.ts +4 -0
  26. package/dist/ir/dead-logical-merge.js +89 -18
  27. package/dist/ir/dense-loops.d.ts +38 -4
  28. package/dist/ir/dense-loops.js +120 -18
  29. package/dist/ir/dense-read-windows.d.ts +42 -0
  30. package/dist/ir/dense-read-windows.js +137 -0
  31. package/dist/ir/facts.d.ts +12 -0
  32. package/dist/ir/facts.js +18 -2
  33. package/dist/ir/field-read-reuse.d.ts +71 -0
  34. package/dist/ir/field-read-reuse.js +430 -0
  35. package/dist/ir/hoist.d.ts +19 -2
  36. package/dist/ir/hoist.js +143 -24
  37. package/dist/ir/lower-narrow.js +19 -1
  38. package/dist/ir/model.d.ts +19 -0
  39. package/dist/ir/native-field-view-domains.d.ts +12 -2
  40. package/dist/ir/native-field-view-domains.js +51 -15
  41. package/dist/ir/native-field-view-facts.js +5 -2
  42. package/dist/ir/native-method-frames.js +15 -2
  43. package/dist/ir/plain-field-read.d.ts +31 -0
  44. package/dist/ir/plain-field-read.js +51 -0
  45. package/dist/ir/program-facts.d.ts +14 -0
  46. package/dist/ir/program-facts.js +85 -2
  47. package/dist/ir/proven-branches.js +8 -1
  48. package/dist/ir/publish-conversion-recipes.js +5 -1
  49. package/dist/ir/short-circuit-threading.d.ts +12 -4
  50. package/dist/ir/short-circuit-threading.js +124 -12
  51. package/dist/ir/stable-cell-reads.d.ts +24 -1
  52. package/dist/ir/stable-cell-reads.js +65 -42
  53. package/dist/ir/write-effects.d.ts +42 -0
  54. package/dist/ir/write-effects.js +208 -0
  55. package/dist/plugins/gea/contract.d.ts +3 -2
  56. package/dist/plugins/gea/contract.js +3 -1
  57. package/dist/plugins/gea/host.d.ts +7 -2
  58. package/dist/plugins/gea/host.js +25 -5
  59. package/dist/project-preparation.d.ts +11 -0
  60. package/dist/project-preparation.js +44 -0
  61. package/dist/projection/classes.d.ts +8 -0
  62. package/dist/projection/classes.js +112 -12
  63. package/dist/projection/dispatch.d.ts +24 -4
  64. package/dist/projection/dispatch.js +71 -2
  65. package/dist/projection/fields.js +2 -2
  66. package/dist/representation/model.d.ts +3 -0
  67. package/dist/representation/model.js +3 -0
  68. package/dist/representation/value-records.js +22 -0
  69. package/dist/semantics/frontend-timing.d.ts +9 -0
  70. package/dist/semantics/frontend-timing.js +43 -2
  71. package/dist/semantics/frontend.js +103 -7
  72. package/dist/semantics/model/operations.d.ts +7 -0
  73. package/dist/semantics/normalize/binding-fixpoint.js +7 -2
  74. package/dist/semantics/normalize/callable-data-write.js +6 -2
  75. package/dist/semantics/normalize/field-bindings.js +151 -111
  76. package/dist/semantics/normalize/flow/callable-reach.js +27 -0
  77. package/dist/semantics/normalize/flow/component-solver.js +23 -5
  78. package/dist/semantics/normalize/flow/source-record-data.js +6 -2
  79. package/dist/semantics/normalize/flow/source-value-session.d.ts +13 -0
  80. package/dist/semantics/normalize/flow/source-value-session.js +207 -65
  81. package/dist/semantics/normalize/global-host-mutations.js +162 -1
  82. package/dist/semantics/normalize/parameter-bindings.js +16 -1
  83. package/dist/semantics/normalize/producers/class-lifecycle.js +2 -1
  84. package/dist/semantics/normalize/producers/erasure.js +13 -8
  85. package/dist/semantics/subclass-member-overlay-transform.js +17 -4
  86. package/dist/semantics/typescript-tsgo.d.ts +20 -0
  87. package/dist/semantics/typescript-tsgo.js +832 -0
  88. package/dist/semantics/typescript.d.ts +0 -9
  89. package/dist/semantics/typescript.js +4 -1
  90. package/dist/targets/cpp/borrowed-call-entry.d.ts +9 -0
  91. package/dist/targets/cpp/borrowed-call-entry.js +12 -2
  92. package/dist/targets/cpp/captures.js +4 -0
  93. package/dist/targets/cpp/class-properties/computed-method-value.d.ts +1 -1
  94. package/dist/targets/cpp/class-properties/computed-method-value.js +17 -7
  95. package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +8 -0
  96. package/dist/targets/cpp/class-properties/emit-class-properties.js +62 -2
  97. package/dist/targets/cpp/class-properties/native-method-read.js +12 -1
  98. package/dist/targets/cpp/conversions.js +1 -0
  99. package/dist/targets/cpp/emit-arrays.d.ts +5 -0
  100. package/dist/targets/cpp/emit-arrays.js +60 -10
  101. package/dist/targets/cpp/emit-binding-reference.d.ts +19 -6
  102. package/dist/targets/cpp/emit-binding-reference.js +26 -8
  103. package/dist/targets/cpp/emit-bindings.js +22 -0
  104. package/dist/targets/cpp/emit-callable.js +133 -16
  105. package/dist/targets/cpp/emit-carrier-members.d.ts +6 -0
  106. package/dist/targets/cpp/emit-carrier-members.js +24 -2
  107. package/dist/targets/cpp/emit-context.d.ts +97 -1
  108. package/dist/targets/cpp/emit-context.js +52 -0
  109. package/dist/targets/cpp/emit-equality.js +3 -0
  110. package/dist/targets/cpp/emit-narrowing.js +9 -0
  111. package/dist/targets/cpp/emit-native-field-view.d.ts +24 -0
  112. package/dist/targets/cpp/emit-native-field-view.js +87 -8
  113. package/dist/targets/cpp/emit-properties.js +139 -16
  114. package/dist/targets/cpp/emit-record-view.js +49 -22
  115. package/dist/targets/cpp/emit-return.js +5 -1
  116. package/dist/targets/cpp/emit-tonumber.js +4 -1
  117. package/dist/targets/cpp/emit-union-properties.js +1 -1
  118. package/dist/targets/cpp/emit.d.ts +4 -1
  119. package/dist/targets/cpp/emit.js +148 -6
  120. package/dist/targets/cpp/reactive-dependencies.js +100 -28
  121. package/dist/targets/cpp/translation-unit.js +71 -17
  122. package/dist/targets/cpp/virtual-methods.d.ts +2 -2
  123. package/dist/targets/cpp/virtual-methods.js +11 -3
  124. package/package.json +1 -1
  125. package/src/targets/cpp/runtime/gea_runtime.h +400 -21
@@ -1,3 +1,4 @@
1
+ import { progress } from '../frontend-timing.js'; // WIP-SOLVER-TIMING: not for commit
1
2
  import { callableCompletionSummaryOf } from './flow/callable-completions.js';
2
3
  import { relative } from 'node:path';
3
4
  import ts from '#typescript';
@@ -1229,10 +1230,152 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
1229
1230
  * instance). Without it the answer is identity only -- the global object, a
1230
1231
  * standard-library binding, or a local cell some write fills with one.
1231
1232
  */
1233
+ // Defined ahead of every census consumer: `isIntrinsicSurface` asks it while
1234
+ // the alias facts below are still being built.
1235
+ const completionValuesOf = (declaration) => {
1236
+ const summary = callableCompletionSummaryOf(flow, declaration);
1237
+ return summary === null ? [] : [...summary.values, ...summary.yields];
1238
+ };
1239
+ /**
1240
+ * What a call resolved to a source method can complete with: the values of
1241
+ * that body and of every override a class below its declaring class
1242
+ * supplies, since a receiver typed as the declaring class may hold any of
1243
+ * them. An abstract declaration contributes no body: an instance of its own
1244
+ * class misses the lookup and throws before completing. A class whose
1245
+ * `extends` this scan cannot resolve might be a subclass, so it counts. A
1246
+ * write to the slot, a non-method member under the name, or a body whose
1247
+ * completion this census cannot state leaves the answer unknown (`null`).
1248
+ */
1249
+ const methodCompletionValues = new Map();
1250
+ let programClasses = null;
1251
+ const methodFamilyCompletionValuesOf = (declaration) => {
1252
+ const known = methodCompletionValues.get(declaration);
1253
+ if (known !== undefined)
1254
+ return known;
1255
+ const answer = methodFamilyCompletionValuesUncached(declaration);
1256
+ methodCompletionValues.set(declaration, answer);
1257
+ return answer;
1258
+ };
1259
+ const methodFamilyCompletionValuesUncached = (declaration) => {
1260
+ if ((ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Static) !== 0)
1261
+ return null;
1262
+ const owner = declaration.parent;
1263
+ const name = declaration.name;
1264
+ if (!ts.isClassLike(owner) || !(ts.isIdentifier(name) || ts.isPrivateIdentifier(name)))
1265
+ return null;
1266
+ const slot = checker.getSymbolAtLocation(name);
1267
+ if (slot === undefined || flow.writesToSymbol(slot).length > 0)
1268
+ return null;
1269
+ const family = new Set([owner]);
1270
+ const classes = (programClasses ??= nodes.filter((node) => ts.isClassDeclaration(node) || ts.isClassExpression(node)));
1271
+ for (let grew = true; grew;) {
1272
+ grew = false;
1273
+ for (const candidate of classes) {
1274
+ if (family.has(candidate))
1275
+ continue;
1276
+ const heritage = candidate.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
1277
+ if (!heritage)
1278
+ continue;
1279
+ const extended = actualSymbol(checker.getSymbolAtLocation(unwrapErasedExpression(heritage.expression)))?.valueDeclaration;
1280
+ if (extended === undefined || !ts.isClassLike(extended) || family.has(extended)) {
1281
+ family.add(candidate);
1282
+ grew = true;
1283
+ }
1284
+ }
1285
+ }
1286
+ const values = [];
1287
+ let implemented = false;
1288
+ for (const member of family) {
1289
+ for (const element of member.members) {
1290
+ if (element.name === undefined || !(ts.isIdentifier(element.name) || ts.isPrivateIdentifier(element.name)))
1291
+ continue;
1292
+ if (element.name.text !== name.text)
1293
+ continue;
1294
+ if (!ts.isMethodDeclaration(element))
1295
+ return null;
1296
+ if ((ts.getCombinedModifierFlags(element) & ts.ModifierFlags.Static) !== 0)
1297
+ continue;
1298
+ if (element.body === undefined)
1299
+ continue;
1300
+ const completed = completionValuesOf(element);
1301
+ if (completed.length === 0)
1302
+ return null;
1303
+ implemented = true;
1304
+ values.push(...completed);
1305
+ }
1306
+ }
1307
+ return implemented ? values : null;
1308
+ };
1309
+ /**
1310
+ * Whether a call always completes with an object this program allocated
1311
+ * itself -- an object or array literal -- read through const-like locals
1312
+ * and further such calls. It asks nothing of the callee's parameters or
1313
+ * receiver: a refused invocation (one whose argument forwarding this census
1314
+ * could not model) can still be known to return a fresh object, which is
1315
+ * neither the global object nor an intrinsic.
1316
+ */
1317
+ const callReturnsFreshObject = (call, seen) => {
1318
+ if (seen.has(call) || seen.size > 32)
1319
+ return false;
1320
+ seen.add(call);
1321
+ try {
1322
+ return callCompletionsAreFresh(call, seen);
1323
+ }
1324
+ finally {
1325
+ seen.delete(call);
1326
+ }
1327
+ };
1328
+ const callCompletionsAreFresh = (call, seen) => {
1329
+ const declaration = checker.getResolvedSignature(call)?.declaration;
1330
+ if (declaration === undefined || ts.isJSDocSignature(declaration) || declaration.getSourceFile().isDeclarationFile)
1331
+ return false;
1332
+ let completions = null;
1333
+ if (ts.isMethodDeclaration(declaration))
1334
+ completions = methodFamilyCompletionValuesOf(declaration);
1335
+ else if (ts.isFunctionDeclaration(declaration) && declaration.body !== undefined && declaration.name !== undefined) {
1336
+ // A function's own `return` values are filed under it too; only an
1337
+ // assignment to the binding replaces the function.
1338
+ const written = flow
1339
+ .writesToDeclaration(declaration)
1340
+ .some((write) => write.slot === 'whole' &&
1341
+ (write.edge === 'identifier-assignment' || write.edge === 'compound-assignment' || write.edge === 'logical-assignment'));
1342
+ const symbol = checker.getSymbolAtLocation(declaration.name);
1343
+ if (!written && symbol !== undefined && (symbol.declarations?.length ?? 0) === 1)
1344
+ completions = completionValuesOf(declaration);
1345
+ }
1346
+ return completions !== null && completions.length > 0 && completions.every((value) => valueIsFreshObject(value, seen));
1347
+ };
1348
+ const valueIsFreshObject = (expression, seen) => {
1349
+ const current = unwrapErasedExpression(expression);
1350
+ if (ts.isObjectLiteralExpression(current) || ts.isArrayLiteralExpression(current))
1351
+ return true;
1352
+ if (ts.isConditionalExpression(current))
1353
+ return valueIsFreshObject(current.whenTrue, seen) && valueIsFreshObject(current.whenFalse, seen);
1354
+ if (ts.isCallExpression(current))
1355
+ return callReturnsFreshObject(current, seen);
1356
+ if (!ts.isIdentifier(current))
1357
+ return false;
1358
+ const binding = bindingOf(current);
1359
+ if (binding === null || !ts.isVariableDeclaration(binding) || seen.has(binding))
1360
+ return false;
1361
+ seen.add(binding);
1362
+ try {
1363
+ const writes = flow.writesToDeclaration(binding).filter((write) => write.slot === 'whole');
1364
+ return writes.length > 0 && writes.every((write) => write.value !== null && valueIsFreshObject(write.value, seen));
1365
+ }
1366
+ finally {
1367
+ seen.delete(binding);
1368
+ }
1369
+ };
1232
1370
  const isIntrinsicSurface = (expression, seen = new Set(), byType = true) => {
1233
1371
  const current = unwrapErasedExpression(expression);
1234
1372
  if (hasFreshLiteralIdentity(current))
1235
1373
  return false;
1374
+ // A value that is always the program's own fresh allocation (a literal,
1375
+ // read through locals and calls whose every runnable body returns one) is
1376
+ // that allocation, whatever intrinsic its declared type admits.
1377
+ if (valueIsFreshObject(current, new Set()))
1378
+ return false;
1236
1379
  if (isProvenGlobalObject(current) ||
1237
1380
  (byType &&
1238
1381
  (nativeResult(checker.getTypeAtLocation(current), current) || mayBeAuthenticatedNativeSurface(checker.getTypeAtLocation(current))))) {
@@ -2085,7 +2228,11 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
2085
2228
  // backs it, so it carries no publication dependency -- and must still
2086
2229
  // go through the same memo the rest of this function writes, or the
2087
2230
  // dependency solver below never sees it as grounded and discards it.
2088
- const result = publishedTypeRepresentation(publishedTypeAt(current), current);
2231
+ //
2232
+ // A result type an intrinsic could inhabit (`Document`) still publishes
2233
+ // `object` when every body the call can run returns a fresh allocation
2234
+ // of its own (`callReturnsFreshObject`), which reads no parameter.
2235
+ const result = publishedTypeRepresentation(publishedTypeAt(current), current) ?? (callReturnsFreshObject(current, new Set()) ? 'object' : null);
2089
2236
  publishedRepresentations.set(current, result);
2090
2237
  return result;
2091
2238
  }
@@ -2814,7 +2961,12 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
2814
2961
  // so they do leave the call incomplete. Delete this exception together with
2815
2962
  // that walk, once the shared layout grows per-binding-element slots.
2816
2963
  const frameForwardingIsModelled = (frame) => frame.forwarding.kind === 'values' || frame.forwarding.reason === 'destructured-parameter';
2964
+ let wipSites = 0; // WIP-SOLVER-TIMING
2965
+ let wipClosedMs = 0;
2966
+ let wipSlowest = 0;
2817
2967
  for (const site of reachableFlowCalls) {
2968
+ if (++wipSites % 500 === 0)
2969
+ progress(`host-mutations call sites ${wipSites}/${reachableFlowCalls.length}, closedCalleeBodiesOf ${(wipClosedMs / 1000).toFixed(1)}s, slowest ${(wipSlowest / 1000).toFixed(1)}s`);
2818
2970
  const explicitDeclaration = site.explicitThis ? flow.targetOf(site.explicitThis.callee)?.declaration : null;
2819
2971
  const staticDeclaration = explicitDeclaration && ts.isFunctionLike(explicitDeclaration)
2820
2972
  ? explicitDeclaration
@@ -2932,7 +3084,16 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
2932
3084
  // authority, which knows about the escape, so `sink( receiver );
2933
3085
  // receiver.run( globalThis )` was admitted as running only program bodies
2934
3086
  // and never asked whether it hands the global object to an open callee.
3087
+ if (wipSites >= Number(process.env['GEA_WIP_TRACE_FROM'] ?? Infinity)) {
3088
+ const wipFile = site.call.getSourceFile();
3089
+ progress(`host-mutations site ${wipSites} ${wipFile.fileName.split('/').pop()}:${wipFile.getLineAndCharacterOfPosition(site.call.getStart(wipFile)).line + 1} ${site.call.getText(wipFile).replace(/\s+/g, ' ').slice(0, 100)}`);
3090
+ }
3091
+ const wipAt = performance.now();
2935
3092
  const closedBodies = callableFrames.closedCalleeBodiesOf?.(site.call) ?? null;
3093
+ const wipTook = performance.now() - wipAt;
3094
+ wipClosedMs += wipTook;
3095
+ if (wipTook > wipSlowest)
3096
+ wipSlowest = wipTook;
2936
3097
  const allocationProven = process.env['GEA_NO_ALLOCATION_PROVEN'] !== '1' &&
2937
3098
  closedBodies !== null &&
2938
3099
  closedBodies.length > 0 &&
@@ -3756,6 +3756,14 @@ hostProvided = noHostProvidedNames) => {
3756
3756
  publishing.reset();
3757
3757
  /** Answers for `statedTypeAt`, settled once the fixpoint above has stopped. */
3758
3758
  const statedTypes = new NullableMemo();
3759
+ const refusedParameterCell = (node) => {
3760
+ if (ts.isParameter(node))
3761
+ return lastRefusal.has(node);
3762
+ if (!ts.isIdentifier(node))
3763
+ return false;
3764
+ const parameter = checker.getSymbolAtLocation(node)?.declarations?.find(ts.isParameter);
3765
+ return parameter !== undefined && lastRefusal.has(parameter);
3766
+ };
3759
3767
  const computeStatedTypeAt = (node) => {
3760
3768
  // A PRIOR ROUND's stated narrowings are forwarded, the same way `known`
3761
3769
  // above forwards `upstream.typeAt`: round two exists precisely so a
@@ -3778,7 +3786,14 @@ hostProvided = noHostProvidedNames) => {
3778
3786
  finally {
3779
3787
  inheritedStatedLookups.depth--;
3780
3788
  }
3781
- if (inherited)
3789
+ // ...except a parameter this round re-decided and refused. A prior round
3790
+ // bound it from a smaller view (a field it reads was not yet widened to
3791
+ // `any`, say), and this round's refusal is the settled fact: `typeAt`,
3792
+ // which the ABI slot reads (`structural-parts.ts`'s `parameterOf`),
3793
+ // answers only this round's bindings, so forwarding the stale narrowing
3794
+ // to the body alone splits the cell into "parameter N is bound as
3795
+ // `array-object(string)` but the ABI declares `array-object(dynamic)`".
3796
+ if (inherited && !(lastRefusal.size !== 0 && refusedParameterCell(node)))
3782
3797
  return inherited;
3783
3798
  if (ts.isParameter(node))
3784
3799
  return statedBindings.size === 0 ? null : (statedBindings.get(node) ?? null);
@@ -710,7 +710,8 @@ export const createClassLifecycleProducer = (context) => {
710
710
  allocates: true,
711
711
  callsUserCode: false
712
712
  });
713
- operations.push(defineOperation);
713
+ const abstractMember = node.body === undefined && (ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.AbstractKeyword) ?? false);
714
+ operations.push(abstractMember ? { ...defineOperation, abstractMember: true } : defineOperation);
714
715
  if (methodValue)
715
716
  edges.push({ kind: 'value', result: methodValue.id, to: defineId, role: 'method', ordinal: 0 });
716
717
  if (keySource) {
@@ -16,17 +16,22 @@ import ts from '#typescript';
16
16
  * silent -- so there is one, and it is the only one.
17
17
  */
18
18
  export const unwrapErased = (node) => {
19
+ // One switch on the kind rather than five `ts.is*` calls: the value-flow
20
+ // solver unwraps every expression it interns, hundreds of millions of times
21
+ // on a large program, and almost none of them are wrapped.
19
22
  let current = node;
20
23
  for (;;) {
21
- if (ts.isParenthesizedExpression(current) ||
22
- ts.isNonNullExpression(current) ||
23
- ts.isAsExpression(current) ||
24
- ts.isSatisfiesExpression(current) ||
25
- ts.isTypeAssertionExpression(current)) {
26
- current = current.expression;
27
- continue;
24
+ switch (current.kind) {
25
+ case ts.SyntaxKind.ParenthesizedExpression:
26
+ case ts.SyntaxKind.NonNullExpression:
27
+ case ts.SyntaxKind.AsExpression:
28
+ case ts.SyntaxKind.SatisfiesExpression:
29
+ case ts.SyntaxKind.TypeAssertionExpression:
30
+ current = current.expression;
31
+ continue;
32
+ default:
33
+ return current;
28
34
  }
29
- return current;
30
35
  }
31
36
  };
32
37
  /** The same rule where the caller already knows it holds an expression. */
@@ -857,11 +857,24 @@ const compactScan = (scan) => {
857
857
  return EMPTY_SCAN;
858
858
  return { ...scan, externallyReadNames: [...new Set(scan.externallyReadNames)].map(sharedName) };
859
859
  };
860
- const buildPackageIndex = (root, read, neverSkip, graph) => {
860
+ const buildPackageIndex = (root, read, neverSkip, graph, compiled) => {
861
861
  const found = collectSourceFiles(root, neverSkip);
862
862
  // a confined file is the program's own or not indexed at all (see `ancestryBetween`)
863
863
  const confined = found.confined.filter((filePath) => graph.has(resolve(filePath)));
864
- const key = confined.length === 0 ? indexKey(root, neverSkip) : `${indexKey(root, neverSkip)}\n${confined.join('\n')}`;
864
+ // A program that itself lives in a skipped directory is not the package it
865
+ // sits in: the package's other files are its scenery exactly as its
866
+ // directory's neighbours are, so they too are indexed only from its graph.
867
+ // Without this, any `.js` elsewhere under the root -- an untracked fixture,
868
+ // a vendored suite -- declaring a class of the same name dropped the
869
+ // program's own class as a duplicate, and a checkout holding such files
870
+ // emitted different text and identities than a clean one.
871
+ const programIsConfined = found.confined.some((filePath) => resolve(filePath) === compiled);
872
+ const files = programIsConfined ? found.files.filter((filePath) => graph.has(resolve(filePath))) : found.files;
873
+ const key = programIsConfined
874
+ ? `${indexKey(root, neverSkip)}\n\n${[...files, ...confined].join('\n')}`
875
+ : confined.length === 0
876
+ ? indexKey(root, neverSkip)
877
+ : `${indexKey(root, neverSkip)}\n${confined.join('\n')}`;
865
878
  const cached = cachesFor(read).index.get(key);
866
879
  if (cached)
867
880
  return cached;
@@ -872,7 +885,7 @@ const buildPackageIndex = (root, read, neverSkip, graph) => {
872
885
  const externallyReadNames = new Set();
873
886
  const constantDomainsByName = new Map();
874
887
  const duplicateConstants = new Set();
875
- for (const filePath of [...found.files, ...confined]) {
888
+ for (const filePath of [...files, ...confined]) {
876
889
  let text;
877
890
  try {
878
891
  text = read(filePath);
@@ -1235,7 +1248,7 @@ export const createSubclassMemberOverlayTransform = (read, roots = []) => {
1235
1248
  // the package, so a file declaring no class does not pay for it.
1236
1249
  if (!file.statements.some((statement) => ts.isClassDeclaration(statement) && statement.name !== undefined))
1237
1250
  return null;
1238
- const index = buildPackageIndex(root, read, ancestryBetween(root, input.fileName), graphFor(input.fileName));
1251
+ const index = buildPackageIndex(root, read, ancestryBetween(root, input.fileName), graphFor(input.fileName), here);
1239
1252
  const boundHere = new Set();
1240
1253
  let leadingImportEnd = 0;
1241
1254
  let stillLeading = true;
@@ -0,0 +1,20 @@
1
+ import type TypeScript from 'typescript';
2
+ /**
3
+ * EXPERIMENT (`GEA_TS_BACKEND=tsgo`): TypeScript's own parser and program
4
+ * graph, with typescript-go's checker behind them.
5
+ *
6
+ * `createProgram` still builds the program with TypeScript -- module
7
+ * resolution, the source transforms and every file's final text stay exactly
8
+ * as they are -- and then opens the same texts in typescript-go (loaded
9
+ * in-process through `tscapi.dll`). The program's `getTypeChecker` answers
10
+ * from typescript-go: its types, symbols and signatures are facades over
11
+ * typescript-go handles, and every node it names is mapped back to
12
+ * TypeScript's node at the same file, kind and span, so the rest of the
13
+ * compiler keeps walking the AST it always has.
14
+ *
15
+ * Configuration: `GEA_TSGO_DLL` (the bridge), `GEA_TSGO_KOFFI` (the FFI
16
+ * module), `GEA_TSGO_FLAGS` (typescript-go's flag bit table).
17
+ */
18
+ type Ts = typeof TypeScript;
19
+ export declare const tsgoTypeScript: (real: Ts) => Ts;
20
+ export {};