@geastack/compiler 1.0.32 → 1.0.34
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/README.md +1 -1
- package/dist/cli-coverage.js +2 -4
- package/dist/cli-emit.js +1 -1
- package/dist/cli-module-graph.js +1 -1
- package/dist/cli.js +2 -1
- package/dist/compiler.js +35 -28
- package/dist/conversion/array-view.js +9 -0
- package/dist/conversion/build.js +15 -8
- package/dist/conversion/dictionary-view.js +2 -2
- package/dist/conversion/nodes.d.ts +7 -0
- package/dist/conversion/nodes.js +58 -11
- package/dist/identity/ids.d.ts +4 -0
- package/dist/identity/ids.js +4 -0
- package/dist/ir/build.d.ts +4 -3
- package/dist/ir/build.js +14 -5
- package/dist/ir/call-dispatch.js +67 -7
- package/dist/ir/call-entry.js +1 -1
- package/dist/ir/callable-class-flow.d.ts +4 -0
- package/dist/ir/callable-class-flow.js +123 -1
- package/dist/ir/certify/parallel-region.js +698 -20
- package/dist/ir/certify.d.ts +3 -0
- package/dist/ir/certify.js +44 -9
- package/dist/ir/class-allocation-domain.js +2 -2
- package/dist/ir/class-construction-status.d.ts +10 -0
- package/dist/ir/class-construction-status.js +36 -0
- package/dist/ir/convert-carriers.d.ts +10 -1
- package/dist/ir/convert-carriers.js +18 -1
- package/dist/ir/dynamic-constructor-conversions.js +4 -2
- package/dist/ir/finite-iterator-close.d.ts +14 -0
- package/dist/ir/finite-iterator-close.js +50 -0
- package/dist/ir/host-template-conversions.js +9 -0
- package/dist/ir/lower-allocation.js +1 -1
- package/dist/ir/lower-flow.js +24 -3
- package/dist/ir/lower-operands.js +88 -7
- package/dist/ir/lower-protocol.js +1 -1
- package/dist/ir/lower.js +22 -6
- package/dist/ir/model.d.ts +41 -1
- package/dist/ir/native-accessor-definition.d.ts +3 -2
- package/dist/ir/native-accessor-definition.js +29 -10
- package/dist/ir/native-array-transport.js +2 -2
- package/dist/ir/native-field-view-domains.d.ts +23 -0
- package/dist/ir/native-field-view-domains.js +115 -9
- package/dist/ir/native-field-view-facts.d.ts +46 -2
- package/dist/ir/native-field-view-facts.js +159 -4
- package/dist/ir/native-iterable.d.ts +17 -0
- package/dist/ir/native-iterable.js +72 -0
- package/dist/ir/native-key-query.js +1 -1
- package/dist/ir/operation-conversions.js +15 -3
- package/dist/ir/program-conversions.js +2 -2
- package/dist/ir/publish-native-field-view-facts.js +9 -4
- package/dist/ir/pure-conversion-reuse.d.ts +58 -0
- package/dist/ir/pure-conversion-reuse.js +263 -0
- package/dist/ir/queries.js +1 -0
- package/dist/ir/reflection-demand.js +70 -18
- package/dist/ir/shake.js +2 -2
- package/dist/ir/unobserved-callable-inputs.d.ts +37 -0
- package/dist/ir/unobserved-callable-inputs.js +111 -0
- package/dist/native-signatures.d.ts +1 -1
- package/dist/native-signatures.js +27 -2
- package/dist/plugins/gea/component-classes.d.ts +2 -1
- package/dist/plugins/gea/component-classes.js +3 -3
- package/dist/plugins/gea/contract.d.ts +26 -3
- package/dist/plugins/gea/contract.js +42 -43
- package/dist/plugins/gea/host.d.ts +9 -0
- package/dist/plugins/gea/host.js +25 -4
- package/dist/plugins/gea/plugin.js +12 -6
- package/dist/plugins/gea/producer.d.ts +2 -2
- package/dist/plugins/gea/producer.js +2 -2
- package/dist/plugins/load.js +18 -1
- package/dist/plugins/model.d.ts +5 -0
- package/dist/plugins/native-iterable-providers.d.ts +18 -0
- package/dist/plugins/native-iterable-providers.js +51 -0
- package/dist/project-preparation.d.ts +8 -0
- package/dist/project-preparation.js +49 -7
- package/dist/projection/bindings.d.ts +13 -0
- package/dist/projection/bindings.js +20 -1
- package/dist/projection/classes.d.ts +4 -2
- package/dist/projection/classes.js +12 -5
- package/dist/representation/collections.js +2 -0
- package/dist/representation/derive.js +1 -0
- package/dist/representation/model.d.ts +2 -0
- package/dist/representation/model.js +1 -0
- package/dist/representation/policies.d.ts +2 -0
- package/dist/representation/primitive-domain.d.ts +1 -1
- package/dist/representation/primitive-domain.js +1 -1
- package/dist/representation/unassigned-binding-cells.d.ts +4 -3
- package/dist/representation/unassigned-binding-cells.js +19 -2
- package/dist/representation/union.js +6 -6
- package/dist/semantics/frontend.d.ts +2 -0
- package/dist/semantics/frontend.js +34 -5
- package/dist/semantics/host-methods.js +4 -1
- package/dist/semantics/jsx-runtime-provider.d.ts +5 -0
- package/dist/semantics/jsx-runtime-provider.js +16 -0
- package/dist/semantics/model/native-iterable.d.ts +14 -0
- package/dist/semantics/model/native-iterable.js +7 -0
- package/dist/semantics/model/operands.d.ts +30 -0
- package/dist/semantics/model/operations.d.ts +15 -0
- package/dist/semantics/model/primitive-domain.d.ts +15 -0
- package/dist/semantics/model/primitive-domain.js +27 -4
- package/dist/semantics/module-resolution.js +13 -2
- package/dist/semantics/normalize/any-cast-member-call.d.ts +1 -1
- package/dist/semantics/normalize/callback-parameter-contracts.d.ts +32 -4
- package/dist/semantics/normalize/callback-parameter-contracts.js +66 -6
- package/dist/semantics/normalize/census.d.ts +3 -0
- package/dist/semantics/normalize/census.js +17 -12
- package/dist/semantics/normalize/deferred-intrinsic-protocols.d.ts +4 -1
- package/dist/semantics/normalize/deferred-intrinsic-protocols.js +29 -9
- package/dist/semantics/normalize/flow/callable-reach.js +94 -3
- package/dist/semantics/normalize/flow/component-solver.js +144 -55
- package/dist/semantics/normalize/flow/member-call-forwarding.d.ts +9 -0
- package/dist/semantics/normalize/flow/member-call-forwarding.js +30 -4
- package/dist/semantics/normalize/flow/proof-hypotheses.d.ts +2 -0
- package/dist/semantics/normalize/flow/proof-hypotheses.js +27 -0
- package/dist/semantics/normalize/flow/source-callable-own-data.js +87 -14
- package/dist/semantics/normalize/flow/source-commonjs-exports.d.ts +2 -0
- package/dist/semantics/normalize/flow/source-commonjs-exports.js +2 -0
- package/dist/semantics/normalize/flow/source-native-iterable-integrity.d.ts +17 -0
- package/dist/semantics/normalize/flow/source-native-iterable-integrity.js +125 -0
- package/dist/semantics/normalize/flow/source-native-origin.d.ts +6 -0
- package/dist/semantics/normalize/flow/source-native-origin.js +38 -0
- package/dist/semantics/normalize/flow/source-proxy-operation.d.ts +37 -0
- package/dist/semantics/normalize/flow/source-proxy-operation.js +201 -0
- package/dist/semantics/normalize/flow/source-raw-constructor-entry.d.ts +20 -0
- package/dist/semantics/normalize/flow/source-raw-constructor-entry.js +73 -0
- package/dist/semantics/normalize/flow/source-value-session.d.ts +50 -1
- package/dist/semantics/normalize/flow/source-value-session.js +596 -57
- package/dist/semantics/normalize/flow/value-flow.d.ts +17 -0
- package/dist/semantics/normalize/flow/value-flow.js +84 -0
- package/dist/semantics/normalize/fresh-dictionary-storage.js +2 -2
- package/dist/semantics/normalize/fresh-table-last-use.d.ts +52 -0
- package/dist/semantics/normalize/fresh-table-last-use.js +129 -0
- package/dist/semantics/normalize/gating.js +5 -1
- package/dist/semantics/normalize/global-host-mutations.js +190 -13
- package/dist/semantics/normalize/identities.js +20 -1
- package/dist/semantics/normalize/local-bindings.js +2 -2
- package/dist/semantics/normalize/parameter-bindings.js +10 -1
- package/dist/semantics/normalize/producer-context.d.ts +5 -0
- package/dist/semantics/normalize/producers/binding-kind.js +2 -0
- package/dist/semantics/normalize/producers/cited-value-type.d.ts +2 -2
- package/dist/semantics/normalize/producers/cited-value-type.js +2 -2
- package/dist/semantics/normalize/producers/class-lifecycle.js +39 -9
- package/dist/semantics/normalize/producers/computations.js +36 -5
- package/dist/semantics/normalize/producers/conditional-guard.d.ts +6 -0
- package/dist/semantics/normalize/producers/conditional-guard.js +5 -0
- package/dist/semantics/normalize/producers/control.js +7 -1
- package/dist/semantics/normalize/producers/destructuring.js +8 -9
- package/dist/semantics/normalize/producers/invocations.js +55 -2
- package/dist/semantics/normalize/producers/properties.d.ts +13 -0
- package/dist/semantics/normalize/producers/properties.js +21 -3
- package/dist/semantics/normalize/producers/references.js +8 -4
- package/dist/semantics/normalize/reachability.d.ts +15 -3
- package/dist/semantics/normalize/reachability.js +128 -20
- package/dist/semantics/normalize/return-bindings.js +3 -3
- package/dist/semantics/normalize/source-native-iterable.d.ts +19 -0
- package/dist/semantics/normalize/source-native-iterable.js +74 -0
- package/dist/semantics/normalize/structural-any-binding-consumer.d.ts +1 -1
- package/dist/semantics/normalize/structural-declarations.js +1 -1
- package/dist/semantics/normalize/structural-indexed-access.js +9 -0
- package/dist/semantics/normalize/structural.js +11 -0
- package/dist/semantics/normalize/unshared-array-result.d.ts +42 -0
- package/dist/semantics/normalize/unshared-array-result.js +269 -0
- package/dist/semantics/package-sources.js +3 -2
- package/dist/semantics/program.d.ts +8 -0
- package/dist/semantics/program.js +55 -0
- package/dist/semantics/source-transform-exports.d.ts +8 -0
- package/dist/semantics/source-transform-exports.js +145 -0
- package/dist/semantics/source-transform-protocol.d.ts +22 -0
- package/dist/semantics/this-constructor-source-transform.js +19 -1
- package/dist/targets/cpp/class-layout.d.ts +2 -0
- package/dist/targets/cpp/class-layout.js +35 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +11 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.js +33 -4
- package/dist/targets/cpp/conversions.js +6 -3
- package/dist/targets/cpp/emit-callable.js +73 -7
- package/dist/targets/cpp/emit-context.d.ts +23 -9
- package/dist/targets/cpp/emit-context.js +19 -8
- package/dist/targets/cpp/emit-equality.js +41 -1
- package/dist/targets/cpp/emit-exceptions.js +29 -11
- package/dist/targets/cpp/emit-iterator-object-view.js +2 -2
- package/dist/targets/cpp/emit-iterator.js +33 -9
- package/dist/targets/cpp/emit-live-field-view.js +6 -1
- package/dist/targets/cpp/emit-narrowing.d.ts +11 -3
- package/dist/targets/cpp/emit-narrowing.js +58 -18
- package/dist/targets/cpp/emit-native-field-view.d.ts +3 -1
- package/dist/targets/cpp/emit-native-field-view.js +84 -8
- package/dist/targets/cpp/emit-properties.d.ts +1 -0
- package/dist/targets/cpp/emit-properties.js +26 -7
- package/dist/targets/cpp/emit-protocol-iterator.js +5 -2
- package/dist/targets/cpp/emit-record-view.js +14 -2
- package/dist/targets/cpp/emit-tostring.js +23 -1
- package/dist/targets/cpp/emit-union-properties.js +1 -1
- package/dist/targets/cpp/emit.d.ts +1 -1
- package/dist/targets/cpp/emit.js +132 -21
- package/dist/targets/cpp/host/emit-host-invoke.js +2 -2
- package/dist/targets/cpp/host/emit-host-object.js +28 -2
- package/dist/targets/cpp/host/emit-host-properties.js +9 -1
- package/dist/targets/cpp/host/emit-host-value.d.ts +1 -1
- package/dist/targets/cpp/host/emit-host-value.js +8 -6
- package/dist/targets/cpp/host/host-members.js +2 -1
- package/dist/targets/cpp/prototype/emit-prototype-array.js +69 -5
- package/dist/targets/cpp/prototype/emit-prototype-invoke.js +9 -9
- package/dist/targets/cpp/prototype/emit-prototype-iterator.js +2 -2
- package/dist/targets/cpp/prototype/emit-prototype-promise.js +7 -7
- package/dist/targets/cpp/records.d.ts +1 -0
- package/dist/targets/cpp/records.js +16 -7
- package/dist/targets/cpp/translation-unit.js +30 -16
- package/package.json +8 -7
- package/src/targets/cpp/runtime/gea_dynamic_proxy.h +42 -3
- package/src/targets/cpp/runtime/gea_eval.h +3 -0
- package/src/targets/cpp/runtime/gea_runtime.h +2407 -684
|
@@ -730,6 +730,8 @@ export const censusReachability = (input) => {
|
|
|
730
730
|
// A receiver's static type requires layout, not evaluation of its module or
|
|
731
731
|
// constructor. A later value reference can promote the same class to runtime.
|
|
732
732
|
const layoutClasses = new Set();
|
|
733
|
+
const constructedClasses = new Set();
|
|
734
|
+
const exposedNamespaceFiles = new Set();
|
|
733
735
|
// Every deferrable member the walk has SEEN, and the subset something has
|
|
734
736
|
// NAMED. A member in the first and not the second is dead: the class it
|
|
735
737
|
// belongs to is live, so the walk reached its declaration, and nothing in
|
|
@@ -799,6 +801,14 @@ export const censusReachability = (input) => {
|
|
|
799
801
|
openStatement(statement);
|
|
800
802
|
for (const target of moduleTargetsOf(input.checker, file, { verbatim: input.verbatimModuleSyntax === true }))
|
|
801
803
|
fileQueue.push(target);
|
|
804
|
+
if (entries.has(file) && ts.isExternalModule(file)) {
|
|
805
|
+
const module = input.checker.getSymbolAtLocation(file);
|
|
806
|
+
for (const exported of module ? input.checker.getExportsOfModule(module) : []) {
|
|
807
|
+
const value = input.runtimeExportOf?.(file, exported.getName());
|
|
808
|
+
if (value?.kind !== 'missing')
|
|
809
|
+
markSymbol(value?.kind === 'binding' ? value.symbol : exported);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
802
812
|
};
|
|
803
813
|
const spellKey = (text) => {
|
|
804
814
|
if (spelledKeys.has(text))
|
|
@@ -829,6 +839,22 @@ export const censusReachability = (input) => {
|
|
|
829
839
|
* declares `member`: a class constructor type naming that class or one of
|
|
830
840
|
* its ancestors, or a structural constructor type the class fits.
|
|
831
841
|
*/
|
|
842
|
+
const classDescendsFrom = (from, ancestor) => {
|
|
843
|
+
const seen = new Set();
|
|
844
|
+
const pending = [input.checker.getDeclaredTypeOfSymbol(from)];
|
|
845
|
+
for (let current = pending.pop(); current !== undefined; current = pending.pop()) {
|
|
846
|
+
const symbol = current.getSymbol();
|
|
847
|
+
if (!symbol || seen.has(symbol))
|
|
848
|
+
continue;
|
|
849
|
+
seen.add(symbol);
|
|
850
|
+
if (symbol === ancestor)
|
|
851
|
+
return true;
|
|
852
|
+
const target = current.objectFlags & ts.ObjectFlags.Reference ? current.target : current;
|
|
853
|
+
if (target.isClassOrInterface())
|
|
854
|
+
pending.push(...input.checker.getBaseTypes(target));
|
|
855
|
+
}
|
|
856
|
+
return false;
|
|
857
|
+
};
|
|
832
858
|
const readReachesStatic = (receiver, member) => {
|
|
833
859
|
const own = constructorTypeOfMember(member);
|
|
834
860
|
if (own === null)
|
|
@@ -838,20 +864,10 @@ export const censusReachability = (input) => {
|
|
|
838
864
|
const ownSymbol = own.getSymbol();
|
|
839
865
|
if (!ownSymbol)
|
|
840
866
|
return true;
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
if (!symbol || seen.has(symbol))
|
|
846
|
-
continue;
|
|
847
|
-
seen.add(symbol);
|
|
848
|
-
if (symbol === receiverSymbol)
|
|
849
|
-
return true;
|
|
850
|
-
const target = current.objectFlags & ts.ObjectFlags.Reference ? current.target : current;
|
|
851
|
-
if (target.isClassOrInterface())
|
|
852
|
-
pending.push(...input.checker.getBaseTypes(target));
|
|
853
|
-
}
|
|
854
|
-
return false;
|
|
867
|
+
// A read on a base may run with a subclass as `this`; a read on a
|
|
868
|
+
// subclass reaches an inherited static whenever its own same-named
|
|
869
|
+
// static field is not yet defined (`static a = this.b; static b = 1`).
|
|
870
|
+
return classDescendsFrom(ownSymbol, receiverSymbol) || classDescendsFrom(receiverSymbol, ownSymbol);
|
|
855
871
|
}
|
|
856
872
|
return input.checker.isTypeAssignableTo(own, receiver);
|
|
857
873
|
};
|
|
@@ -859,7 +875,9 @@ export const censusReachability = (input) => {
|
|
|
859
875
|
// The class's own binding (`Readable.from`, an imported alias of it) is
|
|
860
876
|
// exactly that class -- TypeScript refuses an assignment to it -- and its
|
|
861
877
|
// read already opened the one declaration it names by symbol.
|
|
862
|
-
|
|
878
|
+
// A static method's `this` also resolves to the class symbol, but it is
|
|
879
|
+
// whichever subclass the call ran on, so it takes the typed path below.
|
|
880
|
+
let named = receiver.kind === ts.SyntaxKind.ThisKeyword ? undefined : input.checker.getSymbolAtLocation(receiver);
|
|
863
881
|
if (named && named.flags & ts.SymbolFlags.Alias)
|
|
864
882
|
named = input.checker.getAliasedSymbol(named);
|
|
865
883
|
if (named && named.flags & ts.SymbolFlags.Class)
|
|
@@ -883,7 +901,56 @@ export const censusReachability = (input) => {
|
|
|
883
901
|
for (const member of opened)
|
|
884
902
|
openMember(member);
|
|
885
903
|
};
|
|
886
|
-
const
|
|
904
|
+
const markConstructed = (owner) => {
|
|
905
|
+
if (constructedClasses.has(owner))
|
|
906
|
+
return;
|
|
907
|
+
constructedClasses.add(owner);
|
|
908
|
+
if (liveStatements.has(owner))
|
|
909
|
+
statementQueue.push(owner);
|
|
910
|
+
for (const clause of owner.heritageClauses ?? []) {
|
|
911
|
+
if (clause.token !== ts.SyntaxKind.ExtendsKeyword)
|
|
912
|
+
continue;
|
|
913
|
+
for (const base of clause.types)
|
|
914
|
+
markConstruction(base.expression);
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
const markConstruction = (expression) => {
|
|
918
|
+
const selected = input.constructorTargetsOf?.(expression);
|
|
919
|
+
if (selected) {
|
|
920
|
+
for (const owner of selected)
|
|
921
|
+
markConstructed(owner);
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
const signatures = input.checker.getTypeAtLocation(expression).getConstructSignatures();
|
|
925
|
+
const results = signatures.flatMap((signature) => {
|
|
926
|
+
const result = input.checker.getReturnTypeOfSignature(signature);
|
|
927
|
+
return result.isUnion() ? result.types : [result];
|
|
928
|
+
});
|
|
929
|
+
for (const file of input.files)
|
|
930
|
+
for (const statement of file.statements) {
|
|
931
|
+
if (!ts.isClassDeclaration(statement) || !statement.name)
|
|
932
|
+
continue;
|
|
933
|
+
const symbol = input.checker.getSymbolAtLocation(statement.name);
|
|
934
|
+
if (!symbol)
|
|
935
|
+
continue;
|
|
936
|
+
const instance = input.checker.getDeclaredTypeOfSymbol(symbol);
|
|
937
|
+
if (results.length === 0 || results.some((result) => input.checker.isTypeAssignableTo(instance, result)))
|
|
938
|
+
markConstructed(statement);
|
|
939
|
+
}
|
|
940
|
+
};
|
|
941
|
+
const exposeNamespace = (file) => {
|
|
942
|
+
if (!compiled.has(file) || exposedNamespaceFiles.has(file))
|
|
943
|
+
return;
|
|
944
|
+
exposedNamespaceFiles.add(file);
|
|
945
|
+
fileQueue.push(file);
|
|
946
|
+
const module = input.checker.getSymbolAtLocation(file);
|
|
947
|
+
for (const exported of module ? input.checker.getExportsOfModule(module) : []) {
|
|
948
|
+
const value = input.runtimeExportOf?.(file, exported.getName());
|
|
949
|
+
if (value?.kind !== 'missing')
|
|
950
|
+
markSymbol(value?.kind === 'binding' ? value.symbol : exported);
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
const markSymbol = (symbol, constructionUse = true) => {
|
|
887
954
|
if (!symbol)
|
|
888
955
|
return;
|
|
889
956
|
for (const declaration of declarationsOf(input.checker, symbol)) {
|
|
@@ -894,8 +961,11 @@ export const censusReachability = (input) => {
|
|
|
894
961
|
if (imported && ts.isImportDeclaration(imported)) {
|
|
895
962
|
const module = input.checker.getSymbolAtLocation(imported.moduleSpecifier);
|
|
896
963
|
for (const target of module?.declarations ?? [])
|
|
897
|
-
if (ts.isSourceFile(target))
|
|
964
|
+
if (ts.isSourceFile(target)) {
|
|
898
965
|
fileQueue.push(target);
|
|
966
|
+
if (constructionUse && ts.isNamespaceImport(declaration))
|
|
967
|
+
exposeNamespace(target);
|
|
968
|
+
}
|
|
899
969
|
}
|
|
900
970
|
// Reading an imported binding needs the imported module. The alias's
|
|
901
971
|
// declaration does not execute every statement in its containing file.
|
|
@@ -909,13 +979,24 @@ export const censusReachability = (input) => {
|
|
|
909
979
|
owner = owner.parent;
|
|
910
980
|
if (owner && (ts.isInterfaceDeclaration(owner) || ts.isTypeAliasDeclaration(owner)))
|
|
911
981
|
continue;
|
|
982
|
+
if (ts.isNamespaceExport(declaration) && ts.isExportDeclaration(declaration.parent) && declaration.parent.moduleSpecifier) {
|
|
983
|
+
const module = input.checker.getSymbolAtLocation(declaration.parent.moduleSpecifier);
|
|
984
|
+
for (const target of module?.declarations ?? [])
|
|
985
|
+
if (ts.isSourceFile(target))
|
|
986
|
+
exposeNamespace(target);
|
|
987
|
+
continue;
|
|
988
|
+
}
|
|
912
989
|
if (ts.isSourceFile(declaration)) {
|
|
913
990
|
fileQueue.push(declaration);
|
|
991
|
+
if (constructionUse)
|
|
992
|
+
exposeNamespace(declaration);
|
|
914
993
|
continue;
|
|
915
994
|
}
|
|
916
995
|
const file = declaration.getSourceFile();
|
|
917
996
|
if (!compiled.has(file))
|
|
918
997
|
continue;
|
|
998
|
+
if (constructionUse && ts.isClassDeclaration(declaration))
|
|
999
|
+
markConstructed(declaration);
|
|
919
1000
|
let memberOwner = declaration.parent;
|
|
920
1001
|
while (memberOwner && !ts.isSourceFile(memberOwner) && !ts.isClassDeclaration(memberOwner))
|
|
921
1002
|
memberOwner = memberOwner.parent;
|
|
@@ -942,7 +1023,12 @@ export const censusReachability = (input) => {
|
|
|
942
1023
|
openStatement(current);
|
|
943
1024
|
}
|
|
944
1025
|
};
|
|
945
|
-
const markReference = (reference) =>
|
|
1026
|
+
const markReference = (reference) => {
|
|
1027
|
+
const parent = reference.parent;
|
|
1028
|
+
const declarationName = ts.isClassDeclaration(parent) && parent.name === reference;
|
|
1029
|
+
const simpleHeritage = ts.isExpressionWithTypeArguments(parent) && parent.expression === reference && ts.isHeritageClause(parent.parent);
|
|
1030
|
+
markSymbol(input.checker.getSymbolAtLocation(reference), !declarationName && !simpleHeritage);
|
|
1031
|
+
};
|
|
946
1032
|
/**
|
|
947
1033
|
* A member READ on a receiver typed as a class keeps that class's
|
|
948
1034
|
* definition, and only that.
|
|
@@ -1114,6 +1200,24 @@ export const censusReachability = (input) => {
|
|
|
1114
1200
|
}
|
|
1115
1201
|
return;
|
|
1116
1202
|
}
|
|
1203
|
+
// Class expressions retain their existing conservative constructor bodies
|
|
1204
|
+
// and construct recipes. Their implicit or explicit super frame therefore
|
|
1205
|
+
// still requires the base construction convention, even though evaluating
|
|
1206
|
+
// a named class declaration alone does not construct its base.
|
|
1207
|
+
if (ts.isClassExpression(node))
|
|
1208
|
+
for (const clause of node.heritageClauses ?? []) {
|
|
1209
|
+
if (clause.token === ts.SyntaxKind.ExtendsKeyword)
|
|
1210
|
+
for (const base of clause.types)
|
|
1211
|
+
markConstruction(base.expression);
|
|
1212
|
+
}
|
|
1213
|
+
if (ts.isConstructorDeclaration(node) && ts.isClassDeclaration(node.parent) && !constructedClasses.has(node.parent))
|
|
1214
|
+
return;
|
|
1215
|
+
if (ts.isPropertyDeclaration(node.parent) &&
|
|
1216
|
+
node.parent.initializer === node &&
|
|
1217
|
+
ts.isClassDeclaration(node.parent.parent) &&
|
|
1218
|
+
!memberIsStatic(node.parent) &&
|
|
1219
|
+
!constructedClasses.has(node.parent.parent))
|
|
1220
|
+
return;
|
|
1117
1221
|
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node) || ts.isImportEqualsDeclaration(node))
|
|
1118
1222
|
return;
|
|
1119
1223
|
if (ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node))
|
|
@@ -1135,6 +1239,7 @@ export const censusReachability = (input) => {
|
|
|
1135
1239
|
if (ts.isPropertyAccessExpression(node))
|
|
1136
1240
|
openClassOfReceiver(node);
|
|
1137
1241
|
if (ts.isNewExpression(node)) {
|
|
1242
|
+
markConstruction(node.expression);
|
|
1138
1243
|
for (const signature of input.checker.getTypeAtLocation(node.expression).getConstructSignatures()) {
|
|
1139
1244
|
const result = input.checker.getReturnTypeOfSignature(signature);
|
|
1140
1245
|
for (const arm of result.isUnion() ? result.types : [result]) {
|
|
@@ -1290,6 +1395,7 @@ export const censusReachability = (input) => {
|
|
|
1290
1395
|
const reached = new Map();
|
|
1291
1396
|
return {
|
|
1292
1397
|
classIsLayoutOnly: (node) => layoutClasses.has(node),
|
|
1398
|
+
classConstructionIsReachable: (node) => constructedClasses.has(node),
|
|
1293
1399
|
memberIsPruned: (node) => {
|
|
1294
1400
|
if (deferredMembers.has(node) && !liveMembers.has(node))
|
|
1295
1401
|
return true;
|
|
@@ -1298,12 +1404,14 @@ export const censusReachability = (input) => {
|
|
|
1298
1404
|
return false;
|
|
1299
1405
|
if (ts.isHeritageClause(node) && ts.isClassDeclaration(parent) && layoutClasses.has(parent))
|
|
1300
1406
|
return true;
|
|
1301
|
-
if (
|
|
1407
|
+
if (ts.isConstructorDeclaration(node) && ts.isClassDeclaration(parent))
|
|
1408
|
+
return layoutClasses.has(parent) || !constructedClasses.has(parent);
|
|
1409
|
+
if (ts.isClassStaticBlockDeclaration(node) && ts.isClassDeclaration(parent))
|
|
1302
1410
|
return layoutClasses.has(parent);
|
|
1303
1411
|
return (ts.isPropertyDeclaration(parent) &&
|
|
1304
1412
|
parent.initializer === node &&
|
|
1305
1413
|
ts.isClassDeclaration(parent.parent) &&
|
|
1306
|
-
layoutClasses.has(parent.parent));
|
|
1414
|
+
(layoutClasses.has(parent.parent) || (!memberIsStatic(parent) && !constructedClasses.has(parent.parent))));
|
|
1307
1415
|
},
|
|
1308
1416
|
statementsOf: (file) => {
|
|
1309
1417
|
const known = reached.get(file);
|
|
@@ -1047,7 +1047,7 @@ moduleRecords = emptyCommonJsModuleRecordCensus) => {
|
|
|
1047
1047
|
* into a slot whose every signature returns a type the operand already is:
|
|
1048
1048
|
* the assertion changes only the checker's view, so the function returns
|
|
1049
1049
|
* the operand's own type, exactly as `physicalAssertionReturns` reads an
|
|
1050
|
-
* `as unknown as T` past its assertion.
|
|
1050
|
+
* `as unknown as T` past its assertion. An HTTP framework's constructor installs
|
|
1051
1051
|
* `this[method] = (...) => { ...; return this as any }` under overloaded
|
|
1052
1052
|
* `HandlerInterface`s that all return the app; laid out as `any`, each
|
|
1053
1053
|
* return boxed the app and published its whole router to dynamic code.
|
|
@@ -1067,8 +1067,8 @@ moduleRecords = emptyCommonJsModuleRecordCensus) => {
|
|
|
1067
1067
|
if (signatures.every((signature) => checker.isTypeAssignableTo(operand, checker.getReturnTypeOfSignature(signature))))
|
|
1068
1068
|
return operand;
|
|
1069
1069
|
// The slot's signatures may name the operand's own class at other type
|
|
1070
|
-
// arguments --
|
|
1071
|
-
// while `this` is `
|
|
1070
|
+
// arguments -- an HTTP framework's return `AppBase<E, S & ToSchema<...>, BasePath>`
|
|
1071
|
+
// while `this` is `AppBase<E, S, BasePath>`, which is why the source
|
|
1072
1072
|
// needed the assertion at all. The value is still that one instance of
|
|
1073
1073
|
// that one class; the type arguments are the checker's bookkeeping.
|
|
1074
1074
|
const instance = checker.getApparentType(operand);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import type { StructuralTypeId } from '../../identity/ids.js';
|
|
3
|
+
import type { NativeIterableProvider } from '../../plugins/native-iterable-providers.js';
|
|
4
|
+
import type { ProducerContext } from './producer-context.js';
|
|
5
|
+
import type { ValueFlowIndex } from './flow/model.js';
|
|
6
|
+
import { type SourceNativeIterableIntegrity } from './flow/source-native-iterable-integrity.js';
|
|
7
|
+
/** The native factory is selected only after its real source method, typed
|
|
8
|
+
* standard cursor result and complete mutation/effect inventory agree.
|
|
9
|
+
* @semanticCategory generic-primitive
|
|
10
|
+
*/
|
|
11
|
+
export interface SourceNativeIterable {
|
|
12
|
+
readonly source: ts.Expression;
|
|
13
|
+
readonly method: ts.Symbol;
|
|
14
|
+
readonly provider: NativeIterableProvider;
|
|
15
|
+
readonly iteratorType: StructuralTypeId;
|
|
16
|
+
readonly elementType: StructuralTypeId;
|
|
17
|
+
readonly integrity: SourceNativeIterableIntegrity;
|
|
18
|
+
}
|
|
19
|
+
export declare const sourceNativeIterableOf: (context: ProducerContext, flow: ValueFlowIndex, providers: ReadonlyMap<string, NativeIterableProvider>, source: ts.Expression, consumer: ts.CallExpression | null) => SourceNativeIterable | null;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { sourceNativeOriginIsClosed } from './flow/source-native-origin.js';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
import { sourceNativeIterableIntegrityOf } from './flow/source-native-iterable-integrity.js';
|
|
4
|
+
import { iteratorMethodSymbolOf } from './producers/iteration-yield.js';
|
|
5
|
+
import { unwrapErasedExpression } from './producers/erasure.js';
|
|
6
|
+
import { intrinsicStaticMemberIsIntact } from './intrinsic-static-member.js';
|
|
7
|
+
import { isStandardGlobalValue } from './derived-expression-type.js';
|
|
8
|
+
export const sourceNativeIterableOf = (context, flow, providers, source, consumer) => {
|
|
9
|
+
const { checker } = context;
|
|
10
|
+
const nativeCarrierOf = (type, at) => {
|
|
11
|
+
const symbol = type.getSymbol();
|
|
12
|
+
if (!symbol)
|
|
13
|
+
return null;
|
|
14
|
+
const id = context.identities.symbolDeclarationId(symbol, at);
|
|
15
|
+
return id === null ? null : (context.hostProtocols.get(id)?.native ?? null);
|
|
16
|
+
};
|
|
17
|
+
if (!sourceNativeOriginIsClosed(checker, flow, source, (node) => {
|
|
18
|
+
if (!ts.isIdentifier(node))
|
|
19
|
+
return false;
|
|
20
|
+
const symbol = checker.getSymbolAtLocation(node);
|
|
21
|
+
if (!symbol)
|
|
22
|
+
return false;
|
|
23
|
+
const declaration = context.identities.symbolValueDeclarationId(symbol, node);
|
|
24
|
+
return declaration !== null && context.hostSingletonBindings.has(declaration);
|
|
25
|
+
}))
|
|
26
|
+
return null;
|
|
27
|
+
const raw = context.types.rawTypeAt(unwrapErasedExpression(source));
|
|
28
|
+
const native = nativeCarrierOf(raw, source);
|
|
29
|
+
const provider = native === null ? undefined : providers.get(native);
|
|
30
|
+
if (!provider || context.arrayIteratorDeclaration === null)
|
|
31
|
+
return null;
|
|
32
|
+
const method = iteratorMethodSymbolOf(raw);
|
|
33
|
+
if (!method?.declarations?.length)
|
|
34
|
+
return null;
|
|
35
|
+
// A user augmentation or source method cannot inherit a provider's ABI.
|
|
36
|
+
if (!method.declarations.every((declaration) => declaration.getSourceFile().isDeclarationFile))
|
|
37
|
+
return null;
|
|
38
|
+
const signatures = checker.getTypeOfSymbolAtLocation(method, source).getCallSignatures();
|
|
39
|
+
if (signatures.length !== 1 || signatures[0].parameters.length !== 0 || signatures[0].typeParameters?.length)
|
|
40
|
+
return null;
|
|
41
|
+
const returned = signatures[0].getReturnType();
|
|
42
|
+
const returnedSymbol = returned.getSymbol();
|
|
43
|
+
if (!returnedSymbol || context.identities.symbolDeclarationId(returnedSymbol, source) !== context.arrayIteratorDeclaration)
|
|
44
|
+
return null;
|
|
45
|
+
if ((returned.flags & ts.TypeFlags.Object) === 0 || (returned.objectFlags & ts.ObjectFlags.Reference) === 0)
|
|
46
|
+
return null;
|
|
47
|
+
const arguments_ = checker.getTypeArguments(returned);
|
|
48
|
+
if (arguments_.length !== 1)
|
|
49
|
+
return null;
|
|
50
|
+
const readOnlyCalls = new Set();
|
|
51
|
+
if (consumer !== null) {
|
|
52
|
+
const callee = unwrapErasedExpression(consumer.expression);
|
|
53
|
+
// Mapper callbacks need their own closed invocation/effect authority.
|
|
54
|
+
if (consumer.arguments.length !== 1)
|
|
55
|
+
return null;
|
|
56
|
+
if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== 'from' || consumer.arguments[0] !== source)
|
|
57
|
+
return null;
|
|
58
|
+
const owner = checker.getSymbolAtLocation(callee.expression), member = checker.getSymbolAtLocation(callee.name);
|
|
59
|
+
if (!isStandardGlobalValue(checker, callee.expression, 'Array') || !intrinsicStaticMemberIsIntact(context, owner, member, consumer))
|
|
60
|
+
return null;
|
|
61
|
+
readOnlyCalls.add(consumer);
|
|
62
|
+
}
|
|
63
|
+
const integrity = sourceNativeIterableIntegrityOf(checker, flow, source, provider, nativeCarrierOf, readOnlyCalls);
|
|
64
|
+
if (!integrity)
|
|
65
|
+
return null;
|
|
66
|
+
return {
|
|
67
|
+
source,
|
|
68
|
+
method,
|
|
69
|
+
provider,
|
|
70
|
+
integrity,
|
|
71
|
+
iteratorType: context.types.typeOf(returned),
|
|
72
|
+
elementType: context.types.typeOf(arguments_[0])
|
|
73
|
+
};
|
|
74
|
+
};
|
|
@@ -7,7 +7,7 @@ import type { SpecializationCensus } from './specialization.js';
|
|
|
7
7
|
* A `const` whose stated type leaves positions open (`Matcher<any>`) and whose
|
|
8
8
|
* every use hands it, whole, to one concrete slot is laid out as that slot.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* A regular-expression router states `const nullMatcher: Matcher<any> = [/^$/, [],
|
|
11
11
|
* Object.create(null)]` and only ever `return`s it from
|
|
12
12
|
* `buildMatcherFromPreprocessedRoutes<T>(): Matcher<T>`. Laid out as written,
|
|
13
13
|
* the binding is a record of arrays of `[any, ParamIndexMap]` tuples that the
|
|
@@ -355,7 +355,7 @@ export const physicalInitializerTypeOf = (checker, declaration, declared, parame
|
|
|
355
355
|
// RETURN (`structural.ts` rebuilds the callable shape from the literal's
|
|
356
356
|
// own signature for exactly that reason, and `signatureOf` reads the bound
|
|
357
357
|
// return through it). Taking that answer as the literal's type made a
|
|
358
|
-
// member whose arrow had a settled return --
|
|
358
|
+
// member whose arrow had a settled return -- an HTTP framework's `this[method] = (...)
|
|
359
359
|
// => { ...; return this as any }` -- look non-callable, and the member fell
|
|
360
360
|
// back to its overload set's `callable-identity`.
|
|
361
361
|
const censused = censusedTypeAt(checker, parameters, initializer);
|
|
@@ -90,6 +90,15 @@ export const indexedAccessMemberTypes = (checker, objectType, indexType) => {
|
|
|
90
90
|
if (numberIndex)
|
|
91
91
|
return [numberIndex.type];
|
|
92
92
|
}
|
|
93
|
+
// An index-only dictionary has no named keys to enumerate. Its declared
|
|
94
|
+
// string index is the answer to a broad string read, just as the number
|
|
95
|
+
// index above answers a broad number read. Match that domain explicitly;
|
|
96
|
+
// a numeric or patterned index does not authorize arbitrary string keys.
|
|
97
|
+
if ((indexType.flags & ts.TypeFlags.String) !== 0) {
|
|
98
|
+
const stringIndex = checker.getIndexInfosOfType(objectType).find((info) => (info.keyType.flags & ts.TypeFlags.String) !== 0);
|
|
99
|
+
if (stringIndex)
|
|
100
|
+
return [stringIndex.type];
|
|
101
|
+
}
|
|
93
102
|
const keys = keysOf(checker, objectType, indexType);
|
|
94
103
|
if (keys === null)
|
|
95
104
|
return null;
|
|
@@ -3475,6 +3475,17 @@ const buildMapper = (checker, identities, table, instantiations, specializations
|
|
|
3475
3475
|
if ((shape.kind === 'declared' || shape.kind === 'class-instance') && shape.body !== null)
|
|
3476
3476
|
return valueIdOfShape(table.get(shape.body).shape);
|
|
3477
3477
|
if (shape.kind === 'object' && !shape.membersDropped) {
|
|
3478
|
+
// A declared-any string dictionary may own an accessor installed under
|
|
3479
|
+
// a runtime key. Its index value is not proof that every own property
|
|
3480
|
+
// is a data descriptor. Retain the ambient descriptor's real optional
|
|
3481
|
+
// callable halves rather than minting a record that erases get/set.
|
|
3482
|
+
const soleIndex = shape.index.length === 1 ? shape.index[0] : undefined;
|
|
3483
|
+
const indexedValue = soleIndex === undefined ? null : table.get(soleIndex.value).shape;
|
|
3484
|
+
if (shape.members.length === 0 &&
|
|
3485
|
+
soleIndex?.key === 'string' &&
|
|
3486
|
+
indexedValue?.kind === 'primitive' &&
|
|
3487
|
+
indexedValue.primitive === 'any')
|
|
3488
|
+
return null;
|
|
3478
3489
|
// An accessor member's descriptor is an ACCESSOR descriptor: `get` and
|
|
3479
3490
|
// `set`, no `value`. The data-descriptor record minted below has no
|
|
3480
3491
|
// field for either, so a shape that may answer with one keeps the
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
+
import { type FreshValueKind } from './fresh-table-last-use.js';
|
|
2
3
|
/**
|
|
3
4
|
* The method body a member call runs when it returns an array NO OTHER
|
|
4
5
|
* REFERENCE holds: every `return` hands back an array literal, or a local
|
|
@@ -30,3 +31,44 @@ import ts from 'typescript';
|
|
|
30
31
|
* write, would run a different body the proof never saw.
|
|
31
32
|
*/
|
|
32
33
|
export declare const unsharedArrayResultBodyOf: (checker: ts.TypeChecker, node: ts.CallExpression) => ts.MethodDeclaration | null;
|
|
34
|
+
/**
|
|
35
|
+
* A formal parameter of `callee` that the body only READS as an array: it
|
|
36
|
+
* measures it, indexes it, iterates it and calls reading members on it. It
|
|
37
|
+
* never stores through it, stores IT anywhere, compares it by identity,
|
|
38
|
+
* captures it in a closure, or hands it to another call. `arguments` would
|
|
39
|
+
* alias it, so a body naming `arguments` refuses. So does a generator or an
|
|
40
|
+
* `async` body, which keeps running after the call returned, when the
|
|
41
|
+
* caller's array may already have changed.
|
|
42
|
+
*
|
|
43
|
+
* This is the callee half of a call argument's unshared copy
|
|
44
|
+
* (`unsharedArrayArgumentAt`): such a formal cannot observe whether it holds
|
|
45
|
+
* the caller's array or an element-wise copy of it.
|
|
46
|
+
*/
|
|
47
|
+
export declare const readOnlyArrayFormalOf: (checker: ts.TypeChecker, callee: ts.SignatureDeclaration, index: number) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* An array as `fresh-table-last-use.ts` proves objects unshared: an array
|
|
50
|
+
* literal is the allocation, and a use that fills, measures, indexes,
|
|
51
|
+
* iterates or reads it through a reading member hands no reference to it
|
|
52
|
+
* anywhere.
|
|
53
|
+
*/
|
|
54
|
+
export declare const arrayKind: (checker: ts.TypeChecker) => FreshValueKind;
|
|
55
|
+
/**
|
|
56
|
+
* `return local`: the local array's last use (`isFreshOrLastUseOfFreshLocal`
|
|
57
|
+
* over `arrayKind`), so its one holder dies here and the returned array
|
|
58
|
+
* may be rebuilt at the declared carrier (`SemanticOperand.unsharedFreshArray`).
|
|
59
|
+
* A literal returned directly already takes the slot's carrier from its own
|
|
60
|
+
* allocation, so only the local form is asked.
|
|
61
|
+
*/
|
|
62
|
+
export declare const unsharedReturnedArray: (checker: ts.TypeChecker, statement: ts.ReturnStatement) => boolean;
|
|
63
|
+
/** The one body a call runs, and the formal an argument binds; `null` without an exact target proof. */
|
|
64
|
+
export type ArgumentFormalOf = (call: ts.CallExpression, argument: ts.Expression) => {
|
|
65
|
+
callee: ts.SignatureDeclaration;
|
|
66
|
+
index: number;
|
|
67
|
+
} | null;
|
|
68
|
+
/**
|
|
69
|
+
* `callee(local)` where `local` is unshared (`unsharedLocalArrayOf`) and the
|
|
70
|
+
* formal it binds is read only (`readOnlyArrayFormalOf`)
|
|
71
|
+
* (`SemanticOperand.readOnlyArrayArgument`). `formalOf` is asked of every call
|
|
72
|
+
* the local is passed to, so each of them must be read only too.
|
|
73
|
+
*/
|
|
74
|
+
export declare const readOnlyArrayArgumentAt: (checker: ts.TypeChecker, argument: ts.Expression, formalOf: ArgumentFormalOf) => boolean;
|