@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
@@ -1333,6 +1333,64 @@ flow) => {
1333
1333
  return !jsDocType || jsDocTypeStatesNothing(checker, jsDocType);
1334
1334
  };
1335
1335
  const widenedFields = new Set();
1336
+ let reachSettled = null;
1337
+ const reachOpen = new Map();
1338
+ const reachStack = [];
1339
+ const reachCalls = [];
1340
+ let reachIndex = 0;
1341
+ const reach = (kind, node, walk) => {
1342
+ if (!reachSettled) {
1343
+ // A query outside the widening fixpoint settles against a memo of its own.
1344
+ reachSettled = new Map();
1345
+ try {
1346
+ return reach(kind, node, walk);
1347
+ }
1348
+ finally {
1349
+ reachSettled = null;
1350
+ reachOpen.clear();
1351
+ reachStack.length = 0;
1352
+ reachCalls.length = 0;
1353
+ }
1354
+ }
1355
+ const settled = reachSettled.get(kind)?.get(node);
1356
+ if (settled !== undefined)
1357
+ return settled;
1358
+ const caller = reachCalls[reachCalls.length - 1];
1359
+ const open = reachOpen.get(kind)?.get(node);
1360
+ if (open) {
1361
+ if (caller && open.index < caller.low)
1362
+ caller.low = open.index;
1363
+ return open.dynamic;
1364
+ }
1365
+ const frame = { kind, node, index: reachIndex, position: reachStack.length, low: reachIndex, dynamic: false };
1366
+ reachIndex++;
1367
+ (reachOpen.get(kind) ?? reachOpen.set(kind, new Map()).get(kind)).set(node, frame);
1368
+ reachStack.push(frame);
1369
+ reachCalls.push(frame);
1370
+ try {
1371
+ frame.dynamic = walk();
1372
+ }
1373
+ finally {
1374
+ reachCalls.pop();
1375
+ }
1376
+ if (caller && frame.low < caller.low)
1377
+ caller.low = frame.low;
1378
+ if (frame.low !== frame.index)
1379
+ return frame.dynamic;
1380
+ const members = reachStack.splice(frame.position);
1381
+ const dynamic = members.some((member) => member.dynamic);
1382
+ for (const member of members) {
1383
+ reachOpen.get(member.kind).delete(member.node);
1384
+ (reachSettled.get(member.kind) ?? reachSettled.set(member.kind, new Map()).get(member.kind)).set(member.node, dynamic);
1385
+ }
1386
+ return dynamic;
1387
+ };
1388
+ const forgetCleanVerdicts = () => {
1389
+ for (const byNode of reachSettled?.values() ?? [])
1390
+ for (const [node, dynamic] of byNode)
1391
+ if (!dynamic)
1392
+ byNode.delete(node);
1393
+ };
1336
1394
  /**
1337
1395
  * The candidate field a member read copies, by declaration: a read through a
1338
1396
  * receiver only the census typed names the instance type's own property
@@ -1389,9 +1447,12 @@ flow) => {
1389
1447
  * literal -- leaves the read typed although the parameter itself is boxed.
1390
1448
  * A class instance is not taken to lack a member a subclass may declare.
1391
1449
  */
1392
- const untypedSource = (source, key, depth = 0) => {
1450
+ const untypedSource = (source, key) => {
1393
1451
  if (ts.isParameter(source))
1394
- return parameterSuppliesUntypedSource(source, key, depth);
1452
+ return parameterSuppliesUntypedSource(source, key);
1453
+ return reach(key === null ? 'source' : `source:${key}`, source, () => expressionIsUntypedSource(source, key));
1454
+ };
1455
+ const expressionIsUntypedSource = (source, key) => {
1395
1456
  if (readsWidenedField(source))
1396
1457
  return true;
1397
1458
  if ((checker.getTypeAtLocation(source).flags & ts.TypeFlags.Any) === 0)
@@ -1402,22 +1463,21 @@ flow) => {
1402
1463
  // An object the checker types `any` is only as untyped as where it came
1403
1464
  // from: a call's result, a member read, a `const` holding either.
1404
1465
  if (ts.isCallExpression(unwrapped) || ts.isNewExpression(unwrapped))
1405
- return callReturnsDynamicValue(unwrapped, depth);
1466
+ return callReturnsDynamicValue(unwrapped);
1406
1467
  if (ts.isPropertyAccessExpression(unwrapped) || ts.isElementAccessExpression(unwrapped))
1407
- return writesDynamicValue(unwrapped, depth + 1);
1468
+ return writesDynamicValue(unwrapped);
1408
1469
  if (!ts.isIdentifier(unwrapped))
1409
1470
  return true;
1410
1471
  const declaration = checker.getSymbolAtLocation(unwrapped)?.valueDeclaration;
1411
1472
  if (declaration && ts.isParameter(declaration))
1412
- return parameterSuppliesUntypedSource(declaration, key, depth);
1473
+ return parameterSuppliesUntypedSource(declaration, key);
1413
1474
  if (declaration && ts.isVariableDeclaration(declaration) && parameters.typeAt(declaration))
1414
1475
  return false;
1415
1476
  if (declaration &&
1416
1477
  ts.isVariableDeclaration(declaration) &&
1417
1478
  declaration.initializer &&
1418
- (ts.getCombinedNodeFlags(declaration) & ts.NodeFlags.Const) !== 0 &&
1419
- depth <= 8)
1420
- return untypedSource(declaration.initializer, key, depth + 1);
1479
+ (ts.getCombinedNodeFlags(declaration) & ts.NodeFlags.Const) !== 0)
1480
+ return untypedSource(declaration.initializer, key);
1421
1481
  return true;
1422
1482
  };
1423
1483
  /** The values a parameter receives: its default, its call sites' arguments, and its body's own assignments to it. */
@@ -1458,8 +1518,7 @@ flow) => {
1458
1518
  return (checker.getTypeOfSymbolAtLocation(member, at).flags & ts.TypeFlags.Any) !== 0;
1459
1519
  });
1460
1520
  };
1461
- const visitingSourceParameters = new Set();
1462
- const parameterSuppliesUntypedSource = (parameter, key, depth) => {
1521
+ const parameterSuppliesUntypedSource = (parameter, key) => {
1463
1522
  if (parameters.typeAt(parameter))
1464
1523
  return false;
1465
1524
  // A destructured parameter names no slot the flow index files call-site
@@ -1467,22 +1526,14 @@ flow) => {
1467
1526
  // pattern's implied record of `any` members, and that is what it supplies.
1468
1527
  if (!ts.isIdentifier(parameter.name))
1469
1528
  return true;
1470
- if (depth > 8 || visitingSourceParameters.has(parameter))
1471
- return false;
1472
- visitingSourceParameters.add(parameter);
1473
- try {
1474
- return valuesReceivedBy(parameter).some((value) => {
1475
- if (untypedSource(value, key, depth + 1))
1476
- return true;
1477
- if (key === null)
1478
- return false;
1479
- const type = knownOrResolve(value);
1480
- return type !== null && typedSourceLeavesKeyUntyped(type, key, value);
1481
- });
1482
- }
1483
- finally {
1484
- visitingSourceParameters.delete(parameter);
1485
- }
1529
+ return reach(key === null ? 'supplies' : `supplies:${key}`, parameter, () => valuesReceivedBy(parameter).some((value) => {
1530
+ if (untypedSource(value, key))
1531
+ return true;
1532
+ if (key === null)
1533
+ return false;
1534
+ const type = knownOrResolve(value);
1535
+ return type !== null && typedSourceLeavesKeyUntyped(type, key, value);
1536
+ }));
1486
1537
  };
1487
1538
  /**
1488
1539
  * A member read off a receiver the census typed, whose own type for the
@@ -1492,7 +1543,7 @@ flow) => {
1492
1543
  * the member holds. A member the receiver lacks is an absence, and a
1493
1544
  * literal's member holds what its initializer does.
1494
1545
  */
1495
- const readsDeclaredDynamicMember = (read, depth) => {
1546
+ const readsDeclaredDynamicMember = (read) => {
1496
1547
  const receiver = receiverTypeOf(read.expression);
1497
1548
  if (!receiver)
1498
1549
  return false;
@@ -1509,9 +1560,9 @@ flow) => {
1509
1560
  return isAny(checker.getIndexTypeOfType(holder, ts.IndexKind.String) ?? undefined);
1510
1561
  const declaration = member.valueDeclaration;
1511
1562
  if (declaration && ts.isPropertyAssignment(declaration))
1512
- return writesDynamicValue(declaration.initializer, depth + 1);
1563
+ return writesDynamicValue(declaration.initializer);
1513
1564
  if (declaration && ts.isShorthandPropertyAssignment(declaration))
1514
- return writesDynamicValue(declaration.name, depth + 1);
1565
+ return writesDynamicValue(declaration.name);
1515
1566
  if (declaration && ts.isBinaryExpression(declaration))
1516
1567
  return false;
1517
1568
  return isAny(checker.getTypeOfSymbolAtLocation(member, read));
@@ -1526,9 +1577,8 @@ flow) => {
1526
1577
  return ts.isVariableDeclaration(holder) && holder.initializer ? holder.initializer : null;
1527
1578
  };
1528
1579
  /** Whether `value` reaches its field as an untyped dynamic value, whatever it holds. */
1529
- const writesDynamicValue = (value, depth = 0) => {
1530
- if (depth > 8)
1531
- return false;
1580
+ const writesDynamicValue = (value) => reach('writes', value, () => valueIsDynamic(value));
1581
+ const valueIsDynamic = (value) => {
1532
1582
  if (readsWidenedField(value))
1533
1583
  return true;
1534
1584
  if ((checker.getTypeAtLocation(value).flags & ts.TypeFlags.Any) === 0)
@@ -1545,13 +1595,13 @@ flow) => {
1545
1595
  // `opts.pageOffset || 0` over an `opts` the census typed stores that
1546
1596
  // record's member, an absence, or the literal.
1547
1597
  if (ts.isConditionalExpression(unwrapped))
1548
- return writesDynamicValue(unwrapped.whenTrue, depth + 1) || writesDynamicValue(unwrapped.whenFalse, depth + 1);
1598
+ return writesDynamicValue(unwrapped.whenTrue) || writesDynamicValue(unwrapped.whenFalse);
1549
1599
  if (ts.isBinaryExpression(unwrapped)) {
1550
1600
  const operator = unwrapped.operatorToken.kind;
1551
1601
  if (operator === ts.SyntaxKind.QuestionQuestionToken ||
1552
1602
  operator === ts.SyntaxKind.BarBarToken ||
1553
1603
  operator === ts.SyntaxKind.AmpersandAmpersandToken)
1554
- return writesDynamicValue(unwrapped.left, depth + 1) || writesDynamicValue(unwrapped.right, depth + 1);
1604
+ return writesDynamicValue(unwrapped.left) || writesDynamicValue(unwrapped.right);
1555
1605
  }
1556
1606
  // A member read out of an untyped object hands the field whatever the
1557
1607
  // object holds: `source.label`, `values[ key ]`, a binding destructured
@@ -1561,26 +1611,26 @@ flow) => {
1561
1611
  if (resolveExpr(value) !== null)
1562
1612
  return false;
1563
1613
  const key = ts.isPropertyAccessExpression(unwrapped) ? unwrapped.name.text : literalMemberNameOf(unwrapped);
1564
- return untypedSource(unwrapped.expression, key, depth) || readsDeclaredDynamicMember(unwrapped, depth);
1614
+ return untypedSource(unwrapped.expression, key) || readsDeclaredDynamicMember(unwrapped);
1565
1615
  }
1566
1616
  if (ts.isCallExpression(unwrapped) || ts.isNewExpression(unwrapped))
1567
- return callReturnsDynamicValue(unwrapped, depth);
1617
+ return callReturnsDynamicValue(unwrapped);
1568
1618
  if (!ts.isIdentifier(unwrapped))
1569
1619
  return false;
1570
1620
  const declaration = checker.getSymbolAtLocation(unwrapped)?.valueDeclaration;
1571
1621
  if (declaration && ts.isParameter(declaration))
1572
- return parameterReceivesDynamicValue(declaration, depth);
1622
+ return parameterReceivesDynamicValue(declaration);
1573
1623
  if (declaration && ts.isBindingElement(declaration)) {
1574
1624
  const source = destructuredSourceOf(declaration);
1575
1625
  const name = declaration.propertyName ?? declaration.name;
1576
1626
  const key = ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name) ? name.text : null;
1577
- return source !== null && untypedSource(source, key, depth);
1627
+ return source !== null && untypedSource(source, key);
1578
1628
  }
1579
1629
  if (!declaration || !ts.isVariableDeclaration(declaration) || !declaration.initializer || !ts.isIdentifier(declaration.name))
1580
1630
  return false;
1581
1631
  if ((ts.getCombinedNodeFlags(declaration) & ts.NodeFlags.Const) === 0)
1582
1632
  return false;
1583
- return writesDynamicValue(declaration.initializer, depth + 1);
1633
+ return writesDynamicValue(declaration.initializer);
1584
1634
  };
1585
1635
  /**
1586
1636
  * A parameter no census typed holds what its callers pass, and what its own
@@ -1590,26 +1640,22 @@ flow) => {
1590
1640
  * the parameter itself is boxed. A parameter that reaches itself (a
1591
1641
  * recursive call forwarding it) adds nothing.
1592
1642
  */
1593
- const visitingParameters = new Set();
1594
- const parameterReceivesDynamicValue = (parameter, depth) => {
1595
- if (parameters.typeAt(parameter) || visitingParameters.has(parameter) || !ts.isIdentifier(parameter.name))
1643
+ const parameterReceivesDynamicValue = (parameter) => {
1644
+ if (parameters.typeAt(parameter) || !ts.isIdentifier(parameter.name))
1596
1645
  return false;
1597
- const symbol = checker.getSymbolAtLocation(parameter.name);
1646
+ const name = parameter.name;
1647
+ const symbol = checker.getSymbolAtLocation(name);
1598
1648
  if (!symbol)
1599
1649
  return false;
1600
- visitingParameters.add(parameter);
1601
- try {
1602
- const dynamic = valuesReceivedBy(parameter).find((value) => writesDynamicValue(value, depth + 1));
1650
+ return reach('receives', parameter, () => {
1651
+ const dynamic = valuesReceivedBy(parameter).find((value) => writesDynamicValue(value));
1603
1652
  if (dynamic && WIDEN_DEBUG) {
1604
1653
  const file = dynamic.getSourceFile();
1605
1654
  const line = file.getLineAndCharacterOfPosition(dynamic.getStart()).line + 1;
1606
- process.stderr.write(`[WIDEN-ARG] ${parameter.name.getText()} <- ${file.fileName}:${line} ${dynamic.getText().replace(/\s+/g, ' ').slice(0, 100)}\n`);
1655
+ process.stderr.write(`[WIDEN-ARG] ${name.getText()} <- ${file.fileName}:${line} ${dynamic.getText().replace(/\s+/g, ' ').slice(0, 100)}\n`);
1607
1656
  }
1608
1657
  return dynamic !== undefined;
1609
- }
1610
- finally {
1611
- visitingParameters.delete(parameter);
1612
- }
1658
+ });
1613
1659
  };
1614
1660
  /**
1615
1661
  * A call the checker types `any` and no census resolved: a host function
@@ -1617,7 +1663,6 @@ flow) => {
1617
1663
  * returns whatever it produces; a function of the program returns what its
1618
1664
  * `return` statements do.
1619
1665
  */
1620
- const visitingCallees = new Set();
1621
1666
  const isGlobalObjectCreate = (call) => {
1622
1667
  const target = call.expression;
1623
1668
  return (ts.isCallExpression(call) &&
@@ -1634,40 +1679,31 @@ flow) => {
1634
1679
  * census's own type for it, and one the census cannot type is no evidence.
1635
1680
  * A call that is not a method call returns whatever it produces.
1636
1681
  */
1637
- const methodOfUntypedReceiverReturnsDynamicValue = (call, depth) => {
1682
+ const methodOfUntypedReceiverReturnsDynamicValue = (call) => {
1638
1683
  const target = unwrapParens(call.expression);
1639
1684
  if (!ts.isCallExpression(call) || !ts.isPropertyAccessExpression(target))
1640
1685
  return true;
1641
1686
  const receiver = unwrapParens(target.expression);
1642
1687
  const declaration = ts.isIdentifier(receiver) ? checker.getSymbolAtLocation(receiver)?.valueDeclaration : undefined;
1643
1688
  const isUntypedParameter = declaration !== undefined && ts.isParameter(declaration) && !parameters.typeAt(declaration);
1644
- if (depth > 8)
1645
- return false;
1646
1689
  if (!isUntypedParameter) {
1647
1690
  // Any other receiver: the census's own type for it, when it has one.
1648
- if (untypedSource(receiver, null, depth + 1))
1691
+ if (untypedSource(receiver, null))
1649
1692
  return true;
1650
1693
  const type = knownOrResolve(receiver);
1651
- return type !== null && methodOfTypeReturnsDynamicValue(type, target.name.text, call, depth);
1694
+ return type !== null && methodOfTypeReturnsDynamicValue(type, target.name.text, call);
1652
1695
  }
1653
1696
  const parameter = declaration;
1654
- if (visitingSourceParameters.has(parameter))
1655
- return false;
1656
- visitingSourceParameters.add(parameter);
1657
- try {
1658
- return valuesReceivedBy(parameter).some((value) => {
1659
- if (untypedSource(value, null, depth + 1))
1660
- return true;
1661
- const type = knownOrResolve(value);
1662
- return type !== null && methodOfTypeReturnsDynamicValue(type, target.name.text, call, depth);
1663
- });
1664
- }
1665
- finally {
1666
- visitingSourceParameters.delete(parameter);
1667
- }
1697
+ const name = target.name.text;
1698
+ return reach(`method:${name}`, parameter, () => valuesReceivedBy(parameter).some((value) => {
1699
+ if (untypedSource(value, null))
1700
+ return true;
1701
+ const type = knownOrResolve(value);
1702
+ return type !== null && methodOfTypeReturnsDynamicValue(type, name, call);
1703
+ }));
1668
1704
  };
1669
1705
  /** Whether calling `name` on an object of `type` can return a value nothing types. */
1670
- const methodOfTypeReturnsDynamicValue = (type, name, call, depth) => {
1706
+ const methodOfTypeReturnsDynamicValue = (type, name, call) => {
1671
1707
  const holder = checker.getNonNullableType(type);
1672
1708
  return (holder.isUnion() ? holder.types : [holder]).some((arm) => {
1673
1709
  const method = checker.getPropertyOfType(arm, name);
@@ -1678,35 +1714,29 @@ flow) => {
1678
1714
  const signatures = checker.getTypeOfSymbolAtLocation(method, call).getCallSignatures();
1679
1715
  return signatures.some((signature) => (checker.getReturnTypeOfSignature(signature).flags & ts.TypeFlags.Any) !== 0);
1680
1716
  }
1681
- return ts.isFunctionLike(body) && functionReturnsDynamicValue(body, depth);
1717
+ return ts.isFunctionLike(body) && functionReturnsDynamicValue(body);
1682
1718
  });
1683
1719
  };
1684
1720
  /** Whether one of a program function's own `return` statements hands back a value nothing types. */
1685
- const functionReturnsDynamicValue = (callee, depth) => {
1721
+ const functionReturnsDynamicValue = (callee) => {
1686
1722
  if (!('body' in callee) || !callee.body)
1687
1723
  return true;
1688
- if (visitingCallees.has(callee))
1689
- return false;
1690
- visitingCallees.add(callee);
1691
- try {
1692
- const body = callee.body;
1724
+ const body = callee.body;
1725
+ return reach('returns', callee, () => {
1693
1726
  if (!ts.isBlock(body))
1694
- return writesDynamicValue(body, depth + 1);
1727
+ return writesDynamicValue(body);
1695
1728
  let dynamic = false;
1696
1729
  const visit = (node) => {
1697
1730
  if (dynamic || (node !== body && ts.isFunctionLike(node)))
1698
1731
  return;
1699
- if (ts.isReturnStatement(node) && node.expression && writesDynamicValue(node.expression, depth + 1))
1732
+ if (ts.isReturnStatement(node) && node.expression && writesDynamicValue(node.expression))
1700
1733
  dynamic = true;
1701
1734
  else
1702
1735
  ts.forEachChild(node, visit);
1703
1736
  };
1704
1737
  visit(body);
1705
1738
  return dynamic;
1706
- }
1707
- finally {
1708
- visitingCallees.delete(callee);
1709
- }
1739
+ });
1710
1740
  };
1711
1741
  /**
1712
1742
  * `entries.get( key )` on a Map or Set the program built without type
@@ -1714,7 +1744,7 @@ flow) => {
1714
1744
  * program's own `set`/`add` calls put in it -- dynamic only where one of
1715
1745
  * those values is.
1716
1746
  */
1717
- const collectionReadIsTyped = (call, depth) => {
1747
+ const collectionReadIsTyped = (call) => {
1718
1748
  const target = unwrapParens(call.expression);
1719
1749
  if (!ts.isCallExpression(call) || !ts.isPropertyAccessExpression(target) || target.name.text !== 'get')
1720
1750
  return false;
@@ -1727,20 +1757,20 @@ flow) => {
1727
1757
  if (!symbol)
1728
1758
  return false;
1729
1759
  const values = flow.writesToSymbol(symbol).filter((write) => write.edge === 'collection-value' && write.value !== null);
1730
- return values.length > 0 && !values.some((write) => writesDynamicValue(write.value, depth + 1));
1760
+ return values.length > 0 && !values.some((write) => writesDynamicValue(write.value));
1731
1761
  };
1732
- const callReturnsDynamicValue = (call, depth) => {
1762
+ const callReturnsDynamicValue = (call) => {
1733
1763
  if (resolveExpr(call) !== null)
1734
1764
  return false;
1735
1765
  const callee = checker.getResolvedSignature(call)?.getDeclaration();
1736
1766
  if (!callee)
1737
- return methodOfUntypedReceiverReturnsDynamicValue(call, depth);
1767
+ return methodOfUntypedReceiverReturnsDynamicValue(call);
1738
1768
  // `Object.create( proto )` is declared to return `any`, but it builds a
1739
1769
  // fresh object holding none of the program's values; storing it is the
1740
1770
  // ordinary conversion of an empty object into the field's carrier.
1741
1771
  if (callee.getSourceFile().isDeclarationFile)
1742
- return !isGlobalObjectCreate(call) && !collectionReadIsTyped(call, depth);
1743
- return !ts.isFunctionLike(callee) || functionReturnsDynamicValue(callee, depth);
1772
+ return !isGlobalObjectCreate(call) && !collectionReadIsTyped(call);
1773
+ return !ts.isFunctionLike(callee) || functionReturnsDynamicValue(callee);
1744
1774
  };
1745
1775
  const dynamicWriteEvidence = (write) => write.slot === 'whole' &&
1746
1776
  write.value !== null &&
@@ -1833,26 +1863,12 @@ flow) => {
1833
1863
  // may have been silent only because the field it reads was still being
1834
1864
  // resolved -- `this.text = source.text` copying another instance's own.
1835
1865
  nodeMemo.clear();
1836
- for (let changed = true; changed;) {
1837
- changed = false;
1838
- for (const symbol of unstated) {
1839
- if (widenedFields.has(symbol))
1840
- continue;
1841
- const evidence = dynamicWriteInto(symbol);
1842
- if (!evidence)
1843
- continue;
1844
- widenedFields.add(symbol);
1845
- changed = true;
1846
- // `GEA_WIDEN_DEBUG=1` names each widened field and the write that
1847
- // widened it -- the one fact a moved carrier needs to be judged by.
1848
- if (WIDEN_DEBUG) {
1849
- const file = evidence.getSourceFile();
1850
- const line = file.getLineAndCharacterOfPosition(evidence.getStart()).line + 1;
1851
- const owner = ownersOf(symbol).values().next().value?.name?.text ?? '?';
1852
- const kind = statedFieldSymbols.has(symbol) ? 'stated' : 'inferred';
1853
- process.stderr.write(`[WIDEN] ${owner}.${symbol.name} ${kind} <- ${file.fileName}:${line} ${evidence.getText().replace(/\s+/g, ' ').slice(0, 120)}\n`);
1854
- }
1855
- }
1866
+ reachSettled = new Map();
1867
+ try {
1868
+ settleWidenedFields(unstated);
1869
+ }
1870
+ finally {
1871
+ reachSettled = null;
1856
1872
  }
1857
1873
  if (widenedFields.size === 0)
1858
1874
  return;
@@ -1878,6 +1894,30 @@ flow) => {
1878
1894
  }
1879
1895
  nodeMemo.clear();
1880
1896
  };
1897
+ const settleWidenedFields = (unstated) => {
1898
+ for (let changed = true; changed;) {
1899
+ changed = false;
1900
+ for (const symbol of unstated) {
1901
+ if (widenedFields.has(symbol))
1902
+ continue;
1903
+ const evidence = dynamicWriteInto(symbol);
1904
+ if (!evidence)
1905
+ continue;
1906
+ widenedFields.add(symbol);
1907
+ forgetCleanVerdicts();
1908
+ changed = true;
1909
+ // `GEA_WIDEN_DEBUG=1` names each widened field and the write that
1910
+ // widened it -- the one fact a moved carrier needs to be judged by.
1911
+ if (WIDEN_DEBUG) {
1912
+ const file = evidence.getSourceFile();
1913
+ const line = file.getLineAndCharacterOfPosition(evidence.getStart()).line + 1;
1914
+ const owner = ownersOf(symbol).values().next().value?.name?.text ?? '?';
1915
+ const kind = statedFieldSymbols.has(symbol) ? 'stated' : 'inferred';
1916
+ process.stderr.write(`[WIDEN] ${owner}.${symbol.name} ${kind} <- ${file.fileName}:${line} ${evidence.getText().replace(/\s+/g, ' ').slice(0, 120)}\n`);
1917
+ }
1918
+ }
1919
+ }
1920
+ };
1881
1921
  // Enumerate every candidate SYMBOL up front, from every `x.field = expr`
1882
1922
  // write's left-hand side, so `boundCount`/`refusals` reflect the whole
1883
1923
  // program rather than only the nodes some other pass happened to query.
@@ -628,6 +628,7 @@ const sharedAnswers = new WeakMap();
628
628
  */
629
629
  const refusalMemoEnabled = process.env['GEA_REFUSAL_MEMO'] !== '0';
630
630
  const sharedStats = { asks: 0, hits: 0, stores: 0, refusals: 0, ungrounded: 0 };
631
+ const wipEscapes = new Map(); // WIP-SOLVER-TIMING
631
632
  const intactCheckIds = new WeakMap();
632
633
  let intactChecksSeen = 0;
633
634
  const intactCheckIdOf = (check) => {
@@ -1369,6 +1370,8 @@ const closedMemberCallableUses = (checker, flow, member, countedCalls, givenRece
1369
1370
  hypothesisGuardIsOpen(key);
1370
1371
  const sharedAnswerOf = (identity, compute, shareable) => {
1371
1372
  sharedStats.asks++;
1373
+ if (process.env['GEA_WIP_PROOF_STATS'] && sharedStats.asks % 500000 === 0)
1374
+ console.error(memberProofStats()); // WIP-SOLVER-TIMING
1372
1375
  let byReceiverTypeAt = sharedAnswers.get(flow);
1373
1376
  if (!byReceiverTypeAt)
1374
1377
  sharedAnswers.set(flow, (byReceiverTypeAt = new WeakMap()));
@@ -1466,6 +1469,30 @@ const closedMemberCallableUses = (checker, flow, member, countedCalls, givenRece
1466
1469
  // 16k answers because 98% of the asks refused.
1467
1470
  if (computed.value === null && !grounded)
1468
1471
  sharedStats.ungrounded++;
1472
+ if (computed.value === null && !grounded && process.env['GEA_WIP_PROOF_STATS']) {
1473
+ // WIP-SOLVER-TIMING: which escaped hypotheses keep refusals out of the memo
1474
+ const describe = (key) => {
1475
+ const node = key;
1476
+ if (typeof node.kind === 'number' && typeof node.getSourceFile === 'function') {
1477
+ const file = node.getSourceFile();
1478
+ const line = file.getLineAndCharacterOfPosition(key.getStart(file)).line + 1;
1479
+ return `${ts.SyntaxKind[node.kind]} ${file.fileName.split('/').pop()}:${line} ${key.getText(file).replace(/\s+/g, ' ').slice(0, 50)}`;
1480
+ }
1481
+ const named = key;
1482
+ return `${key.constructor?.name ?? 'object'} ${String(named.escapedName ?? named.name ?? named.kind ?? '')}`;
1483
+ };
1484
+ for (const key of escaped) {
1485
+ const label = `${identity.split(':')[0]} <- ${describe(key)}`;
1486
+ wipEscapes.set(label, (wipEscapes.get(label) ?? 0) + 1);
1487
+ }
1488
+ if (sharedStats.ungrounded % 200000 === 0)
1489
+ console.error('[WIP-ESCAPES]\n' +
1490
+ [...wipEscapes]
1491
+ .sort((a, b) => b[1] - a[1])
1492
+ .slice(0, 12)
1493
+ .map(([label, count]) => ` ${count} ${label}`)
1494
+ .join('\n'));
1495
+ }
1469
1496
  if ((shareable?.(computed.value) ?? true) && (computed.value !== null || (grounded && refusalMemoEnabled))) {
1470
1497
  const recorded = [];
1471
1498
  for (const [reference, kinds] of opens)
@@ -484,6 +484,27 @@ const componentEngine = (graph, mode) => {
484
484
  const SMALL_EDGES = 8;
485
485
  /** How far ahead of its last edge read `observedState` looks before asking the dependency. */
486
486
  const CURSOR_WINDOW = 4;
487
+ /**
488
+ * Whether two equally sized fact collections hold the same facts in the same
489
+ * order. Stepping two iterators by hand allocated a result object per fact on
490
+ * each side, several percent of a large solve's allocation; an array side is
491
+ * indexed instead, and only a set against a set steps one iterator by hand.
492
+ */
493
+ const sameOrder = (mine, theirs) => {
494
+ const indexed = Array.isArray(theirs) ? theirs : Array.isArray(mine) ? mine : null;
495
+ if (indexed !== null) {
496
+ let index = 0;
497
+ for (const fact of indexed === theirs ? mine : theirs)
498
+ if (fact !== indexed[index++])
499
+ return false;
500
+ return true;
501
+ }
502
+ const right = theirs.values();
503
+ for (const fact of mine)
504
+ if (fact !== right.next().value)
505
+ return false;
506
+ return true;
507
+ };
487
508
  const edgeCount = (edges) => edges === null ? 0 : edges instanceof Map || edges instanceof Set ? edges.size : Array.isArray(edges) ? edges.length : 1;
488
509
  const NO_EDGE_STATES = [];
489
510
  const edgeStates = (edges) => edges === null ? NO_EDGE_STATES : edges instanceof Set || Array.isArray(edges) ? edges : [edges];
@@ -727,11 +748,8 @@ export class FactState {
727
748
  return false;
728
749
  if (this.size !== other.size)
729
750
  return false;
730
- const left = mine.values();
731
- const right = theirs.values();
732
- for (let a = left.next(), b = right.next(); !a.done; a = left.next(), b = right.next())
733
- if (a.value !== b.value)
734
- return false;
751
+ if (!sameOrder(mine, theirs))
752
+ return false;
735
753
  this.facts = theirs;
736
754
  this.flags |= SHARED_FACTS;
737
755
  other.flags |= SHARED_FACTS;
@@ -620,8 +620,12 @@ export const sourceRecordSlotValuesOf = (flow, access, authority) => {
620
620
  }
621
621
  finally {
622
622
  // The re-entry above hands out exactly one thing -- a refusal -- so a
623
- // refusal here confirms it outright.
624
- exitHypothesisGuard(access, true);
623
+ // refusal here confirms it outright. It also settles it as the truth, as
624
+ // `fieldValuesOf`'s guard does: without that, every refusal that leaned on
625
+ // a re-entry stayed ungrounded after this read closed, was never stored,
626
+ // and was derived again on every later ask -- millions of times for a
627
+ // recursive key function over a union, the self-compile never finishing.
628
+ exitHypothesisGuard(access, true, answered === null);
625
629
  activeSlotReads.delete(access);
626
630
  }
627
631
  };
@@ -103,11 +103,24 @@ declare class QueryState extends FactState<Query, Value, Cause> {
103
103
  get subject(): FrameSubject | Value | undefined;
104
104
  get key(): string | undefined;
105
105
  get root(): FrameSubject | Value | undefined;
106
+ /**
107
+ * The computed writes whose receiver this query is. Held on the state
108
+ * rather than in a session map: `hasUnnamedWrite` and `computedWriteNames`
109
+ * ask it of every holder of a root, often thousands, and almost every
110
+ * answer is none -- a field read where a map lookup was most of their time.
111
+ */
112
+ computedWriteEdges: WriteEdge[] | undefined;
106
113
  }
107
114
  interface Cause {
108
115
  readonly reason: string;
109
116
  readonly node: ts.Node;
110
117
  }
118
+ interface WriteEdge {
119
+ readonly access: Access;
120
+ readonly receiver: Query;
121
+ readonly key: string | null;
122
+ readonly write: ValueFlowIndex['allWrites'][number];
123
+ }
111
124
  /** Operand identities of an authenticated native Proxy allocation. This is
112
125
  * not a closure, trap-effect, member-lookup or construction-result proof. */
113
126
  export interface SourceProxyResultIdentity {