@geastack/compiler 1.0.21 → 1.0.22

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 (35) hide show
  1. package/dist/compiler.js +2 -1
  2. package/dist/conversion/build.d.ts +12 -0
  3. package/dist/conversion/build.js +15 -0
  4. package/dist/ir/callable-class-flow.d.ts +3 -1
  5. package/dist/ir/callable-class-flow.js +27 -1
  6. package/dist/ir/certificate.js +87 -16
  7. package/dist/ir/certify/carrier-keys.js +3 -1
  8. package/dist/ir/lower-invocation.js +7 -1
  9. package/dist/ir/proven-branches.js +3 -1
  10. package/dist/ir/reflection-demand.js +10 -0
  11. package/dist/project-preparation.js +20 -0
  12. package/dist/semantics/class-alias.d.ts +16 -1
  13. package/dist/semantics/class-alias.js +21 -2
  14. package/dist/semantics/class-heritage.js +2 -2
  15. package/dist/semantics/frontend.js +35 -7
  16. package/dist/semantics/normalize/bivariant-slot-parameter.js +21 -6
  17. package/dist/semantics/normalize/commonjs-require.d.ts +9 -5
  18. package/dist/semantics/normalize/commonjs-require.js +127 -44
  19. package/dist/semantics/normalize/host-mutation-key-reader.js +35 -10
  20. package/dist/semantics/normalize/identities.js +15 -0
  21. package/dist/semantics/normalize/object-bag-bindings.js +16 -2
  22. package/dist/semantics/normalize/omitted-stated-parameter.d.ts +1 -1
  23. package/dist/semantics/normalize/omitted-stated-parameter.js +34 -4
  24. package/dist/semantics/normalize/parameter-bindings.js +33 -7
  25. package/dist/semantics/normalize/structural.js +17 -0
  26. package/dist/semantics/program.js +42 -20
  27. package/dist/semantics/shared-declaration-files.d.ts +44 -0
  28. package/dist/semantics/shared-declaration-files.js +42 -0
  29. package/dist/semantics/subclass-member-overlay-transform.js +95 -53
  30. package/dist/targets/cpp/emit-allocation.js +34 -1
  31. package/dist/targets/cpp/emit-union-properties.js +16 -3
  32. package/dist/targets/cpp/manifest/capabilities.js +10 -1
  33. package/dist/targets/cpp/records.js +8 -1
  34. package/package.json +10 -10
  35. package/src/targets/cpp/runtime/gea_runtime.h +66 -14
@@ -1474,13 +1474,66 @@ const collectFunctions = (files) => {
1474
1474
  visit(file);
1475
1475
  return functions;
1476
1476
  };
1477
+ /**
1478
+ * What a read of `require` is, given the files that can write the wrapper cell
1479
+ * and the definition states the flow computed for them. Shared by the full
1480
+ * census and by `createCommonJsRequireTargetCensus`, which has no writer and
1481
+ * so no state to read: one definition of "static" for both.
1482
+ */
1483
+ const requireStatusOf = (checker, identity, requireWriters, reads) => {
1484
+ const statusOf = (expression, seen = new Set()) => {
1485
+ const node = unwrapExpression(expression);
1486
+ if (!ts.isIdentifier(node))
1487
+ return 'ordinary';
1488
+ const identityAtNode = identity.classify(node);
1489
+ if (identityAtNode.kind === 'provenance-failure')
1490
+ return 'provenance-failure';
1491
+ if (identityAtNode.kind === 'wrapper') {
1492
+ if (identityAtNode.global !== 'require')
1493
+ return 'ordinary';
1494
+ // A module whose source never writes its wrapper `require` (see
1495
+ // `requireWriters`) keeps Node's loader in that cell for its whole
1496
+ // lifetime, so every read of it is static -- including reads the
1497
+ // per-file flow never reaches (an exported function or a class method
1498
+ // only other modules call, which get no entry state here) and reads it
1499
+ // reaches as `unknown` only because an unresolved call *might* have been
1500
+ // one of this file's writers. Sound because the cell is a parameter of
1501
+ // this module's own wrapper function: no other module can name it, so
1502
+ // the only possible writers are syntactic writes in this file, and
1503
+ // `wrapperWrite` sees every one of them -- the first pass analyzes every
1504
+ // function body and every top level from a reachable state, and records
1505
+ // the writer before any reachability filter (a write the flow proves
1506
+ // dead never runs). A `var require`/`function require` rebinding either
1507
+ // is such a write or resolves the read to a user declaration, which is
1508
+ // not the wrapper and never gets here; the non-syntactic aliases (direct
1509
+ // `eval`, the wrapper's `arguments`) are `canAliasWrapperCells`.
1510
+ if (!requireWriters.has(node.getSourceFile()))
1511
+ return 'static';
1512
+ const definitions = reads.get(node) ?? unreachable;
1513
+ if (definitions === originalDefinition)
1514
+ return 'static';
1515
+ return definitions === unreachable ? 'ordinary' : 'possibly-reassigned';
1516
+ }
1517
+ const symbol = resolvedSymbolAt(checker, node);
1518
+ if (!symbol || seen.has(symbol))
1519
+ return 'ordinary';
1520
+ seen.add(symbol);
1521
+ const declaration = symbol.valueDeclaration;
1522
+ if (!declaration || !ts.isVariableDeclaration(declaration) || !declaration.initializer)
1523
+ return 'ordinary';
1524
+ if (!ts.isVariableDeclarationList(declaration.parent) || (declaration.parent.flags & ts.NodeFlags.Const) === 0)
1525
+ return 'ordinary';
1526
+ return statusOf(declaration.initializer, seen);
1527
+ };
1528
+ return statusOf;
1529
+ };
1477
1530
  /**
1478
1531
  * CommonJS static dispatch is a reaching-definition proof over one wrapper
1479
1532
  * cell per source module. The cell starts at Node's original loader and every
1480
1533
  * possible write replaces that proof with unknown. Const aliases snapshot the
1481
1534
  * definition at their own initializer; later cell writes cannot alter them.
1482
1535
  */
1483
- export const createCommonJsRequireCensus = (checker, files, globals) => {
1536
+ const analyseCommonJsRequireCensus = (checker, files, globals) => {
1484
1537
  // Without any installed wrapper declarations, no identifier can authenticate
1485
1538
  // as Node's loader. Ordinary user functions need no wrapper-effect analysis.
1486
1539
  if (globals.size === 0)
@@ -1685,51 +1738,81 @@ export const createCommonJsRequireCensus = (checker, files, globals) => {
1685
1738
  }
1686
1739
  if (process.env['GEA_STAGE_TIMING'])
1687
1740
  process.stderr.write(`[census] ${JSON.stringify({ ...stats, requireWriters: requireWriters.size })}\n`);
1688
- const statusOf = (expression, seen = new Set()) => {
1689
- const node = unwrapExpression(expression);
1690
- if (!ts.isIdentifier(node))
1691
- return 'ordinary';
1692
- const identityAtNode = identity.classify(node);
1693
- if (identityAtNode.kind === 'provenance-failure')
1694
- return 'provenance-failure';
1695
- if (identityAtNode.kind === 'wrapper') {
1696
- if (identityAtNode.global !== 'require')
1697
- return 'ordinary';
1698
- // A module whose source never writes its wrapper `require` (see
1699
- // `requireWriters`) keeps Node's loader in that cell for its whole
1700
- // lifetime, so every read of it is static -- including reads the
1701
- // per-file flow never reaches (an exported function or a class method
1702
- // only other modules call, which get no entry state here) and reads it
1703
- // reaches as `unknown` only because an unresolved call *might* have been
1704
- // one of this file's writers. Sound because the cell is a parameter of
1705
- // this module's own wrapper function: no other module can name it, so
1706
- // the only possible writers are syntactic writes in this file, and
1707
- // `wrapperWrite` sees every one of them -- the first pass analyzes every
1708
- // function body and every top level from a reachable state, and records
1709
- // the writer before any reachability filter (a write the flow proves
1710
- // dead never runs). A `var require`/`function require` rebinding either
1711
- // is such a write or resolves the read to a user declaration, which is
1712
- // not the wrapper and never gets here; the non-syntactic aliases (direct
1713
- // `eval`, the wrapper's `arguments`) are `canAliasWrapperCells`.
1714
- if (!requireWriters.has(node.getSourceFile()))
1715
- return 'static';
1716
- const definitions = reads.get(node) ?? unreachable;
1717
- if (definitions === originalDefinition)
1718
- return 'static';
1719
- return definitions === unreachable ? 'ordinary' : 'possibly-reassigned';
1741
+ return { statusOf: requireStatusOf(checker, identity, requireWriters, reads) };
1742
+ };
1743
+ const sameGlobals = (left, right) => left === right || (left.size === right.size && [...left].every(([name, declaration]) => right.get(name) === declaration));
1744
+ /**
1745
+ * The census is a pure function of the checker, the program's file list and
1746
+ * the wrapper declarations, and the frontend asks it twice with exactly those
1747
+ * inputs (the module-record census and the invocation producer), 0.4 s a
1748
+ * time. The last answer per checker is kept so the second ask is the first's
1749
+ * instance -- same proof, so nothing downstream can see two.
1750
+ */
1751
+ const lastCensus = new WeakMap();
1752
+ export const createCommonJsRequireCensus = (checker, files, globals) => {
1753
+ const held = lastCensus.get(checker);
1754
+ if (held && held.files === files && sameGlobals(held.globals, globals))
1755
+ return held.census;
1756
+ const census = analyseCommonJsRequireCensus(checker, files, globals);
1757
+ lastCensus.set(checker, { files, globals, census });
1758
+ return census;
1759
+ };
1760
+ /**
1761
+ * Whether a file can name the wrapper's `require` cell as something to WRITE:
1762
+ * any identifier `require` that is not the callee of a call, the receiver or
1763
+ * member name of a property access, or a property name. Every write form (an
1764
+ * assignment or update, a destructuring target, a `var`/parameter/function
1765
+ * redeclaration, an import binding, a shorthand property) puts such an
1766
+ * identifier in a position outside those, so a file without one cannot write
1767
+ * the cell syntactically; `eval` and the wrapper's `arguments` are the
1768
+ * non-syntactic routes (`canAliasWrapperCells`).
1769
+ */
1770
+ const mayWriteRequireCell = (file) => {
1771
+ let found = false;
1772
+ const visit = (node) => {
1773
+ if (found)
1774
+ return;
1775
+ if (ts.isIdentifier(node)) {
1776
+ if (node.text !== 'require')
1777
+ return;
1778
+ const parent = node.parent;
1779
+ if (ts.isCallExpression(parent) && parent.expression === node)
1780
+ return;
1781
+ if ((ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)) && parent.expression === node)
1782
+ return;
1783
+ if (ts.isPropertyAccessExpression(parent) && parent.name === node)
1784
+ return;
1785
+ if ((ts.isPropertyAssignment(parent) ||
1786
+ ts.isPropertyDeclaration(parent) ||
1787
+ ts.isMethodDeclaration(parent) ||
1788
+ ts.isPropertySignature(parent) ||
1789
+ ts.isMethodSignature(parent)) &&
1790
+ parent.name === node)
1791
+ return;
1792
+ found = true;
1793
+ return;
1720
1794
  }
1721
- const symbol = resolvedSymbolAt(checker, node);
1722
- if (!symbol || seen.has(symbol))
1723
- return 'ordinary';
1724
- seen.add(symbol);
1725
- const declaration = symbol.valueDeclaration;
1726
- if (!declaration || !ts.isVariableDeclaration(declaration) || !declaration.initializer)
1727
- return 'ordinary';
1728
- if (!ts.isVariableDeclarationList(declaration.parent) || (declaration.parent.flags & ts.NodeFlags.Const) === 0)
1729
- return 'ordinary';
1730
- return statusOf(declaration.initializer, seen);
1795
+ ts.forEachChild(node, visit);
1731
1796
  };
1732
- return { statusOf };
1797
+ visit(file);
1798
+ return found;
1799
+ };
1800
+ /**
1801
+ * The census restricted to what a program that is about to be REBUILT needs:
1802
+ * which `require` calls are static. Valid only when no file can write the
1803
+ * wrapper cell, where the full census's answer is `static` for every read of
1804
+ * the wrapper (`requireStatusOf`) and its fact and summary passes compute
1805
+ * nothing anyone consults. Null otherwise -- the caller then asks the full
1806
+ * census. Never used for the program the compile keeps: the full census also
1807
+ * puts the checker in the state later queries (and so emitted names) depend on.
1808
+ */
1809
+ export const createCommonJsRequireTargetCensus = (checker, files, globals) => {
1810
+ if (globals.size === 0)
1811
+ return { statusOf: () => 'ordinary' };
1812
+ const implementationFiles = files.filter((file) => !file.isDeclarationFile);
1813
+ if (implementationFiles.some((file) => canAliasWrapperCells(file) || mayWriteRequireCell(file)))
1814
+ return null;
1815
+ return { statusOf: requireStatusOf(checker, createCommonJsWrapperIdentity(checker, files, globals), new Set(), new Map()) };
1733
1816
  };
1734
1817
  /**
1735
1818
  * The one admission the invocation producer applies before it lowers a call
@@ -175,18 +175,43 @@ export const createMutationKeyReader = (checker, computedKeysOf, publishedTypeAt
175
175
  */
176
176
  export const hostAccessorNamesOf = (declarationFiles, files) => {
177
177
  const names = new Set(['__proto__']);
178
- const visit = (node, ambientOnly) => {
179
- if (ts.isSetAccessorDeclaration(node) && (!ambientOnly || isAmbientDeclaration(node)) && !declarationStatesHostInert(node)) {
180
- const name = node.name;
181
- if (ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name))
182
- names.add(name.text);
183
- }
184
- ts.forEachChild(node, (child) => visit(child, ambientOnly));
185
- };
186
178
  for (const file of declarationFiles)
187
- visit(file, false);
179
+ for (const name of setterNamesOf(file, false))
180
+ names.add(name);
188
181
  for (const file of files)
189
182
  if (!file.isDeclarationFile)
190
- visit(file, true);
183
+ for (const name of setterNamesOf(file, true))
184
+ names.add(name);
191
185
  return names;
192
186
  };
187
+ /**
188
+ * The names of the uncovered setters one file declares, in encounter order.
189
+ *
190
+ * A pure function of the tree -- `declarationStatesHostInert` reads only the
191
+ * declaration and its own JSDoc -- and a declaration file's tree is shared
192
+ * across compiles (`shared-declaration-files.ts`), so the whole-file walk is
193
+ * kept per file instead of repeated for the same standard library every compile.
194
+ */
195
+ const setterNames = new WeakMap();
196
+ const setterNamesOf = (file, ambientOnly) => {
197
+ const known = setterNames.get(file);
198
+ if (known !== undefined)
199
+ return ambientOnly ? known.ambient : known.any;
200
+ const any = [];
201
+ const ambient = [];
202
+ const visit = (node) => {
203
+ if (ts.isSetAccessorDeclaration(node) && !declarationStatesHostInert(node)) {
204
+ const name = node.name;
205
+ if (ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name)) {
206
+ any.push(name.text);
207
+ if (isAmbientDeclaration(node))
208
+ ambient.push(name.text);
209
+ }
210
+ }
211
+ ts.forEachChild(node, visit);
212
+ };
213
+ visit(file);
214
+ const held = { any, ambient };
215
+ setterNames.set(file, held);
216
+ return ambientOnly ? held.ambient : held.any;
217
+ };
@@ -35,6 +35,21 @@ export const specializationKey = (path) => path.map((step) => step.ordinal).join
35
35
  * order and visits each node's tags in source order.
36
36
  */
37
37
  const walkOrdinals = (file) => {
38
+ const known = ordinalWalks.get(file);
39
+ if (known !== undefined)
40
+ return known;
41
+ const walked = computeOrdinals(file);
42
+ ordinalWalks.set(file, walked);
43
+ return walked;
44
+ };
45
+ /**
46
+ * The walk is a pure function of the tree, and a declaration file's tree is
47
+ * shared across compiles (`shared-declaration-files.ts`), so its walk is kept
48
+ * with it -- weakly, so a source file's walk dies with the file. The returned
49
+ * map is only ever read.
50
+ */
51
+ const ordinalWalks = new WeakMap();
52
+ const computeOrdinals = (file) => {
38
53
  const ordinals = new Map();
39
54
  let next = 0;
40
55
  const assign = (node) => {
@@ -1238,7 +1238,17 @@ export const bagShapeTypeAt = (table, typeOf, bags, node) => {
1238
1238
  // is not a new rule, it is the same rule reaching the node that stands for
1239
1239
  // the same value.
1240
1240
  const assignment = ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken ? node : null;
1241
- const asked = ts.isExpression(node) ? node : ts.isVariableDeclaration(node) ? node.initializer : undefined;
1241
+ // A literal's member `targets: {}` is the same: the enclosing record's field
1242
+ // is asked with the `PropertyAssignment`, every `state.targets[ k ]` with an
1243
+ // expression. Answering only the reads left the field at the checker's `{}`,
1244
+ // so each access recast it into the bag's layout -- a fresh COPY -- and
1245
+ // three's `transmissionRenderTarget[ camera.id ] = target` wrote into a
1246
+ // temporary the next read never saw.
1247
+ const asked = ts.isExpression(node)
1248
+ ? node
1249
+ : ts.isVariableDeclaration(node) || ts.isPropertyAssignment(node)
1250
+ ? node.initializer
1251
+ : undefined;
1242
1252
  const optional = bagSlotTypeOf(typeOf, bags);
1243
1253
  // A cell whose bag arrives by assignment rather than by its initializer --
1244
1254
  // see `shapeForOwner`. Asked only after the initializer, so a declaration
@@ -1252,7 +1262,11 @@ export const bagShapeTypeAt = (table, typeOf, bags, node) => {
1252
1262
  // carriers. `shapeForOwner` is identity-keyed and returns nothing for an
1253
1263
  // ordinary assignment to an existing variable, so this admits only the
1254
1264
  // checker-proven JS-field form rather than guessing from assignment syntax.
1255
- const owned = ts.isVariableDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isParameter(node) || assignment !== null
1265
+ const owned = ts.isVariableDeclaration(node) ||
1266
+ ts.isPropertyDeclaration(node) ||
1267
+ ts.isPropertyAssignment(node) ||
1268
+ ts.isParameter(node) ||
1269
+ assignment !== null
1256
1270
  ? bags.shapeForOwner(node)
1257
1271
  : null;
1258
1272
  if (asked === undefined)
@@ -42,7 +42,7 @@ export type OmittedStatedParameterAnswer = {
42
42
  export declare const omissionStatedTypeOf: (checker: ts.TypeChecker, parameter: ts.ParameterDeclaration) => ts.Type | null;
43
43
  /**
44
44
  * `stated | undefined` when some caller in the (already closed) caller set
45
- * omits the argument at `index`.
45
+ * omits the argument at `index`, or passes one that can itself be `undefined`.
46
46
  *
47
47
  * `null` when no caller provably omits it -- every caller passes it, or there
48
48
  * is no attributed caller at all -- so the statement stands as written and
@@ -1,5 +1,5 @@
1
1
  import ts from 'typescript';
2
- import { annotationStatesNothing, containsUnstatedPosition, isUnusableEvidence, jsDocTypeStatesNothing } from './derived-expression-type.js';
2
+ import { annotationStatesNothing, containsUnstatedPosition, isUnusableEvidence, jsDocTypeStatesNothing, withoutUndefinedMember } from './derived-expression-type.js';
3
3
  /** The JSDoc statement of a JavaScript parameter this rule may widen, or `null`. */
4
4
  export const omissionStatedTypeOf = (checker, parameter) => {
5
5
  if ((parameter.flags & ts.NodeFlags.JavaScriptFile) === 0)
@@ -28,7 +28,7 @@ export const omissionStatedTypeOf = (checker, parameter) => {
28
28
  };
29
29
  /**
30
30
  * `stated | undefined` when some caller in the (already closed) caller set
31
- * omits the argument at `index`.
31
+ * omits the argument at `index`, or passes one that can itself be `undefined`.
32
32
  *
33
33
  * `null` when no caller provably omits it -- every caller passes it, or there
34
34
  * is no attributed caller at all -- so the statement stands as written and
@@ -41,7 +41,33 @@ export const statedParameterWithOmission = (checker, stated, index, calls, argum
41
41
  const argumentLists = calls.map((call) => argumentsOf(call) ?? []);
42
42
  // A spread at or before the position may or may not reach it.
43
43
  const reachedBySpread = (args) => args.slice(0, index + 1).some(ts.isSpreadElement);
44
- if (!argumentLists.some((args) => args[index] === undefined && !reachedBySpread(args)))
44
+ // Absence reaches the parameter two ways: a call that leaves the argument
45
+ // out, and a call that passes a value which can itself be `undefined`. The
46
+ // second is the first with a forwarding hop in between -- three's
47
+ // `refreshMaterialUniforms( ..., transmissionRenderTarget )` hands its own
48
+ // parameter (`state.transmissionRenderTarget[ camera.id ]`, undefined until
49
+ // the first transmissive draw) to `refreshUniformsPhysical`, which reads it
50
+ // only under `material.transmission > 0`. Forwarding an absent value is no
51
+ // read of it, so the callee's slot must be able to hold it; refusing the
52
+ // widening left a required slot that threw at the call.
53
+ const carriesAbsence = (type) => (type.isUnion() ? type.types : [type]).some((part) => (part.flags & ts.TypeFlags.Undefined) !== 0);
54
+ const omitted = argumentLists.some((args) => args[index] === undefined && !reachedBySpread(args));
55
+ const passedAbsent = argumentLists.some((args) => {
56
+ const argument = args[index];
57
+ if (argument === undefined || reachedBySpread(args))
58
+ return false;
59
+ const type = argumentType(argument);
60
+ return type !== null && carriesAbsence(type);
61
+ });
62
+ if (!omitted && !passedAbsent)
63
+ return null;
64
+ // A statement that already admits `undefined` holds a passed absent value as
65
+ // written, so this rule has nothing to add -- and binding it anyway would
66
+ // pre-empt every later rule that refines the parameter. The native-webgl
67
+ // overlay states three's uniform setters as `NativeUniformValue`, which
68
+ // includes `undefined`; claiming those left `array[ 0 ]` reading the whole
69
+ // value union. (An omitted argument keeps its existing answer.)
70
+ if (!omitted && carriesAbsence(stated))
45
71
  return null;
46
72
  for (const args of argumentLists) {
47
73
  if (reachedBySpread(args))
@@ -52,7 +78,11 @@ export const statedParameterWithOmission = (checker, stated, index, calls, argum
52
78
  const type = argumentType(argument);
53
79
  if (!type || isUnusableEvidence(type) || (type.flags & ts.TypeFlags.Unknown) !== 0)
54
80
  return { refused: 'stated-omission-argument-unresolved' };
55
- if (!checker.isTypeAssignableTo(type, stated))
81
+ // A bare `undefined` is pure absence, which is what widens the slot; otherwise the rest of the
82
+ // argument is held to the statement.
83
+ if ((type.flags & ts.TypeFlags.Undefined) !== 0)
84
+ continue;
85
+ if (!checker.isTypeAssignableTo(withoutUndefinedMember(checker, type), stated))
56
86
  return { refused: 'stated-omission-argument-not-assignable' };
57
87
  }
58
88
  return { type: checker.getNullableType(stated, ts.TypeFlags.Undefined) };
@@ -3313,6 +3313,9 @@ hostProvided = noHostProvidedNames) => {
3313
3313
  // like any inference, and its obligations are kept with the binding.
3314
3314
  propagating.reset();
3315
3315
  // `GEA_STATED_OMISSION_OFF` keeps the arm without this rule runnable, the way `GEA_BAG_OFF` is.
3316
+ // The parameters this rule widened. The class-instance rule below still owns
3317
+ // their LAYOUT -- see its own comment -- and keeps this rule's absence arm.
3318
+ const omissionWidened = new Set();
3316
3319
  for (const site of process.env['GEA_STATED_OMISSION_OFF'] ? [] : index.omissionSites) {
3317
3320
  if (bindings.has(site.parameter) || unionArms.has(site.parameter))
3318
3321
  continue;
@@ -3338,6 +3341,7 @@ hostProvided = noHostProvidedNames) => {
3338
3341
  bindings.set(site.parameter, answer.type);
3339
3342
  statedBindings.set(site.parameter, answer.type);
3340
3343
  protocolRequirements.set(site.parameter, captured.requirements);
3344
+ omissionWidened.add(site.parameter);
3341
3345
  if (process.env['GEA_BINDING_DEBUG'])
3342
3346
  console.error(`[STATED-OMISSION] ${describeParameter(site.parameter)} :: ${checker.typeToString(answer.type)}`);
3343
3347
  }
@@ -3380,7 +3384,14 @@ hostProvided = noHostProvidedNames) => {
3380
3384
  // converts into it, and the class arm only holds what a caller it CAN see
3381
3385
  // provably passes -- the object itself, never a copy of it.
3382
3386
  for (const site of index.classInstanceSites) {
3383
- if (bindings.has(site.parameter) || unionArms.has(site.parameter) || recordHomeArms.has(site.parameter))
3387
+ // A parameter the omission rule widened is still this rule's: widening
3388
+ // answers only "may it be absent", while this answers which object the
3389
+ // record statement holds. memory-pager's `updated(page)` receives a `Page`
3390
+ // instance the census types `Page | undefined`; bound as the bare widened
3391
+ // statement, the instance was viewed into the record's struct -- a copy --
3392
+ // and `pager.updates[0] === one` compared a record with a `Page`.
3393
+ const widened = omissionWidened.has(site.parameter);
3394
+ if ((bindings.has(site.parameter) && !widened) || unionArms.has(site.parameter) || recordHomeArms.has(site.parameter))
3384
3395
  continue;
3385
3396
  if (!ts.isIdentifier(site.parameter.name))
3386
3397
  continue;
@@ -3397,7 +3408,12 @@ hostProvided = noHostProvidedNames) => {
3397
3408
  if (classes.length === 0)
3398
3409
  continue;
3399
3410
  const declaredArms = site.stated.isUnion() ? site.stated.types : [site.stated];
3400
- recordHomeArms.set(site.parameter, withDeclaredAbsenceArms(site.parameter, [...declaredArms, ...classes]));
3411
+ const absence = widened ? [checker.getUndefinedType()] : [];
3412
+ recordHomeArms.set(site.parameter, withDeclaredAbsenceArms(site.parameter, [...declaredArms, ...classes, ...absence]));
3413
+ if (widened) {
3414
+ bindings.delete(site.parameter);
3415
+ statedBindings.delete(site.parameter);
3416
+ }
3401
3417
  if (process.env['GEA_BINDING_DEBUG'])
3402
3418
  console.error(`[CLASS-INSTANCE] ${describeParameter(site.parameter)} :: ${classes.map((arm) => checker.typeToString(arm)).join(' | ')}`);
3403
3419
  }
@@ -3543,14 +3559,24 @@ hostProvided = noHostProvidedNames) => {
3543
3559
  * construct path. Only the absence members are taken from the checker --
3544
3560
  * everything else the read holds is still the census's answer.
3545
3561
  */
3546
- const withReadAbsenceOf = (read, bound) => {
3562
+ const withReadAbsenceOf = (read, parameter, bound) => {
3547
3563
  if (!bound.isUnion())
3548
3564
  return bound;
3549
3565
  const checked = checker.getTypeAtLocation(read);
3550
3566
  if ((checked.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0)
3551
3567
  return bound;
3552
- const present = (checked.isUnion() ? checked.types : [checked]).reduce((flags, part) => flags | part.flags, 0);
3553
- const dropped = (ts.TypeFlags.Undefined | ts.TypeFlags.Null) & ~present;
3568
+ const flagsOf = (type) => (type.isUnion() ? type.types : [type]).reduce((flags, part) => flags | part.flags, 0);
3569
+ const present = flagsOf(checked);
3570
+ // The checker's read lacks an absence only as evidence that its flow ruled
3571
+ // it out when the parameter's own declaration admits it. A binding that
3572
+ // ADDS an absence the statement never spelled -- `omitted-stated-
3573
+ // parameter.ts`'s `@param {boolean} premultipliedAlpha` that
3574
+ // `colorBuffer.setClear( 0, 0, 0, 1 )` leaves out -- reads as `boolean` at
3575
+ // every mention, so stripping on that basis undid the widening at each
3576
+ // read: three's `premultipliedAlpha === true` converted the omitted
3577
+ // argument to a bare boolean and threw where the language answers false.
3578
+ const declared = flagsOf(checker.getTypeAtLocation(parameter));
3579
+ const dropped = (ts.TypeFlags.Undefined | ts.TypeFlags.Null) & ~present & declared;
3554
3580
  // A narrowed `BufferSource` read under `ArrayBuffer.isView(data)` is an
3555
3581
  // `ArrayBufferView` to the checker: the arms its flow ruled out are the
3556
3582
  // callers' arms not assignable to what it reads there.
@@ -3625,7 +3651,7 @@ hostProvided = noHostProvidedNames) => {
3625
3651
  continue;
3626
3652
  if (guardNarrowsDynamicBinding(node, narrowed))
3627
3653
  return null;
3628
- return withReadAbsenceOf(node, bodyBindingOf(declaration, narrowed));
3654
+ return withReadAbsenceOf(node, declaration, bodyBindingOf(declaration, narrowed));
3629
3655
  }
3630
3656
  return null;
3631
3657
  };
@@ -3671,7 +3697,7 @@ hostProvided = noHostProvidedNames) => {
3671
3697
  const narrowed = ordinal === null ? undefined : copyBindings.get(parameter)?.get(ordinal);
3672
3698
  if (!narrowed)
3673
3699
  return null;
3674
- return node === parameter || !ts.isIdentifier(node) ? narrowed : withReadAbsenceOf(node, bodyBindingOf(parameter, narrowed));
3700
+ return node === parameter || !ts.isIdentifier(node) ? narrowed : withReadAbsenceOf(node, parameter, bodyBindingOf(parameter, narrowed));
3675
3701
  };
3676
3702
  // Implicit slots have an owning signature but no parameter declaration.
3677
3703
  // Reuse the settled call attribution and resolver; never start a second
@@ -2169,6 +2169,23 @@ const buildMapper = (checker, identities, table, instantiations, specializations
2169
2169
  .find((candidate) => candidate.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown));
2170
2170
  if (absorbing)
2171
2171
  return remember(type, typeOf(absorbing));
2172
+ // The global `Object` interface absorbs it too. It is interned as `any`
2173
+ // (above), and a union with a member that is `any` IS `any`; but the
2174
+ // checker keeps `Object | string` as a two-member union, because it only
2175
+ // reduces by `any` flags, so the member reached here as an `any` arm
2176
+ // BESIDE a string one. A sum with an open arm is not a sum: its arms are
2177
+ // not disjoint (every value is the open arm's), a `false` handed to the
2178
+ // parameter matched neither arm, and a live string was ambiguous between
2179
+ // them at the unbox. three.js's `Object3D.toJSON( meta )` is documented
2180
+ // `{?(Object|string)}` and `LightShadow.toJSON` passes `false`. `Object`
2181
+ // admits every non-nullish value -- strings included -- so the union
2182
+ // states nothing the open carrier does not.
2183
+ const objectMember = type.types.find((member) => {
2184
+ const anchor = member.getSymbol()?.declarations?.[0];
2185
+ return anchor !== undefined && isGlobalObjectInterface(checker, anchor, member);
2186
+ });
2187
+ if (objectMember)
2188
+ return remember(type, typeOf(objectMember));
2172
2189
  // An arm naming a type the host says is ABSENT is not an arm this
2173
2190
  // program can ever take. `absentGlobals` already folds the VALUE
2174
2191
  // (`typeof HTMLImageElement !== 'undefined'` is `false` on a headless