@geastack/compiler 1.0.42 → 1.0.44
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.
- package/dist/cli.js +8 -2
- package/dist/conversion/nodes.js +5 -2
- package/dist/ir/callable-class-flow.js +48 -13
- package/dist/ir/certify.js +1 -1
- package/dist/ir/host-template-conversions.d.ts +2 -2
- package/dist/ir/host-template-conversions.js +73 -2
- package/dist/ir/lower-destructuring.js +22 -3
- package/dist/ir/lower-operands.js +30 -1
- package/dist/ir/native-field-view-facts.d.ts +8 -1
- package/dist/ir/native-field-view-facts.js +13 -3
- package/dist/ir/operation-conversions.js +1 -1
- package/dist/ir/program-conversions.d.ts +1 -1
- package/dist/ir/program-conversions.js +68 -1
- package/dist/ir/property-read-conversions.js +7 -1
- package/dist/ir/publish-native-field-view-facts.js +4 -0
- package/dist/ir/reflection-demand.js +29 -3
- package/dist/ir/shake.js +21 -0
- package/dist/projection/dispatch.d.ts +19 -1
- package/dist/projection/dispatch.js +34 -0
- package/dist/representation/value-records.js +182 -13
- package/dist/semantics/frontend.js +18 -14
- package/dist/semantics/normalize/collection-bindings.d.ts +7 -0
- package/dist/semantics/normalize/collection-bindings.js +35 -1
- package/dist/semantics/normalize/derived-expression-type.js +49 -0
- package/dist/semantics/normalize/field-bindings.js +6 -1
- package/dist/semantics/normalize/flow/component-solver.js +37 -2
- package/dist/semantics/normalize/flow/source-value-session.d.ts +12 -2
- package/dist/semantics/normalize/flow/source-value-session.js +861 -212
- package/dist/semantics/normalize/global-host-mutations.js +14 -6
- package/dist/semantics/normalize/implicit-arguments-tuple.d.ts +11 -10
- package/dist/semantics/normalize/implicit-arguments-tuple.js +15 -3
- package/dist/semantics/normalize/local-bindings.js +23 -1
- package/dist/semantics/normalize/producers/references.js +26 -18
- package/dist/semantics/normalize/structural-array-element.d.ts +7 -0
- package/dist/semantics/normalize/structural-array-element.js +24 -1
- package/dist/semantics/normalize/structural-layout-type.js +5 -1
- package/dist/semantics/normalize/structural-mutable-method.js +88 -2
- package/dist/semantics/normalize/structural-parts.js +13 -8
- package/dist/semantics/normalize/structural.js +25 -1
- package/dist/targets/cpp/borrowed-call-entry.d.ts +41 -2
- package/dist/targets/cpp/borrowed-call-entry.js +91 -6
- package/dist/targets/cpp/class-properties/emit-class-properties.js +5 -1
- package/dist/targets/cpp/emit-callable.js +81 -39
- package/dist/targets/cpp/emit-native-field-view.d.ts +2 -0
- package/dist/targets/cpp/emit-native-field-view.js +1 -1
- package/dist/targets/cpp/emit-properties.js +114 -12
- package/dist/targets/cpp/host/emit-host-invoke.js +16 -2
- package/dist/targets/cpp/host/emit-host-object.js +69 -2
- package/dist/targets/cpp/host/host-members.js +4 -0
- package/dist/targets/cpp/prototype/emit-prototype-array.d.ts +42 -0
- package/dist/targets/cpp/prototype/emit-prototype-array.js +31 -9
- package/dist/targets/cpp/records.d.ts +1 -0
- package/dist/targets/cpp/records.js +40 -17
- package/dist/targets/cpp/translation-unit.js +82 -24
- package/dist/targets/cpp/virtual-methods.js +9 -4
- package/package.json +1 -1
- package/src/targets/cpp/runtime/gea_dynamic_proxy.h +17 -1
- package/src/targets/cpp/runtime/gea_runtime.h +485 -64
|
@@ -1009,6 +1009,15 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
|
|
|
1009
1009
|
*/
|
|
1010
1010
|
const isDefinitelyProgramSymbolElementKey = (expression) => ts.isElementAccessExpression(expression) && isProgramSymbolKeyExpression(expression.argumentExpression);
|
|
1011
1011
|
const overwrittenIntrinsicSymbols = new Set();
|
|
1012
|
+
// Every declaration of an overwritten symbol, so `intrinsicSymbolIsOverwritten`
|
|
1013
|
+
// asks of a symbol's own declarations rather than scanning every assignment
|
|
1014
|
+
// target of the program on each question.
|
|
1015
|
+
const overwrittenDeclarations = new Set();
|
|
1016
|
+
const overwriteIntrinsicSymbol = (symbol) => {
|
|
1017
|
+
overwrittenIntrinsicSymbols.add(symbol);
|
|
1018
|
+
for (const declaration of symbol.declarations ?? [])
|
|
1019
|
+
overwrittenDeclarations.add(declaration);
|
|
1020
|
+
};
|
|
1012
1021
|
const propertyKeyDomains = createPropertyKeyDomains(checker, flow, flowSiteIsReachable, publishedTypeAt);
|
|
1013
1022
|
// A computed key set, with Object.prototype's possible enumerable keys
|
|
1014
1023
|
// added when it leans on them; its assumptions are checked at the end.
|
|
@@ -1136,8 +1145,7 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
|
|
|
1136
1145
|
return true;
|
|
1137
1146
|
if ([...computedIntrinsicKeys].some((domain) => propertyKeyDomains.mayName(domain, symbol.name)))
|
|
1138
1147
|
return true;
|
|
1139
|
-
const
|
|
1140
|
-
const overwritten = [...overwrittenIntrinsicSymbols].some((candidate) => (candidate.declarations ?? []).some((declaration) => declarations.has(declaration)));
|
|
1148
|
+
const overwritten = (symbol.declarations ?? []).some((declaration) => overwrittenDeclarations.has(declaration));
|
|
1141
1149
|
if (!overwritten)
|
|
1142
1150
|
trustedIntrinsicNames.add(symbol.name);
|
|
1143
1151
|
return overwritten;
|
|
@@ -1376,13 +1384,13 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
|
|
|
1376
1384
|
}
|
|
1377
1385
|
const symbol = actualSymbol(checker.getPropertyOfType(checker.getTypeAtLocation(target), key));
|
|
1378
1386
|
if (symbol)
|
|
1379
|
-
|
|
1387
|
+
overwriteIntrinsicSymbol(symbol);
|
|
1380
1388
|
};
|
|
1381
1389
|
for (const node of nodes) {
|
|
1382
1390
|
if (ts.isIdentifier(node) && isDirectAssignmentTarget(node)) {
|
|
1383
1391
|
const symbol = actualSymbol(checker.getSymbolAtLocation(node));
|
|
1384
1392
|
if (symbol)
|
|
1385
|
-
|
|
1393
|
+
overwriteIntrinsicSymbol(symbol);
|
|
1386
1394
|
continue;
|
|
1387
1395
|
}
|
|
1388
1396
|
if ((ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) && isDirectAssignmentTarget(node)) {
|
|
@@ -1412,7 +1420,7 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
|
|
|
1412
1420
|
intrinsicSurfaceMemberReplaced = true;
|
|
1413
1421
|
const symbol = memberSymbolOf(node);
|
|
1414
1422
|
if (symbol)
|
|
1415
|
-
|
|
1423
|
+
overwriteIntrinsicSymbol(symbol);
|
|
1416
1424
|
else if (staticKeyOf(node) === null &&
|
|
1417
1425
|
!isDefinitelyNumericElementKey(node) &&
|
|
1418
1426
|
!isDefinitelyProgramSymbolElementKey(node) &&
|
|
@@ -1424,7 +1432,7 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
|
|
|
1424
1432
|
continue;
|
|
1425
1433
|
const member = actualSymbol(checker.getPropertyOfType(checker.getTypeAtLocation(node.expression), key.name));
|
|
1426
1434
|
if (member)
|
|
1427
|
-
|
|
1435
|
+
overwriteIntrinsicSymbol(member);
|
|
1428
1436
|
}
|
|
1429
1437
|
continue;
|
|
1430
1438
|
}
|
|
@@ -11,17 +11,18 @@ import { type ImplicitArgumentsSlot } from './implicit-arguments.js';
|
|
|
11
11
|
*
|
|
12
12
|
* - `tuple`: every read names a FIXED position -- a literal index, or a final
|
|
13
13
|
* `...arguments` spread into a callee convention with no rest formal, which
|
|
14
|
-
* reads positions `0..n-1` exactly
|
|
15
|
-
* joined over the closed callers that fill
|
|
16
|
-
* forwarding shims need: `texImage3D()` is
|
|
17
|
-
* leading positions and `ArrayBufferView | null`
|
|
18
|
-
* type over all ten positions could only be a
|
|
19
|
-
* Positions from `required` on are ones some closed
|
|
20
|
-
* are optional: a read there is `T | undefined`,
|
|
21
|
-
* the field absent rather than inventing a value
|
|
14
|
+
* reads positions `0..n-1` exactly -- or reads the frame's `length`. Each
|
|
15
|
+
* position is then its own fact, joined over the closed callers that fill
|
|
16
|
+
* it. This is the shape WebGL forwarding shims need: `texImage3D()` is
|
|
17
|
+
* called with numbers in its leading positions and `ArrayBufferView | null`
|
|
18
|
+
* in its last, and one element type over all ten positions could only be a
|
|
19
|
+
* union no caller wrote. Positions from `required` on are ones some closed
|
|
20
|
+
* caller omits, so they are optional: a read there is `T | undefined`, the
|
|
21
|
+
* rest slot leaves the field absent rather than inventing a value, and the
|
|
22
|
+
* frame's length counts the fields present.
|
|
22
23
|
* - `array`: the body reads a position only known at run time
|
|
23
|
-
* (`arguments[i]
|
|
24
|
-
*
|
|
24
|
+
* (`arguments[i]`), reads its own element back through a recursive call,
|
|
25
|
+
* or declares parameters in front of the phantom slot.
|
|
25
26
|
* The frame is then a runtime-sized Array of one element type joined over
|
|
26
27
|
* every supplied position -- the frame this fact published before positions
|
|
27
28
|
* existed.
|
|
@@ -64,8 +64,12 @@ const useOf = (checker, use) => {
|
|
|
64
64
|
const access = use.parent;
|
|
65
65
|
if (ts.isElementAccessExpression(access) && access.expression === use)
|
|
66
66
|
return { read: fixedPositionOf(checker, access) === null ? 'indexed' : 'fixed', access };
|
|
67
|
+
// The count of arguments a call passed is the tuple's own length: the
|
|
68
|
+
// positions from `required` on are optional elements, present exactly when
|
|
69
|
+
// the caller wrote them (an explicit `undefined` included), so a body that
|
|
70
|
+
// picks a call form by `arguments.length` keeps its positional frame.
|
|
67
71
|
if (ts.isPropertyAccessExpression(access) && access.expression === use && access.name.text === 'length')
|
|
68
|
-
return { read: '
|
|
72
|
+
return { read: 'length', access };
|
|
69
73
|
if (ts.isSpreadElement(access) && access.expression === use) {
|
|
70
74
|
const call = access.parent;
|
|
71
75
|
if ((ts.isCallExpression(call) || ts.isNewExpression(call)) && call.arguments) {
|
|
@@ -86,6 +90,7 @@ const useOf = (checker, use) => {
|
|
|
86
90
|
export const inferImplicitArgumentsTuple = (evidence) => {
|
|
87
91
|
const { checker, owner, slot, uses } = evidence;
|
|
88
92
|
let indexed = slot.ordinal > 0;
|
|
93
|
+
let readsLength = false;
|
|
89
94
|
for (const use of uses) {
|
|
90
95
|
// A lexical arguments capture needs a frame identity shared with its
|
|
91
96
|
// outer function; a local ordinal alone cannot establish that identity.
|
|
@@ -98,6 +103,8 @@ export const inferImplicitArgumentsTuple = (evidence) => {
|
|
|
98
103
|
return { refused: 'implicit-arguments-object-escapes' };
|
|
99
104
|
if (reading.read === 'indexed')
|
|
100
105
|
indexed = true;
|
|
106
|
+
if (reading.read === 'length')
|
|
107
|
+
readsLength = true;
|
|
101
108
|
// The shared write inventory already includes parenthesized targets,
|
|
102
109
|
// destructuring, updates, loops and deletes. Do not invent a second
|
|
103
110
|
// assignment classifier for this one binding.
|
|
@@ -146,10 +153,15 @@ export const inferImplicitArgumentsTuple = (evidence) => {
|
|
|
146
153
|
for (const [position, written] of Array.from(positions, (entry) => entry ?? []).entries()) {
|
|
147
154
|
const element = written.length > 0 ? (joinOfWrites(checker, written) ?? disjointUnionTypeOf(checker, written)) : null;
|
|
148
155
|
if (!element)
|
|
149
|
-
|
|
156
|
+
break;
|
|
150
157
|
elements[position] = element;
|
|
151
158
|
}
|
|
152
|
-
|
|
159
|
+
if (elements.length === positions.length)
|
|
160
|
+
return { tuple: { frame: 'tuple', elements, required: Math.min(required, elements.length), sourcePositions } };
|
|
161
|
+
// A length read was an Array frame's before it was a tuple's; a position
|
|
162
|
+
// with no join keeps that frame rather than refusing the owner.
|
|
163
|
+
if (!readsLength)
|
|
164
|
+
return { refused: 'implicit-arguments-disjoint-position' };
|
|
153
165
|
}
|
|
154
166
|
// An annotation can supply a common upper bound absent from the
|
|
155
167
|
// observed subclasses. It is only a candidate: every supplied position,
|
|
@@ -718,6 +718,15 @@ moduleRecords = emptyCommonJsModuleRecordCensus) => {
|
|
|
718
718
|
* element type, as do indexed reads whose absence is not observed.
|
|
719
719
|
*/
|
|
720
720
|
const observedIndexedAbsence = new Map();
|
|
721
|
+
/**
|
|
722
|
+
* The same observation over a read the checker types `any` (`const lit = []`
|
|
723
|
+
* in a JavaScript file). `any` names no element, but this census may still
|
|
724
|
+
* type the cell from its write, and the read itself already admits absence
|
|
725
|
+
* (`structural-array-read.ts`'s `admitsUndefined`). The cell's type is known
|
|
726
|
+
* only once resolution settles, so its declaration and observing references
|
|
727
|
+
* wait for it.
|
|
728
|
+
*/
|
|
729
|
+
const untypedObservedAbsence = [];
|
|
721
730
|
const directUndefinedComparison = (expression) => {
|
|
722
731
|
let inner = expression;
|
|
723
732
|
let parent = inner.parent;
|
|
@@ -787,7 +796,8 @@ moduleRecords = emptyCommonJsModuleRecordCensus) => {
|
|
|
787
796
|
if (!arrayRead && !dictionaryRead && !assertedRead)
|
|
788
797
|
return;
|
|
789
798
|
const value = checker.getTypeAtLocation(initializer);
|
|
790
|
-
|
|
799
|
+
const untyped = isAnyType(value);
|
|
800
|
+
if (!untyped && (isUnusableEvidence(value) || (value.flags & ts.TypeFlags.Unknown) !== 0))
|
|
791
801
|
return;
|
|
792
802
|
const symbol = checker.getSymbolAtLocation(declaration.name);
|
|
793
803
|
if (!symbol)
|
|
@@ -797,6 +807,10 @@ moduleRecords = emptyCommonJsModuleRecordCensus) => {
|
|
|
797
807
|
.filter((reference) => directUndefinedComparison(reference) || directTruthinessTest(reference));
|
|
798
808
|
if (observing.length === 0)
|
|
799
809
|
return;
|
|
810
|
+
if (untyped) {
|
|
811
|
+
untypedObservedAbsence.push({ declaration, nodes: [declaration, declaration.name, ...observing] });
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
800
814
|
const optional = checker.getNullableType(value, ts.TypeFlags.Undefined);
|
|
801
815
|
observedIndexedAbsence.set(declaration, optional);
|
|
802
816
|
observedIndexedAbsence.set(declaration.name, optional);
|
|
@@ -1799,6 +1813,14 @@ moduleRecords = emptyCommonJsModuleRecordCensus) => {
|
|
|
1799
1813
|
if (bound.size === before)
|
|
1800
1814
|
break;
|
|
1801
1815
|
}
|
|
1816
|
+
for (const { declaration, nodes } of untypedObservedAbsence) {
|
|
1817
|
+
const cell = bound.get(declaration);
|
|
1818
|
+
if (!cell)
|
|
1819
|
+
continue;
|
|
1820
|
+
const optional = checker.getNullableType(cell, ts.TypeFlags.Undefined);
|
|
1821
|
+
for (const node of nodes)
|
|
1822
|
+
observedIndexedAbsence.set(node, optional);
|
|
1823
|
+
}
|
|
1802
1824
|
// `root` is the same stable, hand-written reason string this census always
|
|
1803
1825
|
// keyed its old count map by (`no-symbol`, `write-unresolved`, one of
|
|
1804
1826
|
// `noEvidenceReason`'s `no-writes:...` family, ...) -- never node text or a
|
|
@@ -43,8 +43,13 @@ const includesUndefined = (type) => {
|
|
|
43
43
|
return true;
|
|
44
44
|
return type.isUnion() && type.types.some(includesUndefined);
|
|
45
45
|
};
|
|
46
|
-
/**
|
|
47
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Whether this expression is an equality operand or `instanceof`'s left
|
|
48
|
+
* operand. Both answer for `undefined` without reading it: IsStrictlyEqual and
|
|
49
|
+
* IsLooselyEqual compare it, and OrdinaryHasInstance returns false for a
|
|
50
|
+
* non-object.
|
|
51
|
+
*/
|
|
52
|
+
const comparesItsOperand = (node) => {
|
|
48
53
|
let inner = node;
|
|
49
54
|
let parent = inner.parent;
|
|
50
55
|
while (parent && ts.isParenthesizedExpression(parent)) {
|
|
@@ -54,14 +59,12 @@ const comparesWithUndefined = (context, node) => {
|
|
|
54
59
|
if (!parent || !ts.isBinaryExpression(parent))
|
|
55
60
|
return false;
|
|
56
61
|
const operator = parent.operatorToken.kind;
|
|
57
|
-
if (operator
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
operator
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const other = parent.left === inner ? parent.right : parent.right === inner ? parent.left : null;
|
|
64
|
-
return other !== null && (context.types.rawTypeAt(other).flags & ts.TypeFlags.Undefined) !== 0;
|
|
62
|
+
if (operator === ts.SyntaxKind.InstanceOfKeyword)
|
|
63
|
+
return parent.left === inner;
|
|
64
|
+
return (operator === ts.SyntaxKind.EqualsEqualsToken ||
|
|
65
|
+
operator === ts.SyntaxKind.ExclamationEqualsToken ||
|
|
66
|
+
operator === ts.SyntaxKind.EqualsEqualsEqualsToken ||
|
|
67
|
+
operator === ts.SyntaxKind.ExclamationEqualsEqualsToken);
|
|
65
68
|
};
|
|
66
69
|
/**
|
|
67
70
|
* Keep an explicitly optional local's physical absence when this use has a
|
|
@@ -71,21 +74,26 @@ const comparesWithUndefined = (context, node) => {
|
|
|
71
74
|
* property producer restores that absence and the cell therefore physically
|
|
72
75
|
* holds `Optional<T>`; dereferencing it at a later optional return or
|
|
73
76
|
* `!== undefined` test would discard the very absence the producer recovered.
|
|
77
|
+
* An unannotated local has the same cell when the local-binding census
|
|
78
|
+
* restored the absence from a later test (`observedIndexedAbsence`), and the
|
|
79
|
+
* checker types its other reads `T` just the same.
|
|
74
80
|
*
|
|
75
81
|
* This does not suppress ordinary control-flow narrowing: only a use whose
|
|
76
|
-
* contextual destination itself admits `undefined`, or which
|
|
77
|
-
*
|
|
78
|
-
* continues to use the checker's narrowed answer and its existing
|
|
79
|
-
* proof/conversion.
|
|
82
|
+
* contextual destination itself admits `undefined`, or which compares it
|
|
83
|
+
* (`comparesItsOperand`), keeps the declaration's stated carrier. A use that
|
|
84
|
+
* requires `T` continues to use the checker's narrowed answer and its existing
|
|
85
|
+
* presence proof/conversion.
|
|
80
86
|
*/
|
|
81
87
|
const destinationPreservesDeclaredAbsence = (context, node, declaration) => {
|
|
82
|
-
if (!declaration || !ts.isVariableDeclaration(declaration)
|
|
88
|
+
if (!declaration || !ts.isVariableDeclaration(declaration))
|
|
83
89
|
return null;
|
|
84
|
-
const declared =
|
|
85
|
-
|
|
90
|
+
const declared = declaration.type !== undefined
|
|
91
|
+
? context.checker.getTypeAtLocation(declaration.name)
|
|
92
|
+
: (context.parameters.preferredTypeAt?.(declaration) ?? null);
|
|
93
|
+
if (!declared || !includesUndefined(declared))
|
|
86
94
|
return null;
|
|
87
95
|
const contextual = context.checker.getContextualType(node);
|
|
88
|
-
if ((contextual === undefined || !includesUndefined(contextual)) && !
|
|
96
|
+
if ((contextual === undefined || !includesUndefined(contextual)) && !comparesItsOperand(node))
|
|
89
97
|
return null;
|
|
90
98
|
return context.types.typeAt(declaration);
|
|
91
99
|
};
|
|
@@ -3,6 +3,13 @@ import type { StructuralTypeId } from '../../identity/ids.js';
|
|
|
3
3
|
import type { StructuralTypeTable } from '../model/structural-type-table.js';
|
|
4
4
|
import type { CollectionBindingCensus } from './collection-bindings.js';
|
|
5
5
|
import { type ObjectBagCensus } from './object-bag-bindings.js';
|
|
6
|
+
/**
|
|
7
|
+
* Whether a computed read (`this.koto[layer]`) can select an object literal's
|
|
8
|
+
* `[]` member that `arrayHoldsUnjoinedWrites`. That member is stored as the
|
|
9
|
+
* box (`inferredArrayElementAt`), while the checker still answers the read
|
|
10
|
+
* with the member's `never[]`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const readsUnjoinedArrayMember: (checker: ts.TypeChecker, collections: CollectionBindingCensus, layoutTypeAt: (node: ts.Node) => ts.Type, node: ts.ElementAccessExpression) => boolean;
|
|
6
13
|
export declare const unstatedNeverArray: (checker: ts.TypeChecker, collections: CollectionBindingCensus, layoutTypeAt: (node: ts.Node) => ts.Type, node: ts.Node) => boolean;
|
|
7
14
|
export declare const inferredArrayElementAt: (checker: ts.TypeChecker, collections: CollectionBindingCensus, layoutTypeAt: (node: ts.Node) => ts.Type, node: ts.Node) => ts.Type | null;
|
|
8
15
|
/**
|
|
@@ -245,6 +245,22 @@ const isOpenStringIndexType = (checker, type) => {
|
|
|
245
245
|
const index = checker.getIndexInfoOfType(type, ts.IndexKind.String);
|
|
246
246
|
return index !== undefined && (index.type.flags & ts.TypeFlags.Any) !== 0 && type.getCallSignatures().length === 0;
|
|
247
247
|
};
|
|
248
|
+
/**
|
|
249
|
+
* Whether a computed read (`this.koto[layer]`) can select an object literal's
|
|
250
|
+
* `[]` member that `arrayHoldsUnjoinedWrites`. That member is stored as the
|
|
251
|
+
* box (`inferredArrayElementAt`), while the checker still answers the read
|
|
252
|
+
* with the member's `never[]`.
|
|
253
|
+
*/
|
|
254
|
+
export const readsUnjoinedArrayMember = (checker, collections, layoutTypeAt, node) => {
|
|
255
|
+
const receiver = checker.getNonNullableType(layoutTypeAt(node.expression));
|
|
256
|
+
return (receiver.isUnion() ? receiver.types : [receiver]).some((arm) => checker.getPropertiesOfType(arm).some((property) => {
|
|
257
|
+
const declaration = property.declarations?.[0];
|
|
258
|
+
return (declaration !== undefined &&
|
|
259
|
+
ts.isPropertyAssignment(declaration) &&
|
|
260
|
+
ts.isArrayLiteralExpression(declaration.initializer) &&
|
|
261
|
+
collections.arrayHoldsUnjoinedWrites(declaration.initializer));
|
|
262
|
+
}));
|
|
263
|
+
};
|
|
248
264
|
export const unstatedNeverArray = (checker, collections, layoutTypeAt, node) => {
|
|
249
265
|
const neverElement = (type) => {
|
|
250
266
|
if (!checker.isArrayType(type))
|
|
@@ -356,8 +372,15 @@ const statesItsOwnType = (checker, node) => {
|
|
|
356
372
|
declaration.type !== undefined);
|
|
357
373
|
};
|
|
358
374
|
export const inferredArrayElementAt = (checker, collections, layoutTypeAt, node) => {
|
|
375
|
+
// An array filled with values the census could not join holds the box.
|
|
376
|
+
// Answered here, not by `unstatedNeverArray`, which leaves an object
|
|
377
|
+
// literal's member to the record's `never[]`: the record's member storage is
|
|
378
|
+
// asked at this same literal (`structural-parts.ts`), so both get the box.
|
|
359
379
|
if (ts.isArrayLiteralExpression(node))
|
|
360
|
-
return (collections.arrayElementAt(node) ??
|
|
380
|
+
return (collections.arrayElementAt(node) ??
|
|
381
|
+
iterableMergeArmElement(checker, layoutTypeAt, node) ??
|
|
382
|
+
definedPropertyArrayElement(checker, node) ??
|
|
383
|
+
(collections.arrayHoldsUnjoinedWrites(node) ? checker.getAnyType() : null));
|
|
361
384
|
// THE CELL'S OWN DECLARATION -- neither the literal that filled it nor a
|
|
362
385
|
// read of it, and the node a cell's stored carrier is actually published
|
|
363
386
|
// from. `const uvBuffer = []` types as `never[]` at the
|
|
@@ -502,7 +502,11 @@ export const createLayoutTypeResolver = (checker, parameters = emptyParameterBin
|
|
|
502
502
|
: ts.isShorthandPropertyAssignment(declaration)
|
|
503
503
|
? declaration.name
|
|
504
504
|
: declaration;
|
|
505
|
-
|
|
505
|
+
// ...unless that write's answer is only its own right-hand side, which
|
|
506
|
+
// states nothing about the field's other writes: see `memberOf`'s
|
|
507
|
+
// `assignedField`.
|
|
508
|
+
const written = parameters.typeAt(censusNode);
|
|
509
|
+
const fromCensus = ts.isBinaryExpression(censusNode) && written === checker.getTypeAtLocation(censusNode) ? parameters.typeAt(censusNode.left) : written;
|
|
506
510
|
if (fromCensus && !isUnreducedTypeForm(fromCensus) && (fromCensus.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) === 0)
|
|
507
511
|
return fromCensus;
|
|
508
512
|
const objectFlags = receiver.objectFlags ?? 0;
|
|
@@ -9,6 +9,70 @@ import { structuralCallSignatures } from './structural-callable.js';
|
|
|
9
9
|
export const createMutableMethodResolver = (checker, table, flow, signatureOf, read, receiverTypeAt) => {
|
|
10
10
|
const cache = new Map();
|
|
11
11
|
const pending = new Set();
|
|
12
|
+
const keyOf = (node) => ts.isPropertyAccessExpression(node)
|
|
13
|
+
? node.name.text
|
|
14
|
+
: ts.isStringLiteralLike(node.argumentExpression) || ts.isNumericLiteral(node.argumentExpression)
|
|
15
|
+
? node.argumentExpression.text
|
|
16
|
+
: null;
|
|
17
|
+
const memberSymbolOf = (node, key) => checker.getSymbolAtLocation(ts.isPropertyAccessExpression(node) ? node.name : node) ??
|
|
18
|
+
checker.getPropertyOfType(checker.getApparentType(receiverTypeAt(node.expression)), key);
|
|
19
|
+
// Keys some write stores through a receiver the checker cannot resolve to a
|
|
20
|
+
// member (`(m as any).hook = ...`): the write lands in the method's own slot
|
|
21
|
+
// at run time while naming no symbol, so `writesToSymbol` never sees it.
|
|
22
|
+
let untypedWrites;
|
|
23
|
+
const untypedWriteKeys = () => {
|
|
24
|
+
if (untypedWrites)
|
|
25
|
+
return untypedWrites;
|
|
26
|
+
const keys = new Set();
|
|
27
|
+
for (const access of flow?.propertyAccesses ?? []) {
|
|
28
|
+
const parent = access.parent;
|
|
29
|
+
if (!ts.isBinaryExpression(parent) || parent.left !== access || parent.operatorToken.kind !== ts.SyntaxKind.EqualsToken)
|
|
30
|
+
continue;
|
|
31
|
+
const key = keyOf(access);
|
|
32
|
+
if (key !== null && checker.getSymbolAtLocation(ts.isPropertyAccessExpression(access) ? access.name : access) === undefined)
|
|
33
|
+
keys.add(key);
|
|
34
|
+
}
|
|
35
|
+
return (untypedWrites = keys);
|
|
36
|
+
};
|
|
37
|
+
// Every call spelled as a member call, by key, so a method's surplus
|
|
38
|
+
// arguments are found without rescanning the program per method.
|
|
39
|
+
let memberCalls;
|
|
40
|
+
const memberCallsOf = (key) => {
|
|
41
|
+
if (!memberCalls) {
|
|
42
|
+
const byKey = new Map();
|
|
43
|
+
for (const site of flow?.calls ?? []) {
|
|
44
|
+
const call = site.call;
|
|
45
|
+
if (!ts.isCallExpression(call))
|
|
46
|
+
continue;
|
|
47
|
+
const callee = call.expression;
|
|
48
|
+
if (!ts.isPropertyAccessExpression(callee) && !ts.isElementAccessExpression(callee))
|
|
49
|
+
continue;
|
|
50
|
+
const name = keyOf(callee);
|
|
51
|
+
if (name === null)
|
|
52
|
+
continue;
|
|
53
|
+
const list = byKey.get(name) ?? [];
|
|
54
|
+
list.push(call);
|
|
55
|
+
byKey.set(name, list);
|
|
56
|
+
}
|
|
57
|
+
memberCalls = byKey;
|
|
58
|
+
}
|
|
59
|
+
return memberCalls.get(key) ?? [];
|
|
60
|
+
};
|
|
61
|
+
/** The most arguments any call of this method passes, or null when one spreads them. */
|
|
62
|
+
const suppliedArity = (symbol) => {
|
|
63
|
+
let widest = 0;
|
|
64
|
+
for (const call of memberCallsOf(symbol.name)) {
|
|
65
|
+
const callee = call.expression;
|
|
66
|
+
// A property read can resolve to a transient (instantiated) symbol of the same declaration.
|
|
67
|
+
const resolved = memberSymbolOf(callee, symbol.name);
|
|
68
|
+
if (resolved !== symbol && !resolved?.declarations?.some((declaration) => symbol.declarations?.includes(declaration)))
|
|
69
|
+
continue;
|
|
70
|
+
if (call.arguments.some(ts.isSpreadElement))
|
|
71
|
+
return null;
|
|
72
|
+
widest = Math.max(widest, call.arguments.length);
|
|
73
|
+
}
|
|
74
|
+
return widest;
|
|
75
|
+
};
|
|
12
76
|
const resolve = (symbol) => {
|
|
13
77
|
if (cache.has(symbol))
|
|
14
78
|
return cache.get(symbol) ?? null;
|
|
@@ -30,7 +94,8 @@ export const createMutableMethodResolver = (checker, table, flow, signatureOf, r
|
|
|
30
94
|
// and counting them re-translated a generic class's open body signature
|
|
31
95
|
// outside every copy.
|
|
32
96
|
const replacements = [...writes].filter((write) => (write.slot === 'whole' || write.slot === 'member') && write.edge !== 'return' && write.edge !== 'yield');
|
|
33
|
-
|
|
97
|
+
const replaced = replacements.some((write) => write.value !== null);
|
|
98
|
+
if (!replaced && !untypedWriteKeys().has(symbol.name))
|
|
34
99
|
return null;
|
|
35
100
|
pending.add(symbol);
|
|
36
101
|
try {
|
|
@@ -54,11 +119,32 @@ export const createMutableMethodResolver = (checker, table, flow, signatureOf, r
|
|
|
54
119
|
}
|
|
55
120
|
if (!signatures.length)
|
|
56
121
|
return null;
|
|
57
|
-
const
|
|
122
|
+
const longest = signatures.reduce((held, next) => (next.parameters.length > held.parameters.length ? next : held));
|
|
58
123
|
// Rest tails have independent positional semantics; never manufacture a
|
|
59
124
|
// fixed frame by truncating one. Equal frames need no new authority.
|
|
60
125
|
if (signatures.some((signature) => signature.parameters.some((parameter) => parameter.rest)))
|
|
61
126
|
return null;
|
|
127
|
+
// A call passes every argument it spells (ECMA-262 13.3.8.1), and the
|
|
128
|
+
// function the slot holds by then is whichever replacement was stored,
|
|
129
|
+
// which may bind more parameters than the declared body does. A frame
|
|
130
|
+
// narrower than the widest call drops the surplus before the stored
|
|
131
|
+
// function can bind it, so the frame carries it as an optional `any`.
|
|
132
|
+
const supplied = suppliedArity(symbol);
|
|
133
|
+
if (supplied === null)
|
|
134
|
+
return null;
|
|
135
|
+
const anyType = table.intern({ kind: 'primitive', primitive: 'any' });
|
|
136
|
+
const surplus = Array.from({ length: Math.max(0, supplied - longest.parameters.length) }, () => ({
|
|
137
|
+
type: anyType,
|
|
138
|
+
slot: anyType,
|
|
139
|
+
optional: true,
|
|
140
|
+
rest: false,
|
|
141
|
+
hasInitializer: false
|
|
142
|
+
}));
|
|
143
|
+
if (surplus.length === 0 && !replaced)
|
|
144
|
+
return null;
|
|
145
|
+
const widest = surplus.length === 0 ? longest : { ...longest, parameters: [...longest.parameters, ...surplus] };
|
|
146
|
+
if (surplus.length > 0)
|
|
147
|
+
signatures.push(widest);
|
|
62
148
|
const join = (values) => {
|
|
63
149
|
const members = [...new Set(values)];
|
|
64
150
|
return members.length === 1 ? members[0] : table.intern({ kind: 'union', members });
|
|
@@ -628,14 +628,19 @@ export const createStructuralParts = (input) => {
|
|
|
628
628
|
// `IteratorResult`. An answer equal to the node's own declared type added
|
|
629
629
|
// nothing, so the checker's instantiated answer stands.
|
|
630
630
|
const censused = needsCensus && censusNode ? input.layoutTypeAt(censusNode) : null;
|
|
631
|
-
// A JS assignment declaration (`this.x = k * 2`) is its own first write,
|
|
632
|
-
//
|
|
633
|
-
//
|
|
634
|
-
//
|
|
635
|
-
//
|
|
636
|
-
//
|
|
637
|
-
|
|
638
|
-
const
|
|
631
|
+
// A JS assignment declaration (`this.x = k * 2`) is its own first write,
|
|
632
|
+
// and an answer there that only echoes its right-hand side says nothing
|
|
633
|
+
// about the field's other writes: a constructor's `this.shaku = null` typed
|
|
634
|
+
// the field `null` whatever a later `this.shaku = index.shakuhachi` stored.
|
|
635
|
+
// The field is the LEFT side, where `field-bindings.ts` joins every write
|
|
636
|
+
// (a typed `k * 2` beside an `any` write still binds `number` there) or
|
|
637
|
+
// answers nothing, leaving the checker's `any`.
|
|
638
|
+
const assignedField = censusNode !== null && ts.isBinaryExpression(censusNode) && censused !== null && censused === checker.getTypeAtLocation(censusNode)
|
|
639
|
+
? censusNode.left
|
|
640
|
+
: null;
|
|
641
|
+
const censusCell = assignedField ?? censusNode;
|
|
642
|
+
const cellAnswer = assignedField ? input.layoutTypeAt(assignedField) : censused;
|
|
643
|
+
const fromCensus = cellAnswer !== null && censusCell && cellAnswer === checker.getTypeAtLocation(censusCell) ? null : cellAnswer;
|
|
639
644
|
// Which of the three sources actually answered one named member. A record
|
|
640
645
|
// that carries ONE dynamic field among 130 gives the reader no way to tell
|
|
641
646
|
// "the checker was fine" from "the census had nothing to add".
|
|
@@ -42,7 +42,7 @@ import { indexedAccessMemberTypes } from './structural-indexed-access.js';
|
|
|
42
42
|
import { joinedCallableOf } from './structural-joins.js';
|
|
43
43
|
import { censusFreshDictionaryStorage, isNullPrototypeCreate, dictionaryArmIndexOf } from './fresh-dictionary-storage.js';
|
|
44
44
|
import { creationOrderOf, creationOrderedProperties } from './structural-creation-order.js';
|
|
45
|
-
import { collectionMemberResultTypeAt, contextualArrayConstructTypeAt, inferredArrayElementAt, statedCollectionTypeAt, inferredCollectionTypeArgumentsAt, unstatedNeverArray } from './structural-array-element.js';
|
|
45
|
+
import { collectionMemberResultTypeAt, contextualArrayConstructTypeAt, inferredArrayElementAt, statedCollectionTypeAt, inferredCollectionTypeArgumentsAt, readsUnjoinedArrayMember, unstatedNeverArray } from './structural-array-element.js';
|
|
46
46
|
import { createDeclaredBodyResolver } from './structural-declared-body.js';
|
|
47
47
|
import { emptyInstantiationCensus } from './instantiation.js';
|
|
48
48
|
import { emptySpecializationCensus } from './specialization.js';
|
|
@@ -1250,6 +1250,30 @@ const structuralRules = [
|
|
|
1250
1250
|
return null;
|
|
1251
1251
|
}
|
|
1252
1252
|
},
|
|
1253
|
+
{
|
|
1254
|
+
// The same box, read back through a computed key: each `never[]` arm the
|
|
1255
|
+
// checker answers is a member stored as the box.
|
|
1256
|
+
name: 'computed-read-of-unjoined-array-member',
|
|
1257
|
+
forms: [ts.SyntaxKind.ElementAccessExpression],
|
|
1258
|
+
resolve(node) {
|
|
1259
|
+
if (!ts.isElementAccessExpression(node))
|
|
1260
|
+
return null;
|
|
1261
|
+
const read = this.layoutTypeAt(node);
|
|
1262
|
+
const arms = read.isUnion() ? read.types : [read];
|
|
1263
|
+
const isNeverArray = (arm) => this.checker.isArrayType(arm) &&
|
|
1264
|
+
((this.checker.getTypeArguments(arm)[0]?.flags ?? 0) & ts.TypeFlags.Never) !== 0;
|
|
1265
|
+
if (!arms.some(isNeverArray) || !readsUnjoinedArrayMember(this.checker, this.collections, this.layoutTypeAt, node))
|
|
1266
|
+
return null;
|
|
1267
|
+
const box = this.table.intern({
|
|
1268
|
+
kind: 'array',
|
|
1269
|
+
element: this.table.intern({ kind: 'primitive', primitive: 'any' }),
|
|
1270
|
+
readonly: false,
|
|
1271
|
+
extension: []
|
|
1272
|
+
});
|
|
1273
|
+
const members = [...new Set(arms.map((arm) => (isNeverArray(arm) ? box : this.typeOf(arm))))];
|
|
1274
|
+
return members.length === 1 ? members[0] : this.table.intern({ kind: 'union', members });
|
|
1275
|
+
}
|
|
1276
|
+
},
|
|
1253
1277
|
{
|
|
1254
1278
|
// The K/(V) a bare `new Map()`/`new Set()`/`new WeakMap()`/`new
|
|
1255
1279
|
// WeakSet()` never states -- `collection-bindings.ts` has bound it since
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FunctionId, IrValueId } from '../../identity/ids.js';
|
|
2
2
|
import { type PrivateBorrowCell } from '../../ir/borrowed-call-arguments.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type IrBody, type IrOperand } from '../../ir/model.js';
|
|
4
4
|
import { type CallableAbi } from '../../representation/model.js';
|
|
5
5
|
/** The original body name remains an owning entry wrapper. This additional
|
|
6
6
|
* entry is internal and may be selected only with stable-actual evidence.
|
|
@@ -10,12 +10,20 @@ export interface StableBorrowEntry {
|
|
|
10
10
|
readonly name: string;
|
|
11
11
|
readonly abi: CallableAbi;
|
|
12
12
|
readonly formals: ReadonlySet<number>;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the body's declared signature narrows an integer formal or its
|
|
15
|
+
* result. The entry then spells those narrowed types exactly as the owning
|
|
16
|
+
* entry does, so a direct call reaches either with the same arguments; a
|
|
17
|
+
* carrier-level adapter (`callKnownBorrowed`) passes the unnarrowed ABI and
|
|
18
|
+
* must keep the thunk, which converts at that boundary.
|
|
19
|
+
*/
|
|
20
|
+
readonly narrowedNumericAbi: boolean;
|
|
13
21
|
}
|
|
14
22
|
export declare const stableBorrowEntryOf: (body: IrBody, owner: FunctionId, privateCell: PrivateBorrowCell, originalBorrowed: ReadonlySet<number>, dyingArguments: ReadonlySet<IrValueId>, admission: {
|
|
15
23
|
readonly captureFree: boolean;
|
|
16
24
|
readonly synchronous: boolean;
|
|
17
25
|
readonly singleBody: boolean;
|
|
18
|
-
readonly
|
|
26
|
+
readonly narrowedNumericAbi: boolean;
|
|
19
27
|
}) => StableBorrowEntry | null;
|
|
20
28
|
/** A private caller slot survives arbitrary program re-entry. All extra
|
|
21
29
|
* reference formals must bind such slots; otherwise use the existing owning
|
|
@@ -28,3 +36,34 @@ export declare const stableBorrowEntryOf: (body: IrBody, owner: FunctionId, priv
|
|
|
28
36
|
* Scalars cannot move a string/handle slot. Binding a borrowed formal does
|
|
29
37
|
* not itself move from its argument. */
|
|
30
38
|
export declare const stableBorrowEntryAccepts: (entry: StableBorrowEntry, actuals: readonly IrOperand[], stable: ReadonlySet<IrValueId>, dyingArguments: ReadonlySet<IrValueId>) => boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The borrowed positions a call copies into a temporary of the formal's own
|
|
41
|
+
* carrier so that it can still enter the borrowed entry, or null when the
|
|
42
|
+
* entry is refused.
|
|
43
|
+
*
|
|
44
|
+
* A reference formal bound to a temporary the call itself made is as private
|
|
45
|
+
* as a caller-owned local: nothing else can name it, and it lives until the end
|
|
46
|
+
* of the full-expression, past the callee's return. So an actual that is not a
|
|
47
|
+
* stable slot -- a field or element read the printer may withhold as a
|
|
48
|
+
* reference into mutable storage, or a value converted on the way in -- is
|
|
49
|
+
* copied by itself, which is exactly the copy the owning entry's by-value
|
|
50
|
+
* formal made. Refusing the whole entry for it sent every other argument of
|
|
51
|
+
* the call through by-value formals too: one union read from a field cost a
|
|
52
|
+
* copy and release of each handle beside it, and a move of each local.
|
|
53
|
+
*
|
|
54
|
+
* Mixed move/borrow evaluation is still refused, for `stableBorrowEntryAccepts`'s
|
|
55
|
+
* reason: an owning sibling's `std::move` may be evaluated before a copy or a
|
|
56
|
+
* reference of the same slot is taken.
|
|
57
|
+
*/
|
|
58
|
+
export declare const stableBorrowEntryCopies: (entry: StableBorrowEntry, actuals: readonly IrOperand[], stable: ReadonlySet<IrValueId>, dyingArguments: ReadonlySet<IrValueId>) => ReadonlySet<number> | null;
|
|
59
|
+
/**
|
|
60
|
+
* Dying argument reads a call hands to a position its callee's borrowed entry
|
|
61
|
+
* takes by reference -- a direct call's, or every arm's of a union dispatch: the entry binds them in place, so they move
|
|
62
|
+
* nothing. Only a call that will enter the entry counts -- one where no other
|
|
63
|
+
* position moves a handle (`stableBorrowEntryCopies`' refusal) -- and only an
|
|
64
|
+
* argument already carried as the formal, since a conversion builds a
|
|
65
|
+
* temporary of its own and the move feeds that.
|
|
66
|
+
*/
|
|
67
|
+
export declare const borrowForwardedArgumentsOf: (bodies: readonly IrBody[], entries: ReadonlyMap<string, StableBorrowEntry>, dyingArguments: ReadonlySet<IrValueId>) => ReadonlySet<IrValueId>;
|
|
68
|
+
/** `dying` without `released`, keeping the sunk stores of the reads that remain. */
|
|
69
|
+
export declare const withoutDyingArguments: (dying: ReadonlySet<IrValueId>, released: ReadonlySet<IrValueId>) => ReadonlySet<IrValueId>;
|