@geastack/compiler 1.0.41 → 1.0.43
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/conversion/nodes.js +5 -2
- package/dist/ir/certify.js +1 -1
- package/dist/ir/facts.d.ts +3 -1
- package/dist/ir/facts.js +1 -0
- package/dist/ir/host-template-conversions.d.ts +2 -2
- package/dist/ir/host-template-conversions.js +73 -2
- package/dist/ir/integers.d.ts +6 -0
- package/dist/ir/integers.js +133 -0
- package/dist/ir/lower-destructuring.js +22 -3
- package/dist/ir/lower-operands.js +24 -0
- 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/projection/dispatch.d.ts +19 -1
- package/dist/projection/dispatch.js +34 -0
- package/dist/representation/value-records.js +182 -13
- 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/source-value-session.d.ts +9 -2
- package/dist/semantics/normalize/flow/source-value-session.js +538 -94
- package/dist/semantics/normalize/local-bindings.js +23 -1
- package/dist/semantics/normalize/producers/allocations.js +5 -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-parts.js +13 -8
- package/dist/semantics/normalize/structural.js +25 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.js +5 -1
- package/dist/targets/cpp/emit-callable.js +19 -10
- package/dist/targets/cpp/emit-context.d.ts +3 -0
- package/dist/targets/cpp/emit-context.js +3 -0
- 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/emit.js +7 -1
- package/dist/targets/cpp/host/emit-host-invoke.js +16 -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.js +39 -16
- package/dist/targets/cpp/translation-unit.js +23 -2
- package/package.json +1 -1
- package/src/targets/cpp/runtime/gea_dynamic_proxy.h +17 -1
- package/src/targets/cpp/runtime/gea_runtime.h +312 -51
|
@@ -243,8 +243,23 @@ const callableChildrenOf = (abi) => [
|
|
|
243
243
|
* the call operation accounts for their exposure. Decoding an argument into
|
|
244
244
|
* a native frame does not publish that frame's fields back to dynamic code.
|
|
245
245
|
* Keep the full type inventory in directChildrenOf for candidate discovery.
|
|
246
|
+
*
|
|
247
|
+
* A callable parameter is the exception: a dynamic caller passes its own
|
|
248
|
+
* function there, and decoding it installs the adapter that boxes that
|
|
249
|
+
* parameter's inputs out to it (`DynamicCarrier<CallableObject>`), so those
|
|
250
|
+
* inputs are published exactly as a `convert` to the parameter's convention
|
|
251
|
+
* publishes them. Sakura's untyped `dom.addEventListener('pointerdown', (e) =>
|
|
252
|
+
* e.button)` reaches a typed `HostListener` slot that way, and its event
|
|
253
|
+
* class had no field protocol for the listener's read.
|
|
246
254
|
*/
|
|
247
255
|
const publishedChildrenOf = (representation, classes, deriver) => {
|
|
256
|
+
const withCallbackInputs = (abi) => [
|
|
257
|
+
abi.result,
|
|
258
|
+
...abi.parameters.flatMap((parameter) => {
|
|
259
|
+
const callback = unwrappedCallableAbi(parameter.value);
|
|
260
|
+
return callback === null ? [] : callableAdapterInputsOf(null, callback);
|
|
261
|
+
})
|
|
262
|
+
];
|
|
248
263
|
switch (representation.kind) {
|
|
249
264
|
case 'function':
|
|
250
265
|
case 'function-family':
|
|
@@ -252,11 +267,11 @@ const publishedChildrenOf = (representation, classes, deriver) => {
|
|
|
252
267
|
case 'constructor-value-dispatch':
|
|
253
268
|
case 'function-value-dispatch':
|
|
254
269
|
case 'function-value-family':
|
|
255
|
-
return
|
|
270
|
+
return withCallbackInputs(representation.abi);
|
|
256
271
|
case 'function-and-constructor':
|
|
257
|
-
return [representation.call
|
|
272
|
+
return [...withCallbackInputs(representation.call), ...withCallbackInputs(representation.construct)];
|
|
258
273
|
case 'native-handle':
|
|
259
|
-
return [representation.call, representation.construct].flatMap((abi) => (abi ?
|
|
274
|
+
return [representation.call, representation.construct].flatMap((abi) => (abi ? withCallbackInputs(abi) : []));
|
|
260
275
|
case 'class-ref': {
|
|
261
276
|
// A `#private` element is reachable only from the class's own body,
|
|
262
277
|
// never by dynamic code holding the instance: the reflected protocol
|
|
@@ -1893,6 +1908,13 @@ export const reflectionExposureOf = (bodies, classes, deriver, options) => {
|
|
|
1893
1908
|
}
|
|
1894
1909
|
for (const operation of operations) {
|
|
1895
1910
|
currentOperation = operation;
|
|
1911
|
+
// A callback the operation hands a value of its own (`map`'s element,
|
|
1912
|
+
// `sort`'s pair) takes it boxed when its parameter is `any`. The box is
|
|
1913
|
+
// made in the printed adapter or in the runtime helper, never by a
|
|
1914
|
+
// `convert`, so the published recipe is the only boundary there is to see.
|
|
1915
|
+
for (const recipe of operation.conversionRecipes ?? [])
|
|
1916
|
+
if (recipe.role === 'prototype-callback' && recipe.target.kind === 'dynamic')
|
|
1917
|
+
promoteLogicalReceiver(recipe.source, 'prototype-callback-to-dynamic');
|
|
1896
1918
|
if (operation.kind === 'get-iterator' && operation.nativeNextMethodRead)
|
|
1897
1919
|
promoteIteratorRead(operation.result.representation, operation.nativeNextMethodRead, operation);
|
|
1898
1920
|
if ((operation.kind === 'iterator-next' || operation.kind === 'iterator-close') && operation.nativeMethodRead)
|
|
@@ -2396,6 +2418,10 @@ export const reflectionExposureOf = (bodies, classes, deriver, options) => {
|
|
|
2396
2418
|
else if (representationKey(into.value) !== representationKey(field.value))
|
|
2397
2419
|
promoteFull(field.value, 'spread-converted-field');
|
|
2398
2420
|
}
|
|
2421
|
+
// A live view's slots are inert: the runtime copies a view source by
|
|
2422
|
+
// walking its original's own keys (`copiesThroughNativeView`), never
|
|
2423
|
+
// through the static copy, so that original must list them.
|
|
2424
|
+
demandEnumeratedViewOrigins(operation.source.representation, operation);
|
|
2399
2425
|
continue;
|
|
2400
2426
|
}
|
|
2401
2427
|
promoteFull(operation.source.representation, 'dynamic-spread-source');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DeclarationId, FunctionId } from '../identity/ids.js';
|
|
2
|
-
import type { ClassField, ClassLayout, ClassMethod } from './classes.js';
|
|
2
|
+
import type { ClassAccessor, ClassField, ClassLayout, ClassMethod } from './classes.js';
|
|
3
3
|
import type { ConversionCensus } from '../conversion/nodes.js';
|
|
4
4
|
import type { CallableAbi, Representation } from '../representation/model.js';
|
|
5
5
|
/** Exact allocation identities and the method each prototype lookup selects.
|
|
@@ -14,6 +14,24 @@ export declare const classPrototypeMethodValueArmsOf: (classes: ReadonlyMap<Decl
|
|
|
14
14
|
/** The class that declares `method`; `null` exactly when `method` is. */
|
|
15
15
|
readonly owner: DeclarationId | null;
|
|
16
16
|
}[] | null;
|
|
17
|
+
/** The exact allocations below `receiver` whose lookup of `key` reaches a
|
|
18
|
+
* descendant's accessor although `receiver` itself finds a data field: three's
|
|
19
|
+
* `Material.clearcoat`, a field its `fromJSON` assigns, which
|
|
20
|
+
* `MeshPhysicalMaterial` redeclares as a getter/setter pair. An instance of
|
|
21
|
+
* such an allocation has no own data property under the key -- every base
|
|
22
|
+
* write reaches the setter -- so a base-typed read must call the getter.
|
|
23
|
+
* Empty when `receiver` does not find a field or nothing below redeclares it.
|
|
24
|
+
*/
|
|
25
|
+
export declare const classFieldAccessorArmsOf: (classes: ReadonlyMap<DeclarationId, ClassLayout>, receiver: DeclarationId, key: string) => readonly {
|
|
26
|
+
readonly allocation: DeclarationId;
|
|
27
|
+
readonly owner: DeclarationId;
|
|
28
|
+
readonly accessor: ClassAccessor;
|
|
29
|
+
}[];
|
|
30
|
+
/** The keys `declaration`'s own accessors redeclare over a data field its
|
|
31
|
+
* bases find -- the reflected half of `classFieldAccessorArmsOf`, asked by
|
|
32
|
+
* the class whose own-property hooks must stop answering from the base slot.
|
|
33
|
+
*/
|
|
34
|
+
export declare const classAccessorShadowedFieldKeysOf: (classes: ReadonlyMap<DeclarationId, ClassLayout>, declaration: DeclarationId) => readonly string[];
|
|
17
35
|
/** All prototype keys reachable through this native family, including keys
|
|
18
36
|
* introduced below the static receiver and inherited above it.
|
|
19
37
|
*/
|
|
@@ -25,6 +25,40 @@ export const classPrototypeMethodValueArmsOf = (classes, receiver, key) => {
|
|
|
25
25
|
}
|
|
26
26
|
return arms.length === 0 ? null : arms;
|
|
27
27
|
};
|
|
28
|
+
/** The exact allocations below `receiver` whose lookup of `key` reaches a
|
|
29
|
+
* descendant's accessor although `receiver` itself finds a data field: three's
|
|
30
|
+
* `Material.clearcoat`, a field its `fromJSON` assigns, which
|
|
31
|
+
* `MeshPhysicalMaterial` redeclares as a getter/setter pair. An instance of
|
|
32
|
+
* such an allocation has no own data property under the key -- every base
|
|
33
|
+
* write reaches the setter -- so a base-typed read must call the getter.
|
|
34
|
+
* Empty when `receiver` does not find a field or nothing below redeclares it.
|
|
35
|
+
*/
|
|
36
|
+
export const classFieldAccessorArmsOf = (classes, receiver, key) => {
|
|
37
|
+
if (classMemberOf(classes, receiver, key)?.kind !== 'field')
|
|
38
|
+
return [];
|
|
39
|
+
const arms = [];
|
|
40
|
+
for (const [allocation, layout] of classes) {
|
|
41
|
+
if (!extendsClass(classes, allocation, receiver))
|
|
42
|
+
continue;
|
|
43
|
+
if (layout.uninstantiable === true || layout.allocationAbsent === true)
|
|
44
|
+
continue;
|
|
45
|
+
const site = classMemberOf(classes, allocation, key);
|
|
46
|
+
if (site?.kind === 'accessor')
|
|
47
|
+
arms.push({ allocation, owner: site.owner, accessor: site.accessor });
|
|
48
|
+
}
|
|
49
|
+
return arms;
|
|
50
|
+
};
|
|
51
|
+
/** The keys `declaration`'s own accessors redeclare over a data field its
|
|
52
|
+
* bases find -- the reflected half of `classFieldAccessorArmsOf`, asked by
|
|
53
|
+
* the class whose own-property hooks must stop answering from the base slot.
|
|
54
|
+
*/
|
|
55
|
+
export const classAccessorShadowedFieldKeysOf = (classes, declaration) => {
|
|
56
|
+
const layout = classes.get(declaration);
|
|
57
|
+
const base = layout?.base ?? null;
|
|
58
|
+
if (!layout || base === null)
|
|
59
|
+
return [];
|
|
60
|
+
return layout.accessors.filter((accessor) => classMemberOf(classes, base, accessor.key)?.kind === 'field').map((accessor) => accessor.key);
|
|
61
|
+
};
|
|
28
62
|
/** All prototype keys reachable through this native family, including keys
|
|
29
63
|
* introduced below the static receiver and inherited above it.
|
|
30
64
|
*/
|
|
@@ -61,6 +61,59 @@ const typeArgumentsOf = (graph, id) => {
|
|
|
61
61
|
return new Set(shape.typeArguments);
|
|
62
62
|
return new Set();
|
|
63
63
|
};
|
|
64
|
+
/** `any`/`unknown`: the one view no later operation on it can attribute to a record type. */
|
|
65
|
+
const isDynamic = (graph, id) => {
|
|
66
|
+
const shape = graph.structuralTypes.get(id)?.shape;
|
|
67
|
+
return shape?.kind === 'primitive' && (shape.primitive === 'any' || shape.primitive === 'unknown');
|
|
68
|
+
};
|
|
69
|
+
/** The layout a named type stands for. */
|
|
70
|
+
const bodyOf = (graph, id) => {
|
|
71
|
+
const shape = graph.structuralTypes.get(id)?.shape;
|
|
72
|
+
if ((shape?.kind === 'declared' || shape?.kind === 'class-instance') && shape.body !== null)
|
|
73
|
+
return bodyOf(graph, shape.body);
|
|
74
|
+
return shape?.kind === 'object-anchor' ? bodyOf(graph, shape.body) : id;
|
|
75
|
+
};
|
|
76
|
+
/** The type an argument at `ordinal` binds to, a rest parameter's element included. */
|
|
77
|
+
const parameterTypeAt = (graph, parameters, ordinal) => {
|
|
78
|
+
const last = parameters[parameters.length - 1];
|
|
79
|
+
if (!last?.rest || ordinal < parameters.length - 1)
|
|
80
|
+
return parameters[ordinal]?.type;
|
|
81
|
+
const rest = graph.structuralTypes.get(bodyOf(graph, last.type))?.shape;
|
|
82
|
+
return rest?.kind === 'array' ? rest.element : undefined;
|
|
83
|
+
};
|
|
84
|
+
const sameKey = (left, right) => left.kind === 'symbol'
|
|
85
|
+
? right.kind === 'symbol' && right.declaration === left.declaration
|
|
86
|
+
: right.kind !== 'symbol' && right.kind === left.kind && right.value === left.value;
|
|
87
|
+
/** The cores of a type that can hold an object, as `objectCoresOf` finds them. */
|
|
88
|
+
const objectHoldersOf = (graph, id) => {
|
|
89
|
+
const cores = new Set();
|
|
90
|
+
objectCoresOf(graph, id, cores);
|
|
91
|
+
const scalar = new Set(['primitive', 'literal', 'unique-symbol', 'union', 'intersection']);
|
|
92
|
+
return [...cores].filter((core) => {
|
|
93
|
+
const shape = graph.structuralTypes.get(core)?.shape;
|
|
94
|
+
return shape !== undefined && !scalar.has(shape.kind);
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
/** The receiver's own declared view of the slot a store under `key` lands in (`null`: a computed key). */
|
|
98
|
+
const slotTypesOf = (graph, receiver, key) => {
|
|
99
|
+
if (isDynamic(graph, receiver))
|
|
100
|
+
return [receiver];
|
|
101
|
+
const slots = [];
|
|
102
|
+
for (const core of objectHoldersOf(graph, receiver)) {
|
|
103
|
+
const shape = graph.structuralTypes.get(core)?.shape;
|
|
104
|
+
if (shape?.kind === 'array')
|
|
105
|
+
slots.push(shape.element);
|
|
106
|
+
if (shape?.kind !== 'object')
|
|
107
|
+
continue;
|
|
108
|
+
const member = shape.members.find((candidate) => candidate.key.kind === 'string' && candidate.key.value === key);
|
|
109
|
+
if (member)
|
|
110
|
+
slots.push(member.type);
|
|
111
|
+
else
|
|
112
|
+
for (const index of shape.index)
|
|
113
|
+
slots.push(index.value);
|
|
114
|
+
}
|
|
115
|
+
return slots;
|
|
116
|
+
};
|
|
64
117
|
/** Object shapes reachable from a type that a mutation or an identity test named. */
|
|
65
118
|
const objectCoresOf = (graph, id, into) => {
|
|
66
119
|
if (into.has(id))
|
|
@@ -251,7 +304,115 @@ export const valueRecordTypesOf = (graph) => {
|
|
|
251
304
|
disqualifyParameter(parameter.type);
|
|
252
305
|
}
|
|
253
306
|
};
|
|
307
|
+
// A write or identity test made through an `any`/`unknown` view names no
|
|
308
|
+
// record type, so the type-keyed proof above cannot see it. Everything a
|
|
309
|
+
// value carries BY VALUE leaves with it: a dynamic read of a by-value field
|
|
310
|
+
// boxes a copy, so `view.inner.t = 2` would land in that copy. A worklist,
|
|
311
|
+
// not recursion: an app's object graph nests deeper than the stack.
|
|
312
|
+
const exposed = new Set();
|
|
313
|
+
const exposeToDynamic = (id) => {
|
|
314
|
+
const pending = [id];
|
|
315
|
+
for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
|
|
316
|
+
if (exposed.has(next))
|
|
317
|
+
continue;
|
|
318
|
+
exposed.add(next);
|
|
319
|
+
disqualifyCallable(next);
|
|
320
|
+
const cores = new Set();
|
|
321
|
+
objectCoresOf(graph, next, cores);
|
|
322
|
+
for (const core of cores) {
|
|
323
|
+
disqualified.add(core);
|
|
324
|
+
const shape = graph.structuralTypes.get(core)?.shape;
|
|
325
|
+
if (shape?.kind === 'object')
|
|
326
|
+
for (const member of shape.members)
|
|
327
|
+
pending.push(member.type);
|
|
328
|
+
pending.push(...typeArgumentsOf(graph, core));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
// A value of type `source` stored where the program's view of it is
|
|
333
|
+
// `destination` -- a parameter, a field, a callback's parameter. The proof
|
|
334
|
+
// keys every write and identity test by the type at that site, so the two
|
|
335
|
+
// must be one alias class, as a binding's own views are; a dynamic view
|
|
336
|
+
// escapes the proof outright. The walk follows fields, elements and
|
|
337
|
+
// callable parameters, which hold the same objects under their own types.
|
|
338
|
+
// A host's own declared type (`join` false) is no view the program writes
|
|
339
|
+
// through, and the call already disqualified what it was handed; only its
|
|
340
|
+
// dynamic slots and the program callbacks it calls back are walked.
|
|
341
|
+
const entered = new Set();
|
|
342
|
+
const entersView = (source, destination, join = true) => {
|
|
343
|
+
const edge = `${join ? '' : 'host '}${source}>${destination}`;
|
|
344
|
+
if (source === destination || entered.has(edge))
|
|
345
|
+
return;
|
|
346
|
+
entered.add(edge);
|
|
347
|
+
const held = objectHoldersOf(graph, source);
|
|
348
|
+
if (held.length === 0)
|
|
349
|
+
return;
|
|
350
|
+
if (isDynamic(graph, destination))
|
|
351
|
+
return exposeToDynamic(source);
|
|
352
|
+
// Only the object-shaped cores join: an alias through a shared primitive
|
|
353
|
+
// id would let any comparison against that primitive disqualify both.
|
|
354
|
+
if (join)
|
|
355
|
+
connect([...held, ...objectHoldersOf(graph, destination)]);
|
|
356
|
+
const from = graph.structuralTypes.get(bodyOf(graph, source))?.shape;
|
|
357
|
+
const to = graph.structuralTypes.get(bodyOf(graph, destination))?.shape;
|
|
358
|
+
if (from?.kind === 'array' && to?.kind === 'array')
|
|
359
|
+
entersView(from.element, to.element, join);
|
|
360
|
+
if (from?.kind === 'object' && to?.kind === 'object')
|
|
361
|
+
for (const member of from.members) {
|
|
362
|
+
const slot = to.members.find((candidate) => sameKey(candidate.key, member.key));
|
|
363
|
+
if (slot)
|
|
364
|
+
entersView(member.type, slot.type, join);
|
|
365
|
+
}
|
|
366
|
+
const [fromCall] = signatureShapesOf(source);
|
|
367
|
+
const [toCall] = signatureShapesOf(destination);
|
|
368
|
+
if (!fromCall || !toCall)
|
|
369
|
+
return;
|
|
370
|
+
// A callback's parameters receive what its caller passes, so values flow
|
|
371
|
+
// from the destination's parameters into the source's.
|
|
372
|
+
fromCall.parameters.forEach((parameter, ordinal) => {
|
|
373
|
+
const passed = parameterTypeAt(graph, toCall.parameters, ordinal);
|
|
374
|
+
if (passed !== undefined && !parameter.rest)
|
|
375
|
+
entersView(passed, parameter.type);
|
|
376
|
+
});
|
|
377
|
+
entersView(fromCall.result, toCall.result, join);
|
|
378
|
+
};
|
|
379
|
+
// Where an invocation's argument lands: the callee's own type at the call
|
|
380
|
+
// site is instantiated, while a selected generic signature may still name
|
|
381
|
+
// its type parameters, and joining a type parameter would alias every
|
|
382
|
+
// record it is ever filled with. That fallback only answers whether the
|
|
383
|
+
// parameter is dynamic, which no instantiation changes.
|
|
384
|
+
const enterArguments = (operation) => {
|
|
385
|
+
const callee = operation.operands.find((operand) => operand.role === 'callee');
|
|
386
|
+
const calleeSignatures = callee ? signatureShapesOf(callee.type) : [];
|
|
387
|
+
const exact = calleeSignatures.length === 1 ? calleeSignatures[0].parameters : null;
|
|
388
|
+
const join = operation.selectedSignature?.provenance !== 'ambient';
|
|
389
|
+
for (const operand of operation.operands) {
|
|
390
|
+
if (operand.role !== 'argument')
|
|
391
|
+
continue;
|
|
392
|
+
const destination = exact ? parameterTypeAt(graph, exact, operand.ordinal) : undefined;
|
|
393
|
+
if (destination !== undefined)
|
|
394
|
+
entersView(operand.type, destination, join);
|
|
395
|
+
else {
|
|
396
|
+
const declared = operation.selectedSignature
|
|
397
|
+
? parameterTypeAt(graph, operation.selectedSignature.parameters, operand.ordinal)
|
|
398
|
+
: undefined;
|
|
399
|
+
if (declared !== undefined && isDynamic(graph, declared))
|
|
400
|
+
exposeToDynamic(operand.type);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
};
|
|
254
404
|
for (const operation of graph.operations.values()) {
|
|
405
|
+
// An erased assertion (`list as any[]`) hands a typed result to an operand
|
|
406
|
+
// whose own type is dynamic, with no operation in between to compare.
|
|
407
|
+
for (const operand of operation.operands) {
|
|
408
|
+
const source = operand.source;
|
|
409
|
+
if (source.kind !== 'result' || !isDynamic(graph, operand.type))
|
|
410
|
+
continue;
|
|
411
|
+
const producer = graph.results.get(source.result);
|
|
412
|
+
const produced = producer === undefined ? undefined : graph.operations.get(producer)?.results.find((result) => result.id === source.result);
|
|
413
|
+
if (produced)
|
|
414
|
+
entersView(produced.type, operand.type);
|
|
415
|
+
}
|
|
255
416
|
// A `VariableDeclaration` with an initializer is the one binding shape
|
|
256
417
|
// whose operand and result can carry two DIFFERENT types: `initializer`
|
|
257
418
|
// reads `typeAt(initializer)`, the value's own concrete type, while the
|
|
@@ -260,16 +421,18 @@ export const valueRecordTypesOf = (graph) => {
|
|
|
260
421
|
// binding shape (a plain parameter, a destructured element, a plain `x =
|
|
261
422
|
// expr` write) reuses ONE type for both, so this never fires for them.
|
|
262
423
|
//
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
//
|
|
424
|
+
// Only a RESULT resolving to `any`/`unknown` disqualifies, not the two
|
|
425
|
+
// types merely differing: an ordinary typed widening (`let n: number = 5
|
|
426
|
+
// as const`, a literal into its declared interface where
|
|
266
427
|
// `recordStorageFamilies` did not happen to connect the two Type objects)
|
|
267
428
|
// differs by identity constantly without being an escape, and disqualifying
|
|
268
429
|
// on that alone moved well over a hundred unrelated programs' emitted
|
|
269
|
-
// output measured against `npm run gate`.
|
|
270
|
-
//
|
|
271
|
-
//
|
|
272
|
-
//
|
|
430
|
+
// output measured against `npm run gate`. Such a widening is a second view
|
|
431
|
+
// of the same object, which `entersView` joins to the operand's alias
|
|
432
|
+
// class. `any`/`unknown` is the one declared type this compiler can never
|
|
433
|
+
// narrow back to the operand's own shape, which is exactly the condition a
|
|
434
|
+
// second, differently-typed name for this cell needs to retain the object
|
|
435
|
+
// after this rule's proof.
|
|
273
436
|
if (operation.family === 'binding') {
|
|
274
437
|
if (operation.action !== 'initialize' && operation.action !== 'write')
|
|
275
438
|
continue;
|
|
@@ -287,15 +450,15 @@ export const valueRecordTypesOf = (graph) => {
|
|
|
287
450
|
// structure, so this can never disqualify anything the check above
|
|
288
451
|
// already decides for objects.
|
|
289
452
|
const resultIsWideningArray = !resultIsDynamic && resultShape?.kind === 'array';
|
|
290
|
-
if (!resultIsDynamic && !resultIsWideningArray)
|
|
291
|
-
continue;
|
|
292
453
|
for (const operand of operation.operands) {
|
|
293
454
|
if (operand.type === result.type)
|
|
294
455
|
continue;
|
|
295
|
-
if (resultIsWideningArray && graph.structuralTypes.get(operand.type)?.shape.kind
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
456
|
+
if (resultIsWideningArray && graph.structuralTypes.get(operand.type)?.shape.kind === 'tuple') {
|
|
457
|
+
objectCoresOf(graph, operand.type, disqualified);
|
|
458
|
+
disqualifyCallable(operand.type);
|
|
459
|
+
}
|
|
460
|
+
else
|
|
461
|
+
entersView(operand.type, result.type);
|
|
299
462
|
}
|
|
300
463
|
continue;
|
|
301
464
|
}
|
|
@@ -307,6 +470,11 @@ export const valueRecordTypesOf = (graph) => {
|
|
|
307
470
|
const receiver = operation.operands.find((operand) => operand.role === 'receiver');
|
|
308
471
|
if (!receiver)
|
|
309
472
|
continue;
|
|
473
|
+
const value = operation.operands.find((operand) => operand.role === 'value');
|
|
474
|
+
const key = operation.operands.find((operand) => operand.role === 'key')?.source;
|
|
475
|
+
if (value)
|
|
476
|
+
for (const slot of slotTypesOf(graph, receiver.type, key?.kind === 'constant' ? key.text : null))
|
|
477
|
+
entersView(value.type, slot);
|
|
310
478
|
// `define-own-property` is how an object LITERAL installs its own fields,
|
|
311
479
|
// so every record in the program carries one and reading it as a mutation
|
|
312
480
|
// disqualifies all of them. The write that matters is one aimed at an
|
|
@@ -325,6 +493,7 @@ export const valueRecordTypesOf = (graph) => {
|
|
|
325
493
|
// admitted, because that function's own body compiles against the same
|
|
326
494
|
// carrier and its copy is the value the language already promises.
|
|
327
495
|
if (operation.family === 'invocation') {
|
|
496
|
+
enterArguments(operation);
|
|
328
497
|
const target = operation.target;
|
|
329
498
|
if (target.kind === 'exact' && target.target.kind === 'function') {
|
|
330
499
|
// The exemption's own premise -- "the callee's body compiles against
|
|
@@ -168,6 +168,13 @@ export interface CollectionBindingCensus {
|
|
|
168
168
|
readonly arrayElementAt: (node: ts.ArrayLiteralExpression) => ts.Type | null;
|
|
169
169
|
/** Why this particular empty array literal was not bound, or `null` if it was, or if it was never a candidate (including: `settleEvolving`'s territory, not this module's). */
|
|
170
170
|
readonly arrayRefusalOf: (node: ts.ArrayLiteralExpression) => string | null;
|
|
171
|
+
/**
|
|
172
|
+
* Whether this empty literal's array is filled with values the census could
|
|
173
|
+
* not join to one element: an untyped write, disagreeing writes, or a
|
|
174
|
+
* computed read that hands the array out untyped. Its `never[]` then states
|
|
175
|
+
* nothing about what it holds.
|
|
176
|
+
*/
|
|
177
|
+
readonly arrayHoldsUnjoinedWrites: (node: ts.ArrayLiteralExpression) => boolean;
|
|
171
178
|
/**
|
|
172
179
|
* The element type for a READ of a cell this census bound an array for --
|
|
173
180
|
* `state.probe` and `this.children`, not just the `[]` that filled them.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from '#typescript';
|
|
2
2
|
import { censusRefusal } from './census-refusal.js';
|
|
3
|
-
import { disjointUnionTypeOf, isStandardInterfaceType, joinOfWrites, widestOf } from './derived-expression-type.js';
|
|
3
|
+
import { disjointUnionTypeOf, isStandardInterfaceType, joinOfWrites, literalMemberNameOf, widestOf } from './derived-expression-type.js';
|
|
4
4
|
import { emptyParameterBindingCensus } from './parameter-bindings.js';
|
|
5
5
|
import { closedArrayStoredValuesOf } from './flow/callable-reach.js';
|
|
6
6
|
import { deferredIntrinsicProtocolLedgerOf } from './deferred-intrinsic-protocols.js';
|
|
@@ -13,6 +13,7 @@ export const emptyCollectionBindingCensus = {
|
|
|
13
13
|
refusalOf: () => null,
|
|
14
14
|
arrayElementAt: () => null,
|
|
15
15
|
arrayRefusalOf: () => null,
|
|
16
|
+
arrayHoldsUnjoinedWrites: () => false,
|
|
16
17
|
arrayElementForRead: () => null,
|
|
17
18
|
arrayElementForOwner: () => null,
|
|
18
19
|
arrayRefusalForOwner: () => null,
|
|
@@ -629,6 +630,7 @@ flow) => {
|
|
|
629
630
|
const arraysByOwner = new Map();
|
|
630
631
|
const arrayNodeOwner = new Map();
|
|
631
632
|
const arrayNodeRefusal = new Map();
|
|
633
|
+
const computedReads = [];
|
|
632
634
|
const collectArrayLiterals = (node) => {
|
|
633
635
|
// See the identical guard in `collectConstructions` above: this walk and
|
|
634
636
|
// `flow`'s own must agree on what counts as live code, or a member
|
|
@@ -659,10 +661,29 @@ flow) => {
|
|
|
659
661
|
// (rather than bound to a name) is invisible to the census above
|
|
660
662
|
// rather than counted as a refusal.
|
|
661
663
|
}
|
|
664
|
+
if (ts.isElementAccessExpression(node) && literalMemberNameOf(node) === null)
|
|
665
|
+
computedReads.push(node);
|
|
662
666
|
ts.forEachChild(node, collectArrayLiterals);
|
|
663
667
|
};
|
|
664
668
|
for (const file of files)
|
|
665
669
|
forEachReachableStatement(reachable, file, collectArrayLiterals);
|
|
670
|
+
// An object literal's `[]` member reaches code no edge names once a computed
|
|
671
|
+
// read hands it out as `any`: under `noImplicitAny: false`,
|
|
672
|
+
// `this.koto[k.layer].push(k)` is invisible to the checker and to `flow`, so
|
|
673
|
+
// the member is filled with values nothing typed.
|
|
674
|
+
const untypedMemberReads = new Map();
|
|
675
|
+
for (const read of computedReads) {
|
|
676
|
+
if ((checker.getTypeAtLocation(read).flags & ts.TypeFlags.Any) === 0)
|
|
677
|
+
continue;
|
|
678
|
+
const receiver = checker.getNonNullableType(checker.getTypeAtLocation(read.expression));
|
|
679
|
+
for (const arm of receiver.isUnion() ? receiver.types : [receiver]) {
|
|
680
|
+
for (const property of checker.getPropertiesOfType(arm)) {
|
|
681
|
+
const declaration = property.declarations?.[0];
|
|
682
|
+
if (declaration && ts.isPropertyAssignment(declaration) && arraysByOwner.has(declaration) && !untypedMemberReads.has(declaration))
|
|
683
|
+
untypedMemberReads.set(declaration, read);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
666
687
|
// Pass 4: every `.push`/`.unshift`/`.fill` call and every genuine INDEX
|
|
667
688
|
// (non-literal-key) assignment reaching one of the tracked array literals
|
|
668
689
|
// above OR any cell in its alias closure -- read from `flow`'s
|
|
@@ -720,6 +741,15 @@ flow) => {
|
|
|
720
741
|
return true;
|
|
721
742
|
};
|
|
722
743
|
for (const [owner, aliases] of arrayComponents) {
|
|
744
|
+
const untypedRead = [...aliases].map((alias) => untypedMemberReads.get(alias)).find((read) => read !== undefined);
|
|
745
|
+
if (untypedRead) {
|
|
746
|
+
for (const alias of aliases)
|
|
747
|
+
ownerArrayRefusal.set(alias, 'array:element-unresolved');
|
|
748
|
+
const site = untypedRead.getSourceFile();
|
|
749
|
+
censusRefusals.push(censusRefusal('collection', 'array-element-unresolved', `the computed read \`${untypedRead.getText(site)}\` (${site.fileName}:${site.getLineAndCharacterOfPosition(untypedRead.getStart(site)).line + 1}) ` +
|
|
750
|
+
'hands this array out untyped, so no write through it can be typed', describeOwner(owner)));
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
723
753
|
const evidence = [];
|
|
724
754
|
for (const decl of aliases) {
|
|
725
755
|
for (const write of flow.writesToDeclaration(decl)) {
|
|
@@ -918,6 +948,10 @@ flow) => {
|
|
|
918
948
|
return boundElement.get(owner) ?? null;
|
|
919
949
|
},
|
|
920
950
|
arrayRefusalOf: (node) => arrayNodeRefusal.get(node) ?? null,
|
|
951
|
+
arrayHoldsUnjoinedWrites: (node) => {
|
|
952
|
+
const reason = arrayNodeRefusal.get(node);
|
|
953
|
+
return reason === 'array:element-unresolved' || reason === 'array:elements-disagree';
|
|
954
|
+
},
|
|
921
955
|
arrayElementForRead: (expression) => {
|
|
922
956
|
const owner = ownerDeclOfExpr(expression);
|
|
923
957
|
return owner ? (boundElement.get(owner) ?? null) : null;
|
|
@@ -2679,6 +2679,46 @@ export const isDistinctClassConstructorPair = (a, b) => {
|
|
|
2679
2679
|
const second = classOfConstructorType(b);
|
|
2680
2680
|
return first !== null && second !== null && first !== second;
|
|
2681
2681
|
};
|
|
2682
|
+
/** The class a class INSTANCE type belongs to (a generic one's own class for any instantiation), or `null` for any other type. */
|
|
2683
|
+
const classOfInstanceType = (type) => (type.flags & ts.TypeFlags.Object) !== 0 &&
|
|
2684
|
+
type.symbol !== undefined &&
|
|
2685
|
+
(type.symbol.flags & ts.SymbolFlags.Class) !== 0 &&
|
|
2686
|
+
type.getConstructSignatures().length === 0
|
|
2687
|
+
? type.symbol
|
|
2688
|
+
: null;
|
|
2689
|
+
/** `type`'s class and every ancestor class the checker resolves for it, nearest first. */
|
|
2690
|
+
const classChainOf = (checker, type) => {
|
|
2691
|
+
const chain = [];
|
|
2692
|
+
let current = type;
|
|
2693
|
+
while (current !== undefined) {
|
|
2694
|
+
const own = classOfInstanceType(current);
|
|
2695
|
+
if (own === null || chain.includes(own))
|
|
2696
|
+
break;
|
|
2697
|
+
chain.push(own);
|
|
2698
|
+
const target = current.target ?? current;
|
|
2699
|
+
current = target.isClassOrInterface() ? checker.getBaseTypes(target).find((base) => classOfInstanceType(base) !== null) : undefined;
|
|
2700
|
+
}
|
|
2701
|
+
return chain;
|
|
2702
|
+
};
|
|
2703
|
+
/**
|
|
2704
|
+
* Whether `other` is a class instance that every class arm of `candidate` it is
|
|
2705
|
+
* assignable to fails to hold nominally: none of those arms is its own class or
|
|
2706
|
+
* one of its ancestors, and `candidate` offers no other arm it is assignable to.
|
|
2707
|
+
* The checker's assignability is structural, so a base object is "assignable"
|
|
2708
|
+
* to a subclass that adds no member; this compiler's class carrier is not.
|
|
2709
|
+
*/
|
|
2710
|
+
const isClassInstanceOutsideClassArms = (checker, other, candidate) => {
|
|
2711
|
+
if (classOfInstanceType(other) === null)
|
|
2712
|
+
return false;
|
|
2713
|
+
const receiving = (candidate.isUnion() ? candidate.types : [candidate]).filter((arm) => checker.isTypeAssignableTo(other, arm));
|
|
2714
|
+
if (receiving.length === 0)
|
|
2715
|
+
return false;
|
|
2716
|
+
const chain = classChainOf(checker, other);
|
|
2717
|
+
return receiving.every((arm) => {
|
|
2718
|
+
const armClass = classOfInstanceType(arm);
|
|
2719
|
+
return armClass !== null && !chain.includes(armClass);
|
|
2720
|
+
});
|
|
2721
|
+
};
|
|
2682
2722
|
/**
|
|
2683
2723
|
* A constructor type with no class anchor -- `{ new (bytes: Uint8Array):
|
|
2684
2724
|
* Reply; make(bytes: Uint8Array): Reply }`, `new () => Component`.
|
|
@@ -2832,6 +2872,15 @@ export const widestOf = (checker, types) => {
|
|
|
2832
2872
|
// `[cls = class {}, xCls = class X {}]` read `xCls.name` as `"cls"`.
|
|
2833
2873
|
if (isDistinctClassConstructorPair(other, candidate))
|
|
2834
2874
|
return false;
|
|
2875
|
+
// The same holds for the INSTANCES: a class instance carrier is nominal
|
|
2876
|
+
// too (`class-ref`), and a base-class object is not a subclass object
|
|
2877
|
+
// however alike their shapes. `show(cube)` then `show(new Base())` made
|
|
2878
|
+
// the parameter the subclass, the first observation the base was
|
|
2879
|
+
// structurally assignable to, and the base object then entered it through
|
|
2880
|
+
// an unchecked downcast. Only an ancestor class (or the same one) covers
|
|
2881
|
+
// a class instance.
|
|
2882
|
+
if (isClassInstanceOutsideClassArms(checker, other, candidate))
|
|
2883
|
+
return false;
|
|
2835
2884
|
// An empty object literal the program EVALUATED covers nothing but another
|
|
2836
2885
|
// empty literal. It is a fresh object with zero members -- the most precise
|
|
2837
2886
|
// statement there is (see `exactEmptyObjectLiteralType`) -- and a table
|
|
@@ -22,6 +22,7 @@ export const emptyFieldBindingCensus = {
|
|
|
22
22
|
};
|
|
23
23
|
const WIDENED = process.env['GEA_FLOW_WIDE'] === '1';
|
|
24
24
|
const isAnyType = (type) => (type.flags & ts.TypeFlags.Any) !== 0;
|
|
25
|
+
const isNullish = (type) => (type.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined)) !== 0;
|
|
25
26
|
/** Duplicated from `parameter-bindings.ts` (not exported there): `any`/`void`/`never` say nothing about storage. */
|
|
26
27
|
const isUnusableEvidence = (type) => (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Void | ts.TypeFlags.Never)) !== 0;
|
|
27
28
|
/**
|
|
@@ -1017,7 +1018,11 @@ flow) => {
|
|
|
1017
1018
|
// a vector class's `x`/`y`/`z` carry dozens of writes each, all typed
|
|
1018
1019
|
// `number` but one (`this.x = e[ 12 ]`, `e` unannotated) silent -- every
|
|
1019
1020
|
// read boxed by a veto that read no fact.
|
|
1020
|
-
|
|
1021
|
+
// Writes that speak only of ABSENCE do not count: `this.shaku = null` in a
|
|
1022
|
+
// constructor, filled later by one silent `this.shaku = index.shakuhachi`,
|
|
1023
|
+
// joined to `null` alone, and that silent write -- the only one carrying
|
|
1024
|
+
// what the field holds -- then aborted in its checked unbox.
|
|
1025
|
+
else if (silent > 0 && (!lenientPhase || types.every(isNullish)))
|
|
1021
1026
|
attribute(symbol, 'write-unresolved');
|
|
1022
1027
|
else {
|
|
1023
1028
|
// A FRESH `{}` written into the field contributes a value with no keys,
|
|
@@ -45,7 +45,14 @@ type QueryShape = {
|
|
|
45
45
|
readonly kind: 'own-keys';
|
|
46
46
|
readonly node: ObjectRoot;
|
|
47
47
|
} | {
|
|
48
|
-
readonly kind: '
|
|
48
|
+
readonly kind: 'enumerated-keys';
|
|
49
|
+
readonly node: ts.Expression;
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: 'use' | 'root-use';
|
|
52
|
+
readonly node: ts.Expression;
|
|
53
|
+
readonly root: Value;
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: 'enumerated-slots';
|
|
49
56
|
readonly node: ts.Expression;
|
|
50
57
|
readonly root: Value;
|
|
51
58
|
} | {
|
|
@@ -57,7 +64,7 @@ type QueryShape = {
|
|
|
57
64
|
readonly kind: 'unknown-reads';
|
|
58
65
|
readonly node: ObjectRoot;
|
|
59
66
|
} | {
|
|
60
|
-
readonly kind: 'key-reads';
|
|
67
|
+
readonly kind: 'key-reads' | 'key-uses' | 'family-slot';
|
|
61
68
|
readonly node: ObjectRoot;
|
|
62
69
|
readonly key: string;
|
|
63
70
|
} | {
|