@geastack/compiler 1.0.20 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-emit.js +11 -1
- package/dist/cli-package-source.d.ts +0 -4
- package/dist/cli-package-source.js +8 -112
- package/dist/cli-refusal-location.d.ts +6 -0
- package/dist/cli-refusal-location.js +5 -0
- package/dist/cli.js +2 -1
- package/dist/compiler.d.ts +4 -0
- package/dist/compiler.js +120 -29
- package/dist/conversion/algebra.d.ts +16 -1
- package/dist/conversion/algebra.js +2 -0
- package/dist/conversion/build.d.ts +12 -0
- package/dist/conversion/build.js +31 -6
- package/dist/conversion/constructor-identity-family.d.ts +49 -0
- package/dist/conversion/constructor-identity-family.js +67 -0
- package/dist/conversion/derive.js +39 -6
- package/dist/conversion/iterable-object-view.d.ts +44 -0
- package/dist/conversion/iterable-object-view.js +55 -0
- package/dist/conversion/iterator-object-view.d.ts +77 -0
- package/dist/conversion/iterator-object-view.js +112 -0
- package/dist/conversion/nodes.d.ts +93 -0
- package/dist/conversion/nodes.js +262 -5
- package/dist/conversion/operand-view.js +41 -0
- package/dist/conversion/protocol-iterator.d.ts +84 -0
- package/dist/conversion/protocol-iterator.js +88 -0
- package/dist/conversion/record-view.d.ts +152 -8
- package/dist/conversion/record-view.js +518 -37
- package/dist/conversion/registry.d.ts +32 -0
- package/dist/ir/borrowed-call-arguments.d.ts +22 -1
- package/dist/ir/borrowed-call-arguments.js +102 -1
- package/dist/ir/borrowed-callable-uses.d.ts +62 -0
- package/dist/ir/borrowed-callable-uses.js +135 -0
- package/dist/ir/boxed-bind-assumptions.d.ts +24 -0
- package/dist/ir/boxed-bind-assumptions.js +93 -0
- package/dist/ir/build.d.ts +18 -7
- package/dist/ir/build.js +71 -13
- package/dist/ir/call-dispatch.js +474 -10
- package/dist/ir/call-entry.d.ts +24 -1
- package/dist/ir/call-entry.js +106 -1
- package/dist/ir/callable-class-flow.d.ts +3 -1
- package/dist/ir/callable-class-flow.js +42 -6
- package/dist/ir/callable-identity-demand.d.ts +20 -1
- package/dist/ir/callable-identity-demand.js +157 -18
- package/dist/ir/callable-member-candidates.d.ts +11 -1
- package/dist/ir/callable-member-candidates.js +82 -3
- package/dist/ir/callable-records.js +2 -2
- package/dist/ir/callable-site-escape.d.ts +4 -0
- package/dist/ir/callable-site-escape.js +228 -0
- package/dist/ir/captures.d.ts +10 -1
- package/dist/ir/captures.js +219 -4
- package/dist/ir/certificate.js +87 -16
- package/dist/ir/certify/carrier-keys.d.ts +58 -1
- package/dist/ir/certify/carrier-keys.js +160 -6
- package/dist/ir/certify/property-access-keys.d.ts +17 -0
- package/dist/ir/certify/property-access-keys.js +36 -0
- package/dist/ir/certify/property-access.js +49 -4
- package/dist/ir/certify/runtime-helper.d.ts +4 -0
- package/dist/ir/certify/runtime-helper.js +17 -5
- package/dist/ir/certify.js +132 -79
- package/dist/ir/class-static-fields.d.ts +11 -0
- package/dist/ir/class-static-fields.js +28 -0
- package/dist/ir/construct-entry.d.ts +2 -1
- package/dist/ir/construct-entry.js +3 -2
- package/dist/ir/construction-only-fields.d.ts +73 -0
- package/dist/ir/construction-only-fields.js +211 -0
- package/dist/ir/dominance.d.ts +14 -0
- package/dist/ir/dominance.js +18 -4
- package/dist/ir/emission-representations.js +4 -1
- package/dist/ir/exception-edges.d.ts +17 -0
- package/dist/ir/exception-edges.js +75 -0
- package/dist/ir/facts.d.ts +54 -3
- package/dist/ir/facts.js +182 -5
- package/dist/ir/generator-split.js +2 -2
- package/dist/ir/instance-reparenting.d.ts +83 -0
- package/dist/ir/instance-reparenting.js +167 -0
- package/dist/ir/integer-storage.d.ts +29 -0
- package/dist/ir/integer-storage.js +188 -79
- package/dist/ir/integers.d.ts +16 -0
- package/dist/ir/integers.js +327 -8
- package/dist/ir/integrity-restrictions.d.ts +42 -9
- package/dist/ir/integrity-restrictions.js +335 -42
- package/dist/ir/key-order-observation.d.ts +38 -0
- package/dist/ir/key-order-observation.js +173 -0
- package/dist/ir/literal-set-membership.d.ts +30 -0
- package/dist/ir/literal-set-membership.js +277 -0
- package/dist/ir/lower-allocation.js +68 -8
- package/dist/ir/lower-completion.d.ts +0 -9
- package/dist/ir/lower-completion.js +14 -5
- package/dist/ir/lower-destructuring.js +24 -2
- package/dist/ir/lower-exceptions.js +4 -4
- package/dist/ir/lower-flow.d.ts +21 -0
- package/dist/ir/lower-flow.js +37 -3
- package/dist/ir/lower-graph.d.ts +19 -1
- package/dist/ir/lower-graph.js +91 -67
- package/dist/ir/lower-invocation.d.ts +16 -0
- package/dist/ir/lower-invocation.js +189 -29
- package/dist/ir/lower-narrow.d.ts +0 -46
- package/dist/ir/lower-narrow.js +63 -1
- package/dist/ir/lower-operands.d.ts +52 -2
- package/dist/ir/lower-operands.js +491 -8
- package/dist/ir/lower-property.d.ts +2 -1
- package/dist/ir/lower-property.js +140 -31
- package/dist/ir/lower-protocol.js +16 -4
- package/dist/ir/lower-proxy.d.ts +65 -0
- package/dist/ir/lower-proxy.js +181 -0
- package/dist/ir/lower.js +112 -17
- package/dist/ir/model.d.ts +228 -18
- package/dist/ir/native-class-accessor.d.ts +9 -2
- package/dist/ir/native-class-accessor.js +12 -3
- package/dist/ir/native-class-construction.d.ts +1 -1
- package/dist/ir/native-class-construction.js +2 -1
- package/dist/ir/native-class-initialization.js +2 -2
- package/dist/ir/object-value-conversions.js +20 -5
- package/dist/ir/operation-index.d.ts +16 -0
- package/dist/ir/operation-index.js +17 -0
- package/dist/ir/pcm-loops.d.ts +11 -0
- package/dist/ir/pcm-loops.js +284 -0
- package/dist/ir/presence-proof.js +5 -0
- package/dist/ir/program-facts.d.ts +10 -20
- package/dist/ir/program-facts.js +80 -6
- package/dist/ir/proven-branches.d.ts +2 -2
- package/dist/ir/proven-branches.js +198 -3
- package/dist/ir/queries.js +35 -1
- package/dist/ir/reflection-demand.d.ts +9 -4
- package/dist/ir/reflection-demand.js +410 -28
- package/dist/ir/refusal.d.ts +1 -0
- package/dist/ir/refusal.js +2 -1
- package/dist/ir/shake.d.ts +94 -1
- package/dist/ir/shake.js +209 -12
- package/dist/ir/shared-empty-records.d.ts +12 -0
- package/dist/ir/shared-empty-records.js +301 -0
- package/dist/ir/spread-copy-elision.d.ts +59 -0
- package/dist/ir/spread-copy-elision.js +431 -0
- package/dist/ir/stable-cell-reads.d.ts +40 -0
- package/dist/ir/stable-cell-reads.js +123 -0
- package/dist/ir/static-callables.js +50 -0
- package/dist/ir/string-layout-reuse.d.ts +16 -1
- package/dist/ir/string-layout-reuse.js +66 -0
- package/dist/ir/transfer.d.ts +72 -3
- package/dist/ir/transfer.js +511 -19
- package/dist/ir/typed-property-access.d.ts +18 -2
- package/dist/ir/typed-property-access.js +109 -12
- package/dist/ir/verify.js +2 -1
- package/dist/plugins/apple/plugin.js +3 -2
- package/dist/plugins/gea/host.d.ts +7 -0
- package/dist/plugins/gea/host.js +30 -1
- package/dist/plugins/gea/lower.js +6 -1
- package/dist/plugins/gea/plugin.js +7 -4
- package/dist/plugins/gea/render-bridge.d.ts +4 -2
- package/dist/plugins/gea/render-bridge.js +23 -7
- package/dist/plugins/model.d.ts +2 -0
- package/dist/project-preparation.d.ts +5 -1
- package/dist/project-preparation.js +184 -7
- package/dist/projection/bindings.d.ts +5 -2
- package/dist/projection/bindings.js +40 -1
- package/dist/projection/callee.d.ts +16 -0
- package/dist/projection/callee.js +35 -6
- package/dist/projection/class-prototype.js +5 -1
- package/dist/projection/classes.d.ts +65 -2
- package/dist/projection/classes.js +159 -2
- package/dist/projection/dispatch.d.ts +69 -18
- package/dist/projection/dispatch.js +391 -19
- package/dist/projection/fields.d.ts +4 -3
- package/dist/projection/fields.js +89 -21
- package/dist/projection/instance-test.d.ts +12 -0
- package/dist/projection/instance-test.js +40 -10
- package/dist/projection/method-value-escapes.d.ts +43 -0
- package/dist/projection/method-value-escapes.js +113 -0
- package/dist/projection/slots.d.ts +34 -1
- package/dist/projection/slots.js +82 -5
- package/dist/representation/any-null-record-members.d.ts +41 -0
- package/dist/representation/any-null-record-members.js +115 -0
- package/dist/representation/collections.d.ts +3 -1
- package/dist/representation/collections.js +5 -2
- package/dist/representation/derive.d.ts +9 -1
- package/dist/representation/derive.js +366 -25
- package/dist/representation/difference.js +14 -0
- package/dist/representation/embedded-carriers.js +1 -0
- package/dist/representation/host-abi.d.ts +15 -0
- package/dist/representation/host-abi.js +28 -0
- package/dist/representation/host-templates.d.ts +1 -1
- package/dist/representation/host-templates.js +7 -3
- package/dist/representation/intersection.js +22 -0
- package/dist/representation/json-nullable.d.ts +18 -0
- package/dist/representation/json-nullable.js +22 -0
- package/dist/representation/model.d.ts +141 -0
- package/dist/representation/model.js +47 -3
- package/dist/representation/object-shape.d.ts +5 -1
- package/dist/representation/object-shape.js +5 -2
- package/dist/representation/policies.d.ts +66 -1
- package/dist/representation/proxy-carriers.d.ts +71 -0
- package/dist/representation/proxy-carriers.js +330 -0
- package/dist/representation/publish.d.ts +9 -1
- package/dist/representation/publish.js +186 -18
- package/dist/representation/record-fields.d.ts +5 -0
- package/dist/representation/record-fields.js +7 -1
- package/dist/representation/static-field-cells.d.ts +61 -0
- package/dist/representation/static-field-cells.js +80 -0
- package/dist/representation/unassigned-binding-cells.d.ts +32 -0
- package/dist/representation/unassigned-binding-cells.js +44 -0
- package/dist/representation/union.js +17 -1
- package/dist/representation/unwritten-record-members.d.ts +54 -0
- package/dist/representation/unwritten-record-members.js +167 -0
- package/dist/representation/value-records.js +153 -11
- package/dist/semantics/ambient.d.ts +102 -0
- package/dist/semantics/ambient.js +183 -0
- package/dist/semantics/any-null-member-declarations.d.ts +32 -0
- package/dist/semantics/any-null-member-declarations.js +90 -0
- package/dist/semantics/borrowed-builtin-call-bind-source-transform.js +14 -0
- package/dist/semantics/borrowed-method-receiver-copy-source-transform.d.ts +51 -0
- package/dist/semantics/borrowed-method-receiver-copy-source-transform.js +367 -0
- package/dist/semantics/call-invalidated-narrowing.d.ts +3 -0
- package/dist/semantics/call-invalidated-narrowing.js +715 -0
- package/dist/semantics/callable-origins.d.ts +39 -0
- package/dist/semantics/callable-origins.js +73 -2
- package/dist/semantics/class-alias.d.ts +36 -0
- package/dist/semantics/class-alias.js +64 -14
- package/dist/semantics/class-heritage.d.ts +64 -0
- package/dist/semantics/class-heritage.js +278 -2
- package/dist/semantics/commonjs-wrapper.d.ts +1 -1
- package/dist/semantics/commonjs-wrapper.js +24 -7
- package/dist/semantics/constructor-function-class-source-transform.d.ts +4 -0
- package/dist/semantics/constructor-function-class-source-transform.js +327 -0
- package/dist/semantics/constructor-slot-subclasses.js +163 -4
- package/dist/semantics/declaration-overlay-transform.js +197 -3
- package/dist/semantics/frontend.d.ts +31 -0
- package/dist/semantics/frontend.js +212 -26
- package/dist/semantics/host-methods.d.ts +27 -2
- package/dist/semantics/host-methods.js +57 -4
- package/dist/semantics/host-protocols.d.ts +19 -8
- package/dist/semantics/host-protocols.js +145 -31
- package/dist/semantics/interface-families.d.ts +51 -2
- package/dist/semantics/interface-families.js +609 -23
- package/dist/semantics/interface-implementors.d.ts +20 -0
- package/dist/semantics/interface-implementors.js +130 -6
- package/dist/semantics/known-caller-predicate-parameters.d.ts +2 -0
- package/dist/semantics/known-caller-predicate-parameters.js +161 -0
- package/dist/semantics/model/intrinsic-accessor-getters.d.ts +10 -0
- package/dist/semantics/model/intrinsic-accessor-getters.js +4 -0
- package/dist/semantics/model/operands.d.ts +10 -0
- package/dist/semantics/model/operations.d.ts +107 -0
- package/dist/semantics/model/selected-signature.d.ts +33 -0
- package/dist/semantics/model/structural-type-table.d.ts +15 -0
- package/dist/semantics/model/structural-type-table.js +19 -1
- package/dist/semantics/model/structural-types.d.ts +99 -0
- package/dist/semantics/model/structural-types.js +31 -2
- package/dist/semantics/normalize/absent-globals.d.ts +1 -1
- package/dist/semantics/normalize/absent-globals.js +3 -3
- package/dist/semantics/normalize/bivariant-slot-parameter.d.ts +46 -0
- package/dist/semantics/normalize/bivariant-slot-parameter.js +372 -0
- package/dist/semantics/normalize/callback-parameter-contracts.d.ts +2 -0
- package/dist/semantics/normalize/callback-parameter-contracts.js +21 -0
- package/dist/semantics/normalize/census.d.ts +2 -1
- package/dist/semantics/normalize/census.js +25 -2
- package/dist/semantics/normalize/class-instance-record-statement.d.ts +37 -0
- package/dist/semantics/normalize/class-instance-record-statement.js +74 -0
- package/dist/semantics/normalize/collection-bindings.js +242 -5
- package/dist/semantics/normalize/commonjs-require.d.ts +35 -5
- package/dist/semantics/normalize/commonjs-require.js +464 -147
- package/dist/semantics/normalize/dead-event-emissions.d.ts +6 -0
- package/dist/semantics/normalize/dead-event-emissions.js +866 -0
- package/dist/semantics/normalize/dead-method-copies.d.ts +56 -0
- package/dist/semantics/normalize/dead-method-copies.js +239 -0
- package/dist/semantics/normalize/derived-expression-type.d.ts +149 -2
- package/dist/semantics/normalize/derived-expression-type.js +418 -14
- package/dist/semantics/normalize/field-bindings.js +139 -4
- package/dist/semantics/normalize/flow/callable-reach.js +162 -9
- package/dist/semantics/normalize/flow/member-call-forwarding.js +6 -0
- package/dist/semantics/normalize/flow/owned-class-receivers.js +40 -2
- package/dist/semantics/normalize/flow/source-class-data.d.ts +7 -1
- package/dist/semantics/normalize/flow/source-class-data.js +28 -9
- package/dist/semantics/normalize/flow/source-value-session.js +32 -13
- package/dist/semantics/normalize/flow/targets.d.ts +32 -0
- package/dist/semantics/normalize/flow/targets.js +65 -6
- package/dist/semantics/normalize/flow/value-flow.d.ts +7 -0
- package/dist/semantics/normalize/flow/value-flow.js +30 -2
- package/dist/semantics/normalize/fresh-array-result.d.ts +32 -0
- package/dist/semantics/normalize/fresh-array-result.js +125 -0
- package/dist/semantics/normalize/gating.js +2 -0
- package/dist/semantics/normalize/global-host-mutations.d.ts +11 -1
- package/dist/semantics/normalize/global-host-mutations.js +691 -27
- package/dist/semantics/normalize/host-effect-contracts.d.ts +43 -1
- package/dist/semantics/normalize/host-effect-contracts.js +60 -3
- package/dist/semantics/normalize/host-mutation-key-reader.js +35 -10
- package/dist/semantics/normalize/identities.js +64 -3
- package/dist/semantics/normalize/intrinsic-accessor-getter.d.ts +59 -0
- package/dist/semantics/normalize/intrinsic-accessor-getter.js +129 -0
- package/dist/semantics/normalize/local-bindings.js +117 -21
- package/dist/semantics/normalize/merged-declaration.d.ts +41 -0
- package/dist/semantics/normalize/merged-declaration.js +81 -0
- package/dist/semantics/normalize/never-override-result.d.ts +21 -0
- package/dist/semantics/normalize/never-override-result.js +64 -0
- package/dist/semantics/normalize/null-blind-parameter.d.ts +21 -0
- package/dist/semantics/normalize/null-blind-parameter.js +77 -0
- package/dist/semantics/normalize/object-bag-bindings.js +26 -2
- package/dist/semantics/normalize/omitted-stated-parameter.d.ts +1 -1
- package/dist/semantics/normalize/omitted-stated-parameter.js +34 -4
- package/dist/semantics/normalize/override-field-arms.d.ts +33 -0
- package/dist/semantics/normalize/override-field-arms.js +362 -0
- package/dist/semantics/normalize/parameter-bindings.d.ts +64 -1
- package/dist/semantics/normalize/parameter-bindings.js +827 -81
- package/dist/semantics/normalize/parameter-slot.d.ts +1 -0
- package/dist/semantics/normalize/parameter-slot.js +69 -0
- package/dist/semantics/normalize/physical-overload-result.d.ts +45 -0
- package/dist/semantics/normalize/physical-overload-result.js +132 -0
- package/dist/semantics/normalize/producer-context.d.ts +23 -0
- package/dist/semantics/normalize/producers/allocations.d.ts +13 -0
- package/dist/semantics/normalize/producers/allocations.js +8 -15
- package/dist/semantics/normalize/producers/binding-kind.d.ts +11 -0
- package/dist/semantics/normalize/producers/binding-kind.js +31 -0
- package/dist/semantics/normalize/producers/bindings.js +16 -1
- package/dist/semantics/normalize/producers/boundary.js +21 -1
- package/dist/semantics/normalize/producers/class-lifecycle.js +23 -14
- package/dist/semantics/normalize/producers/computations.js +8 -67
- package/dist/semantics/normalize/producers/control-loops.d.ts +1 -1
- package/dist/semantics/normalize/producers/control-loops.js +25 -1
- package/dist/semantics/normalize/producers/control.js +87 -60
- package/dist/semantics/normalize/producers/declaration-lifecycle.js +5 -0
- package/dist/semantics/normalize/producers/enums.d.ts +10 -0
- package/dist/semantics/normalize/producers/enums.js +169 -0
- package/dist/semantics/normalize/producers/erasure.d.ts +10 -0
- package/dist/semantics/normalize/producers/erasure.js +23 -0
- package/dist/semantics/normalize/producers/intrinsic-accessor-getter.d.ts +15 -0
- package/dist/semantics/normalize/producers/intrinsic-accessor-getter.js +33 -0
- package/dist/semantics/normalize/producers/invocations.js +255 -18
- package/dist/semantics/normalize/producers/iteration-yield.js +6 -1
- package/dist/semantics/normalize/producers/logical-merge-type.d.ts +36 -0
- package/dist/semantics/normalize/producers/logical-merge-type.js +163 -0
- package/dist/semantics/normalize/producers/properties.js +207 -18
- package/dist/semantics/normalize/producers/protocol.d.ts +4 -0
- package/dist/semantics/normalize/producers/protocol.js +147 -12
- package/dist/semantics/normalize/producers/references.js +50 -9
- package/dist/semantics/normalize/producers/shared.d.ts +120 -0
- package/dist/semantics/normalize/producers/shared.js +359 -10
- package/dist/semantics/normalize/producers/spread-arguments.js +85 -4
- package/dist/semantics/normalize/producers/tuple-spread.d.ts +1 -0
- package/dist/semantics/normalize/producers/tuple-spread.js +1 -1
- package/dist/semantics/normalize/property-key-domain.js +6 -0
- package/dist/semantics/normalize/reachability.d.ts +7 -0
- package/dist/semantics/normalize/reachability.js +166 -9
- package/dist/semantics/normalize/record-home-arms.d.ts +25 -0
- package/dist/semantics/normalize/record-home-arms.js +87 -0
- package/dist/semantics/normalize/record-link-families.d.ts +74 -0
- package/dist/semantics/normalize/record-link-families.js +327 -0
- package/dist/semantics/normalize/record-stand-in-arms.d.ts +56 -0
- package/dist/semantics/normalize/record-stand-in-arms.js +484 -0
- package/dist/semantics/normalize/return-bindings.d.ts +6 -2
- package/dist/semantics/normalize/return-bindings.js +60 -7
- package/dist/semantics/normalize/script-global-redefinition.js +5 -0
- package/dist/semantics/normalize/shared-array-storage.d.ts +42 -0
- package/dist/semantics/normalize/shared-array-storage.js +373 -0
- package/dist/semantics/normalize/sloppy-absence.d.ts +41 -0
- package/dist/semantics/normalize/sloppy-absence.js +199 -0
- package/dist/semantics/normalize/specialization.d.ts +40 -0
- package/dist/semantics/normalize/specialization.js +770 -36
- package/dist/semantics/normalize/structural-array-element.js +196 -6
- package/dist/semantics/normalize/structural-array-read.js +12 -0
- package/dist/semantics/normalize/structural-creation-order.d.ts +15 -0
- package/dist/semantics/normalize/structural-creation-order.js +51 -48
- package/dist/semantics/normalize/structural-declarations.d.ts +16 -0
- package/dist/semantics/normalize/structural-declarations.js +43 -0
- package/dist/semantics/normalize/structural-generics.d.ts +13 -0
- package/dist/semantics/normalize/structural-generics.js +22 -0
- package/dist/semantics/normalize/structural-indexed-access.js +16 -0
- package/dist/semantics/normalize/structural-instantiated-member.js +68 -2
- package/dist/semantics/normalize/structural-joins.js +2 -0
- package/dist/semantics/normalize/structural-layout-relevance.d.ts +30 -0
- package/dist/semantics/normalize/structural-layout-relevance.js +164 -0
- package/dist/semantics/normalize/structural-layout-type.js +270 -14
- package/dist/semantics/normalize/structural-leaves.d.ts +1 -1
- package/dist/semantics/normalize/structural-leaves.js +17 -3
- package/dist/semantics/normalize/structural-mutable-method.js +5 -1
- package/dist/semantics/normalize/structural-parts.d.ts +18 -5
- package/dist/semantics/normalize/structural-parts.js +68 -19
- package/dist/semantics/normalize/structural-receiver.d.ts +1 -1
- package/dist/semantics/normalize/structural-receiver.js +23 -1
- package/dist/semantics/normalize/structural-self-reference.d.ts +1 -1
- package/dist/semantics/normalize/structural-self-reference.js +23 -2
- package/dist/semantics/normalize/structural.d.ts +12 -1
- package/dist/semantics/normalize/structural.js +1437 -53
- package/dist/semantics/normalize/suppressed-write-arms.d.ts +47 -0
- package/dist/semantics/normalize/suppressed-write-arms.js +393 -0
- package/dist/semantics/normalize/unresolvable-names.d.ts +15 -2
- package/dist/semantics/normalize/unresolvable-names.js +30 -6
- package/dist/semantics/normalize/unshared-array-result.d.ts +32 -0
- package/dist/semantics/normalize/unshared-array-result.js +125 -0
- package/dist/semantics/package-sources.d.ts +1 -1
- package/dist/semantics/package-sources.js +120 -8
- package/dist/semantics/program.d.ts +20 -0
- package/dist/semantics/program.js +179 -26
- package/dist/semantics/shared-declaration-files.d.ts +44 -0
- package/dist/semantics/shared-declaration-files.js +42 -0
- package/dist/semantics/stable-checker.d.ts +1 -1
- package/dist/semantics/stable-checker.js +7 -2
- package/dist/semantics/subclass-member-overlay-transform.js +95 -53
- package/dist/semantics/unchecked-guard-argument-copies.d.ts +67 -0
- package/dist/semantics/unchecked-guard-argument-copies.js +163 -0
- package/dist/semantics/unchecked-write-member-declarations.d.ts +46 -0
- package/dist/semantics/unchecked-write-member-declarations.js +331 -0
- package/dist/targets/cpp/balanced-units.d.ts +31 -0
- package/dist/targets/cpp/balanced-units.js +57 -0
- package/dist/targets/cpp/borrowed-arm-projections.d.ts +31 -0
- package/dist/targets/cpp/borrowed-arm-projections.js +106 -0
- package/dist/targets/cpp/borrowed-call-entry.d.ts +1 -1
- package/dist/targets/cpp/borrowed-call-entry.js +24 -20
- package/dist/targets/cpp/captures.js +314 -8
- package/dist/targets/cpp/char-code-buffers.d.ts +36 -0
- package/dist/targets/cpp/char-code-buffers.js +214 -0
- package/dist/targets/cpp/class-layout.d.ts +7 -1
- package/dist/targets/cpp/class-layout.js +42 -17
- package/dist/targets/cpp/class-properties/computed-method-value.d.ts +17 -2
- package/dist/targets/cpp/class-properties/computed-method-value.js +50 -4
- package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +31 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.js +174 -17
- package/dist/targets/cpp/class-ref-transport.d.ts +32 -0
- package/dist/targets/cpp/class-ref-transport.js +56 -1
- package/dist/targets/cpp/conversions.js +1827 -1502
- package/dist/targets/cpp/coroutine-bodies.d.ts +97 -0
- package/dist/targets/cpp/coroutine-bodies.js +187 -0
- package/dist/targets/cpp/document.js +11 -1
- package/dist/targets/cpp/emit-allocation.js +568 -21
- package/dist/targets/cpp/emit-arrays.d.ts +10 -0
- package/dist/targets/cpp/emit-arrays.js +147 -16
- package/dist/targets/cpp/emit-binding-reference.d.ts +26 -2
- package/dist/targets/cpp/emit-binding-reference.js +97 -5
- package/dist/targets/cpp/emit-bindings.d.ts +9 -1
- package/dist/targets/cpp/emit-bindings.js +108 -8
- package/dist/targets/cpp/emit-buffers.d.ts +2 -16
- package/dist/targets/cpp/emit-buffers.js +124 -25
- package/dist/targets/cpp/emit-callable.d.ts +35 -72
- package/dist/targets/cpp/emit-callable.js +647 -82
- package/dist/targets/cpp/emit-carrier-members.d.ts +13 -2
- package/dist/targets/cpp/emit-carrier-members.js +50 -9
- package/dist/targets/cpp/emit-constructor-identity-family.d.ts +20 -0
- package/dist/targets/cpp/emit-constructor-identity-family.js +45 -0
- package/dist/targets/cpp/emit-context.d.ts +329 -15
- package/dist/targets/cpp/emit-context.js +104 -13
- package/dist/targets/cpp/emit-dynamic-properties.d.ts +44 -0
- package/dist/targets/cpp/emit-dynamic-properties.js +256 -37
- package/dist/targets/cpp/emit-equality.js +117 -2
- package/dist/targets/cpp/emit-error-constructor.d.ts +19 -0
- package/dist/targets/cpp/emit-error-constructor.js +73 -0
- package/dist/targets/cpp/emit-exceptions.d.ts +25 -3
- package/dist/targets/cpp/emit-exceptions.js +215 -26
- package/dist/targets/cpp/emit-in.js +52 -5
- package/dist/targets/cpp/emit-instanceof.js +59 -11
- package/dist/targets/cpp/emit-integers.d.ts +6 -0
- package/dist/targets/cpp/emit-integers.js +10 -0
- package/dist/targets/cpp/emit-iterable-object-view.d.ts +15 -0
- package/dist/targets/cpp/emit-iterable-object-view.js +51 -0
- package/dist/targets/cpp/emit-iterator-object-view.d.ts +15 -0
- package/dist/targets/cpp/emit-iterator-object-view.js +125 -0
- package/dist/targets/cpp/emit-iterator.d.ts +7 -10
- package/dist/targets/cpp/emit-iterator.js +361 -24
- package/dist/targets/cpp/emit-json.d.ts +7 -1
- package/dist/targets/cpp/emit-json.js +595 -55
- package/dist/targets/cpp/emit-jsx.d.ts +0 -37
- package/dist/targets/cpp/emit-jsx.js +70 -8
- package/dist/targets/cpp/emit-narrowing.d.ts +192 -28
- package/dist/targets/cpp/emit-narrowing.js +1595 -120
- package/dist/targets/cpp/emit-native-selection.js +8 -2
- package/dist/targets/cpp/emit-presence.js +13 -0
- package/dist/targets/cpp/emit-properties.d.ts +3 -1
- package/dist/targets/cpp/emit-properties.js +303 -54
- package/dist/targets/cpp/emit-protocol-iterator.d.ts +14 -0
- package/dist/targets/cpp/emit-protocol-iterator.js +203 -0
- package/dist/targets/cpp/emit-proxy.d.ts +17 -0
- package/dist/targets/cpp/emit-proxy.js +35 -0
- package/dist/targets/cpp/emit-record-view.d.ts +12 -1
- package/dist/targets/cpp/emit-record-view.js +429 -18
- package/dist/targets/cpp/emit-return.d.ts +38 -0
- package/dist/targets/cpp/emit-return.js +143 -21
- package/dist/targets/cpp/emit-scopes.d.ts +78 -0
- package/dist/targets/cpp/emit-scopes.js +196 -0
- package/dist/targets/cpp/emit-sum-widening.js +6 -3
- package/dist/targets/cpp/emit-tonumber.d.ts +40 -1
- package/dist/targets/cpp/emit-tonumber.js +75 -4
- package/dist/targets/cpp/emit-tostring.d.ts +28 -2
- package/dist/targets/cpp/emit-tostring.js +115 -12
- package/dist/targets/cpp/emit-typeof.js +2 -2
- package/dist/targets/cpp/emit-union-properties.d.ts +9 -0
- package/dist/targets/cpp/emit-union-properties.js +391 -49
- package/dist/targets/cpp/emit.d.ts +3 -1
- package/dist/targets/cpp/emit.js +725 -90
- package/dist/targets/cpp/evaluated-once.d.ts +51 -0
- package/dist/targets/cpp/evaluated-once.js +140 -0
- package/dist/targets/cpp/host/core-globals.d.ts +0 -21
- package/dist/targets/cpp/host/core-globals.js +10 -2
- package/dist/targets/cpp/host/emit-host-invoke.d.ts +0 -10
- package/dist/targets/cpp/host/emit-host-invoke.js +454 -36
- package/dist/targets/cpp/host/emit-host-object.js +733 -88
- package/dist/targets/cpp/host/emit-host-properties.js +26 -2
- package/dist/targets/cpp/host/emit-host-reflect.d.ts +1 -0
- package/dist/targets/cpp/host/emit-host-reflect.js +26 -7
- package/dist/targets/cpp/host/emit-host-value.d.ts +13 -0
- package/dist/targets/cpp/host/emit-host-value.js +47 -3
- package/dist/targets/cpp/host/host-members.d.ts +11 -0
- package/dist/targets/cpp/host/host-members.js +50 -4
- package/dist/targets/cpp/host/native-protocols.js +3 -0
- package/dist/targets/cpp/host/object-protocol.d.ts +8 -0
- package/dist/targets/cpp/host/object-protocol.js +55 -13
- package/dist/targets/cpp/key-order-tracking.d.ts +11 -0
- package/dist/targets/cpp/key-order-tracking.js +18 -0
- package/dist/targets/cpp/manifest/capabilities.js +117 -9
- package/dist/targets/cpp/manifest.js +14 -0
- package/dist/targets/cpp/native-collection-base.d.ts +27 -0
- package/dist/targets/cpp/native-collection-base.js +202 -0
- package/dist/targets/cpp/native-error-base.d.ts +14 -0
- package/dist/targets/cpp/native-error-base.js +19 -4
- package/dist/targets/cpp/native-promise-base.d.ts +23 -0
- package/dist/targets/cpp/native-promise-base.js +30 -0
- package/dist/targets/cpp/native-symbol-keys.js +1 -1
- package/dist/targets/cpp/prototype/emit-prototype-array.js +258 -20
- package/dist/targets/cpp/prototype/emit-prototype-date.js +5 -4
- package/dist/targets/cpp/prototype/emit-prototype-invoke.d.ts +9 -1
- package/dist/targets/cpp/prototype/emit-prototype-invoke.js +232 -26
- package/dist/targets/cpp/prototype/emit-prototype-iterator.d.ts +1 -1
- package/dist/targets/cpp/prototype/emit-prototype-iterator.js +111 -13
- package/dist/targets/cpp/prototype/emit-prototype-promise.d.ts +33 -4
- package/dist/targets/cpp/prototype/emit-prototype-promise.js +218 -10
- package/dist/targets/cpp/prototype/emit-prototype-regexp.js +8 -5
- package/dist/targets/cpp/prototype/emit-prototype-string.js +24 -7
- package/dist/targets/cpp/prototype/prototype-method-reads.js +18 -3
- package/dist/targets/cpp/reactive-dependencies.d.ts +2 -0
- package/dist/targets/cpp/reactive-dependencies.js +94 -3
- package/dist/targets/cpp/realm-storage.d.ts +5 -0
- package/dist/targets/cpp/realm-storage.js +12 -0
- package/dist/targets/cpp/records.d.ts +151 -1
- package/dist/targets/cpp/records.js +1328 -122
- package/dist/targets/cpp/recursive-containers.d.ts +4 -1
- package/dist/targets/cpp/recursive-containers.js +28 -9
- package/dist/targets/cpp/translation-unit.d.ts +10 -0
- package/dist/targets/cpp/translation-unit.js +686 -140
- package/dist/targets/cpp/types.d.ts +56 -6
- package/dist/targets/cpp/types.js +218 -12
- package/dist/targets/cpp/virtual-methods.d.ts +3 -3
- package/dist/targets/cpp/virtual-methods.js +174 -17
- package/package.json +14 -13
- package/src/targets/cpp/runtime/gea_dynamic_proxy.h +155 -25
- package/src/targets/cpp/runtime/gea_eval.h +3 -0
- package/src/targets/cpp/runtime/gea_pcm.h +116 -0
- package/src/targets/cpp/runtime/gea_runtime.h +18159 -4887
- package/src/targets/cpp/runtime/gea_runtime_builtins.cpp +7 -45
- package/src/targets/cpp/runtime/gea_runtime_rtc.h +247 -0
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { genericFunctionChoiceMembersOf } from './generic-function-choice.js';
|
|
3
|
-
import { layoutRelevantParameterIndices, parametersInInstanceStorage } from './structural-layout-relevance.js';
|
|
3
|
+
import { layoutRelevantParameterIndices, parametersInInstanceStorage, storedDataDiffers } from './structural-layout-relevance.js';
|
|
4
4
|
import { isAmbientDeclaration } from '../ambient.js';
|
|
5
|
+
import { mergedDeclarationOf } from './merged-declaration.js';
|
|
5
6
|
export const emptySpecializationCensus = {
|
|
6
7
|
specializationsOf: () => [],
|
|
7
8
|
isGeneric: () => false,
|
|
8
9
|
specializationAt: () => null,
|
|
10
|
+
erasedAnyRefilledAt: () => false,
|
|
9
11
|
setSpecializationsAt: () => null,
|
|
10
12
|
specializationOfInstance: () => null,
|
|
11
13
|
copiesMayDifferInLayout: () => false,
|
|
12
|
-
canonicalLayoutFillings: () => null
|
|
14
|
+
canonicalLayoutFillings: () => null,
|
|
15
|
+
reinterpretedCopyOf: () => null,
|
|
16
|
+
admittedUnder: () => true
|
|
13
17
|
};
|
|
14
18
|
const typeParametersOf = (declaration) => {
|
|
15
19
|
const withParameters = declaration;
|
|
@@ -83,13 +87,13 @@ const isHole = (type) => (type.flags & ts.TypeFlags.TypeParameter) !== 0;
|
|
|
83
87
|
* from a call the checker itself already resolved -- is recorded from that
|
|
84
88
|
* call, not from this reference.
|
|
85
89
|
*/
|
|
86
|
-
const
|
|
90
|
+
const containsHoleIn = (checker, type, depth = 0) => {
|
|
87
91
|
if (isHole(type))
|
|
88
92
|
return true;
|
|
89
93
|
if (depth > 6)
|
|
90
94
|
return false;
|
|
91
95
|
if (type.isUnionOrIntersection())
|
|
92
|
-
return type.types.some((one) =>
|
|
96
|
+
return type.types.some((one) => containsHoleIn(checker, one, depth + 1));
|
|
93
97
|
// BOTH argument lists, always. An instantiated ANONYMOUS type -- a mapped
|
|
94
98
|
// alias like tsc's `Mutable<T>`, an inline object or function type -- has a
|
|
95
99
|
// `target` (the open anonymous type it was instantiated from) and NO
|
|
@@ -101,7 +105,82 @@ const containsHole = (type, depth = 0) => {
|
|
|
101
105
|
// was the constraint image while the call wanted the instantiation.
|
|
102
106
|
const reference = type;
|
|
103
107
|
const args = [...(reference.typeArguments ?? []), ...(type.aliasTypeArguments ?? [])];
|
|
104
|
-
|
|
108
|
+
if (args.some((one) => containsHoleIn(checker, one, depth + 1)))
|
|
109
|
+
return true;
|
|
110
|
+
return literalMembersHoldHole(checker, type);
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Whether a written object LITERAL type keeps a hole in one of its PROPERTIES.
|
|
114
|
+
*
|
|
115
|
+
* `new Box<{ v: T }>()` inside `Holder<T>` fills `Box` with a type that has
|
|
116
|
+
* no type arguments at all -- its hole sits in the property `v` -- so the
|
|
117
|
+
* argument walk above read it as closed, and one OPEN copy `Box<{ v: T }>` was
|
|
118
|
+
* minted: its `items: T[]` reached representation with no carrier. The site is
|
|
119
|
+
* open exactly like `Box<T>` would be, and each copy of `Holder` closes it
|
|
120
|
+
* through `filledBy`.
|
|
121
|
+
*
|
|
122
|
+
* Only an anonymous type-literal or object-literal type is walked, and only its
|
|
123
|
+
* properties. A function type's hole sits in a signature, which this module
|
|
124
|
+
* reads nowhere else either, and a class or interface instance's members are
|
|
125
|
+
* that declaration's own business: its arguments already said whether it is
|
|
126
|
+
* open. Remembered per type, because the census asks it of the same fillings on
|
|
127
|
+
* every round of the fixpoint, and a literal that mentions itself answers
|
|
128
|
+
* `false` for the cycle rather than recursing.
|
|
129
|
+
*/
|
|
130
|
+
const literalHoles = new WeakMap();
|
|
131
|
+
const isObjectLiteralType = (type) => (type.flags & ts.TypeFlags.Object) !== 0 &&
|
|
132
|
+
(type.objectFlags & ts.ObjectFlags.Anonymous) !== 0 &&
|
|
133
|
+
((type.getSymbol()?.flags ?? 0) & (ts.SymbolFlags.TypeLiteral | ts.SymbolFlags.ObjectLiteral)) !== 0;
|
|
134
|
+
const literalMembersHoldHole = (checker, type) => {
|
|
135
|
+
if (!isObjectLiteralType(type))
|
|
136
|
+
return false;
|
|
137
|
+
const known = literalHoles.get(type);
|
|
138
|
+
if (known !== undefined)
|
|
139
|
+
return known;
|
|
140
|
+
literalHoles.set(type, false);
|
|
141
|
+
const answer = checker.getPropertiesOfType(type).some((property) => containsHoleIn(checker, checker.getTypeOfSymbol(property), 1));
|
|
142
|
+
literalHoles.set(type, answer);
|
|
143
|
+
return answer;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Whether two OPEN object literal types are one type written twice.
|
|
147
|
+
*
|
|
148
|
+
* Every `{ v: T }` the program writes is its own anonymous type, so the one at
|
|
149
|
+
* `new Box<{ v: T }>()` and the one in `make(): Box<{ v: T }>` are different
|
|
150
|
+
* checker objects even though they are the same type -- and the copy's closed
|
|
151
|
+
* image of the second (`{ v: number }`, read off the copy's instantiated
|
|
152
|
+
* members) is then unreachable from the first by identity. Two literals with
|
|
153
|
+
* the same property names, the same optionality and readonly-ness, and
|
|
154
|
+
* property types that are the SAME type objects (or literals equal by this
|
|
155
|
+
* same rule) are instantiated by any one mapping into equal types, so the
|
|
156
|
+
* image of one is an image of the other.
|
|
157
|
+
*
|
|
158
|
+
* Exact, not assignability: `{ v: T }` and `{ v: T; w?: T }` differ in a
|
|
159
|
+
* property and are never confused, and any signature or index signature on
|
|
160
|
+
* either side declines, because this does not compare those.
|
|
161
|
+
*/
|
|
162
|
+
const sameOpenLiteral = (checker, left, right, depth = 0) => {
|
|
163
|
+
if (left === right)
|
|
164
|
+
return true;
|
|
165
|
+
if (depth > 4 || !isObjectLiteralType(left) || !isObjectLiteralType(right))
|
|
166
|
+
return false;
|
|
167
|
+
const shapeless = (type) => type.getCallSignatures().length === 0 && type.getConstructSignatures().length === 0 && checker.getIndexInfosOfType(type).length === 0;
|
|
168
|
+
if (!shapeless(left) || !shapeless(right))
|
|
169
|
+
return false;
|
|
170
|
+
const leftProperties = checker.getPropertiesOfType(left);
|
|
171
|
+
const rightProperties = checker.getPropertiesOfType(right);
|
|
172
|
+
if (leftProperties.length !== rightProperties.length)
|
|
173
|
+
return false;
|
|
174
|
+
const modifiersOf = (property) => {
|
|
175
|
+
const at = property.valueDeclaration ?? property.declarations?.[0];
|
|
176
|
+
return (property.flags & ts.SymbolFlags.Optional) | (at ? ts.getCombinedModifierFlags(at) & ts.ModifierFlags.Readonly : 0);
|
|
177
|
+
};
|
|
178
|
+
return leftProperties.every((property) => {
|
|
179
|
+
const other = rightProperties.find((candidate) => candidate.escapedName === property.escapedName);
|
|
180
|
+
return (other !== undefined &&
|
|
181
|
+
modifiersOf(property) === modifiersOf(other) &&
|
|
182
|
+
sameOpenLiteral(checker, checker.getTypeOfSymbol(property), checker.getTypeOfSymbol(other), depth + 1));
|
|
183
|
+
});
|
|
105
184
|
};
|
|
106
185
|
/**
|
|
107
186
|
* The declaration whose body a set of type parameters belongs to.
|
|
@@ -149,6 +228,12 @@ const openFilling = (type, depth = 0) => {
|
|
|
149
228
|
const reference = type;
|
|
150
229
|
return [...(reference.typeArguments ?? []), ...(type.aliasTypeArguments ?? [])].some((one) => openFilling(one, depth + 1));
|
|
151
230
|
};
|
|
231
|
+
/** A type parameter's declaration, the class's where a class and interface merge -- see `mergedDeclarationOf`. */
|
|
232
|
+
const typeParameterDeclarationOf = (parameter) => {
|
|
233
|
+
const symbol = parameter?.getSymbol();
|
|
234
|
+
const declaration = symbol ? mergedDeclarationOf(symbol) : null;
|
|
235
|
+
return declaration && ts.isTypeParameterDeclaration(declaration) ? declaration : undefined;
|
|
236
|
+
};
|
|
152
237
|
const ownerOf = (parameter) => {
|
|
153
238
|
const parent = parameter?.parent;
|
|
154
239
|
if (!parent)
|
|
@@ -202,7 +287,7 @@ const unify = (checker, generic, concrete, depth, record, recordPair = null) =>
|
|
|
202
287
|
}
|
|
203
288
|
// A composite with a hole inside, beside the closed type the checker built
|
|
204
289
|
// for it: the pair a copy answers `fillingOf` from.
|
|
205
|
-
if (recordPair &&
|
|
290
|
+
if (recordPair && containsHoleIn(checker, generic))
|
|
206
291
|
recordPair(generic, concrete);
|
|
207
292
|
// An OPTIONALITY MARKER is not content. `status?: U` is read as `U |
|
|
208
293
|
// undefined` and its instantiation as `ContentfulStatusCode | undefined`:
|
|
@@ -326,6 +411,15 @@ const unifySignatures = (checker, generics, concretes, depth, record, recordPair
|
|
|
326
411
|
if (generics.length !== 1 || concretes.length !== 1 || !generic || !concrete)
|
|
327
412
|
return;
|
|
328
413
|
unify(checker, generic.getReturnType(), concrete.getReturnType(), depth + 1, record, recordPair);
|
|
414
|
+
// A type guard's predicate is part of its return: `getReturnType` answers
|
|
415
|
+
// `boolean` and drops `value is readonly T[]`. mongodb's
|
|
416
|
+
// `isReadonlyArray<T>(value: any): value is readonly T[]` mentions `T`
|
|
417
|
+
// nowhere else, so the call bound nothing, minted no copy, and the callee
|
|
418
|
+
// stayed the generic's uninstantiated set.
|
|
419
|
+
const genericPredicate = checker.getTypePredicateOfSignature(generic)?.type;
|
|
420
|
+
const concretePredicate = checker.getTypePredicateOfSignature(concrete)?.type;
|
|
421
|
+
if (genericPredicate && concretePredicate)
|
|
422
|
+
unify(checker, genericPredicate, concretePredicate, depth + 1, record, recordPair);
|
|
329
423
|
// `this` IS a parameter -- ECMA-262 gives it a binding in the function
|
|
330
424
|
// environment like any other -- and it is the only one `Signature.parameters`
|
|
331
425
|
// leaves out. A generic whose type parameter appears ONLY there was therefore
|
|
@@ -379,6 +473,7 @@ const typeOfParameter = (checker, parameter) => {
|
|
|
379
473
|
// verified by reading `frontend.ts`'s call order. See the matching note in
|
|
380
474
|
// `instantiation.ts`.
|
|
381
475
|
export const censusSpecializations = (checker, sourceFiles, reachable, namespacePaths) => {
|
|
476
|
+
const containsHole = (type, depth = 0) => containsHoleIn(checker, type, depth);
|
|
382
477
|
// Per generic declaration: the instantiations seen so far, each a tuple of
|
|
383
478
|
// the types filling its parameters, in declaration order. Tuples are compared
|
|
384
479
|
// by the identity of the types in them -- the checker interns types, so two
|
|
@@ -457,6 +552,21 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
457
552
|
// exact tuple somewhere the program never instantiated from; see
|
|
458
553
|
// `deferredSpellings`.
|
|
459
554
|
const spelling = instantiated ?? deferredSpellingFor(declaration, tuple);
|
|
555
|
+
// A copy's SPELLING carries the member images too, however the copy was
|
|
556
|
+
// minted. A copy minted by substitution -- `new Collection<TSchema>(...)`
|
|
557
|
+
// inside `Db.collection<TSchema>`, closed per copy of the method -- gets
|
|
558
|
+
// its spelling from `deferredSpellings` (the call's resolved return type)
|
|
559
|
+
// and nothing else, so reading the member images only where a written
|
|
560
|
+
// reference passed them in left every such copy without `WithId<DataKey>`
|
|
561
|
+
// for the `new FindCursor<WithId<TSchema>>(...)` its `find` builds.
|
|
562
|
+
const spellingImages = spelling ? fillingsOfSpelling(declaration, spelling) : null;
|
|
563
|
+
if (spellingImages && spellingImages !== fillings) {
|
|
564
|
+
const merged = new Map(fillings ?? []);
|
|
565
|
+
for (const [open, closed] of spellingImages)
|
|
566
|
+
if (!merged.has(open))
|
|
567
|
+
merged.set(open, closed);
|
|
568
|
+
fillings = merged;
|
|
569
|
+
}
|
|
460
570
|
if (existing >= 0) {
|
|
461
571
|
if (spelling && !spelled[existing]) {
|
|
462
572
|
spelled[existing] = spelling;
|
|
@@ -466,8 +576,18 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
466
576
|
paired[existing] = signatures;
|
|
467
577
|
signaturePairs.set(declaration, paired);
|
|
468
578
|
}
|
|
469
|
-
|
|
470
|
-
|
|
579
|
+
// MERGED, not first-wins. `new Holder(1)` is seen twice at one node: as a
|
|
580
|
+
// call, whose constructor signature pairs no composite at all (an EMPTY
|
|
581
|
+
// table), and as a written instance type, whose members pair
|
|
582
|
+
// `Box<{ v: T }>` with `Box<{ v: number }>`. Keeping only the first
|
|
583
|
+
// left the copy with no image for the composite its own body builds.
|
|
584
|
+
const held = filled[existing];
|
|
585
|
+
if (fillings && fillings !== held && [...fillings.keys()].some((open) => !held?.has(open))) {
|
|
586
|
+
const merged = new Map(held ?? []);
|
|
587
|
+
for (const [open, closed] of fillings)
|
|
588
|
+
if (!merged.has(open))
|
|
589
|
+
merged.set(open, closed);
|
|
590
|
+
filled[existing] = merged;
|
|
471
591
|
compositeFillings.set(declaration, filled);
|
|
472
592
|
}
|
|
473
593
|
if (constructs && !minted[existing]) {
|
|
@@ -511,6 +631,43 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
511
631
|
const found = seen.findIndex((candidate) => candidate.length === args.length && candidate.every((t, index) => t === args[index]));
|
|
512
632
|
return found >= 0 ? found : null;
|
|
513
633
|
};
|
|
634
|
+
/**
|
|
635
|
+
* What one copy's composite fillings close `open` to: the copy's own entry
|
|
636
|
+
* for that very type, or else the entry for an object literal type that is
|
|
637
|
+
* the same type written elsewhere (`sameOpenLiteral`).
|
|
638
|
+
*
|
|
639
|
+
* The census's `filledBy` and every reader's `fillingOf` both answer through
|
|
640
|
+
* here, so a site and the copy it names cannot disagree over which closed
|
|
641
|
+
* object stands for `{ v: T }` in that copy -- the tuple a copy is minted
|
|
642
|
+
* with and the tuple a reader looks up are the same objects. When several
|
|
643
|
+
* written literals match, the first recorded wins, the same rule for both.
|
|
644
|
+
*/
|
|
645
|
+
const literalImages = new WeakMap();
|
|
646
|
+
const compositeImageOf = (declaration, ordinal, open) => {
|
|
647
|
+
const table = compositeFillings.get(declaration)?.[ordinal];
|
|
648
|
+
if (!table)
|
|
649
|
+
return null;
|
|
650
|
+
const direct = table.get(open);
|
|
651
|
+
if (direct !== undefined)
|
|
652
|
+
return direct;
|
|
653
|
+
if (!isObjectLiteralType(open) || !containsHole(open))
|
|
654
|
+
return null;
|
|
655
|
+
let known = literalImages.get(table);
|
|
656
|
+
if (!known)
|
|
657
|
+
literalImages.set(table, (known = new Map()));
|
|
658
|
+
const remembered = known.get(open);
|
|
659
|
+
if (remembered !== undefined)
|
|
660
|
+
return remembered;
|
|
661
|
+
let answer = null;
|
|
662
|
+
for (const [written, closed] of table) {
|
|
663
|
+
if (written !== open && sameOpenLiteral(checker, written, open)) {
|
|
664
|
+
answer = closed;
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
known.set(open, answer);
|
|
669
|
+
return answer;
|
|
670
|
+
};
|
|
514
671
|
/**
|
|
515
672
|
* The instantiations one recorded instantiation induces through its heritage.
|
|
516
673
|
*
|
|
@@ -541,7 +698,7 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
541
698
|
const args = reference.typeArguments;
|
|
542
699
|
if (!parameters || !args)
|
|
543
700
|
return;
|
|
544
|
-
const owner = ownerOf(parameters[0]
|
|
701
|
+
const owner = ownerOf(typeParameterDeclarationOf(parameters[0]));
|
|
545
702
|
if (!owner)
|
|
546
703
|
return;
|
|
547
704
|
const induced = new Map();
|
|
@@ -558,6 +715,39 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
558
715
|
}
|
|
559
716
|
recordTuple(owner, induced, null, depth + 1);
|
|
560
717
|
};
|
|
718
|
+
/**
|
|
719
|
+
* Whether the copies of a class extend DIFFERENT copies of a base that
|
|
720
|
+
* itself may split. Each copy's base arguments are its own fillings
|
|
721
|
+
* substituted into the `extends` clause, exactly as `induceFromHeritage`
|
|
722
|
+
* substitutes them; a clause whose argument keeps a hole nested inside it
|
|
723
|
+
* names no tuple, and answers "no" rather than guessing one.
|
|
724
|
+
*/
|
|
725
|
+
const baseCopiesDiffer = (declaration, copies) => {
|
|
726
|
+
const base = declaration.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
|
|
727
|
+
if (!base)
|
|
728
|
+
return false;
|
|
729
|
+
const reference = checker.getTypeAtLocation(base);
|
|
730
|
+
const parameters = reference.target?.typeParameters;
|
|
731
|
+
const args = reference.typeArguments;
|
|
732
|
+
if (!parameters || !args)
|
|
733
|
+
return false;
|
|
734
|
+
const owner = ownerOf(typeParameterDeclarationOf(parameters[0]));
|
|
735
|
+
if (!owner || !census.copiesMayDifferInLayout(owner))
|
|
736
|
+
return false;
|
|
737
|
+
const own = typeParametersOf(declaration).map((parameter) => checker.getSymbolAtLocation(parameter.name));
|
|
738
|
+
// A class reference's arguments end with its polymorphic `this`, which is
|
|
739
|
+
// no parameter of the base.
|
|
740
|
+
const baseTuples = copies.map((copy) => args.slice(0, parameters.length).map((filling) => {
|
|
741
|
+
if (!isHole(filling))
|
|
742
|
+
return containsHole(filling) ? null : filling;
|
|
743
|
+
const index = own.indexOf(filling.getSymbol());
|
|
744
|
+
return index < 0 ? null : (copy.arguments[index] ?? null);
|
|
745
|
+
}));
|
|
746
|
+
if (baseTuples.some((tuple) => tuple.some((filling) => filling === null)))
|
|
747
|
+
return false;
|
|
748
|
+
const [first, ...rest] = baseTuples;
|
|
749
|
+
return first !== undefined && rest.some((tuple) => tuple.some((filling, index) => filling !== first[index]));
|
|
750
|
+
};
|
|
561
751
|
/** Record one instantiation, given the owner and the fillings keyed by parameter symbol. */
|
|
562
752
|
const recordTuple = (declaration, bound, at, depth = 0, instantiated = null, signatures = null, spellingOnly = false, fillings = null, collect = null, constructs = true) => {
|
|
563
753
|
const parameters = typeParametersOf(declaration);
|
|
@@ -677,9 +867,11 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
677
867
|
* declaration the program never introduces.
|
|
678
868
|
*
|
|
679
869
|
* Used ONLY as the member walk's admission gate, where a wider answer can
|
|
680
|
-
* only add pairs. `containsHole` itself
|
|
681
|
-
* a TUPLE is concrete enough to mint a copy, and widening it
|
|
682
|
-
* withhold copies that are minted today.
|
|
870
|
+
* only add pairs. `containsHole` itself does not follow signatures: it also
|
|
871
|
+
* gates whether a TUPLE is concrete enough to mint a copy, and widening it
|
|
872
|
+
* there would withhold copies that are minted today. (It does follow an
|
|
873
|
+
* object literal's properties -- see `literalMembersHoldHole` -- because a
|
|
874
|
+
* copy minted over `{ v: T }` is exactly the open copy it exists to refuse.)
|
|
683
875
|
*/
|
|
684
876
|
const mentionsHoleThroughSignatures = (type, depth = 0) => {
|
|
685
877
|
if (containsHole(type, depth))
|
|
@@ -718,15 +910,52 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
718
910
|
const openType = checker.getTypeOfSymbol(open);
|
|
719
911
|
if (!mentionsHoleThroughSignatures(openType))
|
|
720
912
|
continue;
|
|
721
|
-
|
|
913
|
+
const closedType = checker.getTypeOfSymbol(property);
|
|
914
|
+
const recordPair = (composite, closed) => {
|
|
722
915
|
if (!pairs.has(composite))
|
|
723
916
|
pairs.set(composite, closed);
|
|
724
|
-
}
|
|
917
|
+
};
|
|
918
|
+
unify(checker, openType, closedType, 0, () => undefined, recordPair);
|
|
919
|
+
// An OVERLOADED member, signature by signature. `unifySignatures`
|
|
920
|
+
// declines a list of several because, against a type INFERRED from a
|
|
921
|
+
// call, nothing orders the two lists alike. Here nothing needs to: both
|
|
922
|
+
// sides are one member symbol, read off the generic and off its
|
|
923
|
+
// instantiation, so signature `i` is the image of signature `i` (the
|
|
924
|
+
// pairing `structural-instantiated-member.ts` relies on for the same
|
|
925
|
+
// reason). mongodb's `Collection.find` is the case: its three overloads
|
|
926
|
+
// were the only place `FindCursor<WithId<TSchema>>` was spelled, so no
|
|
927
|
+
// copy of `Collection` ever had the image `WithId<DataKey>` that the
|
|
928
|
+
// `new FindCursor<WithId<TSchema>>(...)` in its body needs, and
|
|
929
|
+
// `FindCursor` was minted no copy at all.
|
|
930
|
+
for (const [openList, closedList] of [
|
|
931
|
+
[openType.getCallSignatures(), closedType.getCallSignatures()],
|
|
932
|
+
[openType.getConstructSignatures(), closedType.getConstructSignatures()]
|
|
933
|
+
]) {
|
|
934
|
+
if (openList.length < 2 || openList.length !== closedList.length)
|
|
935
|
+
continue;
|
|
936
|
+
openList.forEach((signature, index) => {
|
|
937
|
+
const image = closedList[index];
|
|
938
|
+
if (image)
|
|
939
|
+
unifySignatures(checker, [signature], [image], 0, () => undefined, recordPair);
|
|
940
|
+
});
|
|
941
|
+
}
|
|
725
942
|
}
|
|
726
943
|
const answer = pairs.size > 0 ? pairs : null;
|
|
727
944
|
memberFillings.set(reference, answer);
|
|
728
945
|
return answer;
|
|
729
946
|
};
|
|
947
|
+
/** `memberFillingsOf` for a copy's spelling, when the spelling is a closed instantiation of a generic class. */
|
|
948
|
+
const fillingsOfSpelling = (declaration, spelling) => {
|
|
949
|
+
const reference = spelling;
|
|
950
|
+
const target = reference.target;
|
|
951
|
+
const parameters = target?.typeParameters;
|
|
952
|
+
const args = reference.typeArguments;
|
|
953
|
+
if (!target || !parameters || !args)
|
|
954
|
+
return null;
|
|
955
|
+
if (!args.some((argument, index) => argument !== parameters[index]) || args.some((argument) => containsHole(argument)))
|
|
956
|
+
return null;
|
|
957
|
+
return memberFillingsOf(declaration, target, reference);
|
|
958
|
+
};
|
|
730
959
|
/**
|
|
731
960
|
* A type reference the program writes -- or, with `node` null, one it makes
|
|
732
961
|
* without writing (a call's own resolved return type).
|
|
@@ -749,7 +978,7 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
749
978
|
const args = reference.typeArguments;
|
|
750
979
|
if (!target || !parameters || !args)
|
|
751
980
|
return;
|
|
752
|
-
const owner = ownerOf(parameters[0]
|
|
981
|
+
const owner = ownerOf(typeParameterDeclarationOf(parameters[0]));
|
|
753
982
|
if (!owner)
|
|
754
983
|
return;
|
|
755
984
|
const bound = new Map();
|
|
@@ -913,6 +1142,105 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
913
1142
|
* call: module-level function declarations with a body, at least two.
|
|
914
1143
|
*/
|
|
915
1144
|
const genericSetMembersOf = (node) => ts.isCallExpression(node) ? genericFunctionChoiceMembersOf(checker, node.expression) : null;
|
|
1145
|
+
/**
|
|
1146
|
+
* The type parameters a call filled with `any` ONLY because the argument
|
|
1147
|
+
* that binds them was erased with `as any`, refilled with the type of the
|
|
1148
|
+
* value the assertion wraps.
|
|
1149
|
+
*
|
|
1150
|
+
* mongodb's `Collection.insertOne` is `executeOperation(this.client, new
|
|
1151
|
+
* InsertOneOperation(...) as TODO_NODE_3286)` (`TODO_NODE_3286 = any`). The
|
|
1152
|
+
* checker infers `T = any` from the erased argument, so the copy that call
|
|
1153
|
+
* mints takes `operation: any` and every read of the operation in the copy
|
|
1154
|
+
* -- and in the `tryOperation` copy it calls -- is a box of a value whose
|
|
1155
|
+
* class the program states one token earlier. An assertion is erased at
|
|
1156
|
+
* runtime (`producers/erasure.ts`): the argument the copy receives IS the
|
|
1157
|
+
* `InsertOneOperation`, so a copy over that type receives exactly what
|
|
1158
|
+
* arrives.
|
|
1159
|
+
*
|
|
1160
|
+
* Sound only where the erased argument is the SOLE source of the filling:
|
|
1161
|
+
* every parameter whose declared type mentions the type parameter must be
|
|
1162
|
+
* the bare parameter itself, with an `as any` argument whose operand has one
|
|
1163
|
+
* static type that meets the constraint. A parameter that mentions it inside
|
|
1164
|
+
* a composite (`items: T[]`, `(value: T) => void`) was checked against `any`
|
|
1165
|
+
* and could hold anything, so the whole call keeps the checker's answer.
|
|
1166
|
+
*/
|
|
1167
|
+
const erasedAnyRefilledSites = new Set();
|
|
1168
|
+
const erasedAnyFillingsOf = (node, open, bound) => {
|
|
1169
|
+
if (!ts.isCallExpression(node) && !ts.isNewExpression(node))
|
|
1170
|
+
return null;
|
|
1171
|
+
const args = node.arguments ?? [];
|
|
1172
|
+
// A spread argument no longer lines up with a parameter index.
|
|
1173
|
+
if (args.some((argument) => ts.isSpreadElement(argument)))
|
|
1174
|
+
return null;
|
|
1175
|
+
const refilled = new Map();
|
|
1176
|
+
for (const parameter of open.getTypeParameters() ?? []) {
|
|
1177
|
+
const symbol = parameter.getSymbol();
|
|
1178
|
+
const filling = symbol ? bound.get(symbol) : undefined;
|
|
1179
|
+
if (!symbol || !filling || (filling.flags & ts.TypeFlags.Any) === 0)
|
|
1180
|
+
continue;
|
|
1181
|
+
let operandType = null;
|
|
1182
|
+
let sole = true;
|
|
1183
|
+
for (const [index, formal] of open.getParameters().entries()) {
|
|
1184
|
+
const declared = typeOfParameter(checker, formal);
|
|
1185
|
+
if (!declared)
|
|
1186
|
+
return null;
|
|
1187
|
+
if (declared !== parameter) {
|
|
1188
|
+
// Conservative: a composite that could mention the parameter is a
|
|
1189
|
+
// second source this call checked against `any`.
|
|
1190
|
+
if (containsHole(declared))
|
|
1191
|
+
sole = false;
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1194
|
+
const declaration = formal.valueDeclaration;
|
|
1195
|
+
if (declaration && ts.isParameter(declaration) && declaration.dotDotDotToken)
|
|
1196
|
+
return null;
|
|
1197
|
+
const argument = args[index];
|
|
1198
|
+
if (!argument)
|
|
1199
|
+
continue;
|
|
1200
|
+
const operand = erasedAnyOperandOf(argument);
|
|
1201
|
+
if (operand === null) {
|
|
1202
|
+
sole = false;
|
|
1203
|
+
continue;
|
|
1204
|
+
}
|
|
1205
|
+
const type = checker.getTypeAtLocation(operand);
|
|
1206
|
+
if ((type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0) {
|
|
1207
|
+
sole = false;
|
|
1208
|
+
continue;
|
|
1209
|
+
}
|
|
1210
|
+
if (operandType !== null && operandType !== type)
|
|
1211
|
+
sole = false;
|
|
1212
|
+
operandType = type;
|
|
1213
|
+
}
|
|
1214
|
+
if (!sole || operandType === null)
|
|
1215
|
+
continue;
|
|
1216
|
+
const constraint = checker.getBaseConstraintOfType(parameter);
|
|
1217
|
+
if (constraint && (constraint.flags & ts.TypeFlags.Unknown) === 0 && !checker.isTypeAssignableTo(operandType, constraint))
|
|
1218
|
+
continue;
|
|
1219
|
+
refilled.set(symbol, operandType);
|
|
1220
|
+
}
|
|
1221
|
+
return refilled.size > 0 ? refilled : null;
|
|
1222
|
+
};
|
|
1223
|
+
/** The operand of an `x as any` / `<any>x` argument (through parentheses and `!`), or `null`. */
|
|
1224
|
+
const erasedAnyOperandOf = (argument) => {
|
|
1225
|
+
let current = argument;
|
|
1226
|
+
let erasedToAny = false;
|
|
1227
|
+
for (;;) {
|
|
1228
|
+
if (ts.isParenthesizedExpression(current) || ts.isNonNullExpression(current)) {
|
|
1229
|
+
current = current.expression;
|
|
1230
|
+
continue;
|
|
1231
|
+
}
|
|
1232
|
+
if (ts.isAsExpression(current) || ts.isTypeAssertionExpression(current)) {
|
|
1233
|
+
const target = checker.getTypeFromTypeNode(current.type);
|
|
1234
|
+
if ((target.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) === 0)
|
|
1235
|
+
return null;
|
|
1236
|
+
if ((target.flags & ts.TypeFlags.Any) !== 0)
|
|
1237
|
+
erasedToAny = true;
|
|
1238
|
+
current = current.expression;
|
|
1239
|
+
continue;
|
|
1240
|
+
}
|
|
1241
|
+
return erasedToAny ? current : null;
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
916
1244
|
const fromCall = (node) => {
|
|
917
1245
|
const resolved = checker.getResolvedSignature(node);
|
|
918
1246
|
const setMembers = resolved ? genericSetMembersOf(node) : null;
|
|
@@ -946,13 +1274,22 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
946
1274
|
return;
|
|
947
1275
|
}
|
|
948
1276
|
const generic = genericSignatureOf(node, resolved);
|
|
949
|
-
|
|
1277
|
+
// A NON-generic overload of a generic implementation still runs that
|
|
1278
|
+
// implementation at some filling: mongodb's `Db.listCollections(filter,
|
|
1279
|
+
// {nameOnly: false})` resolves to the overload returning
|
|
1280
|
+
// `ListCollectionsCursor<CollectionInfo>`, and the body builds `new
|
|
1281
|
+
// ListCollectionsCursor<T>(...)`. Unifying the implementation against the
|
|
1282
|
+
// overload binds `T` from the overload's stated result, so the copy the
|
|
1283
|
+
// body constructs is the copy the caller holds.
|
|
1284
|
+
const overload = !generic && resolved ? resolved.getDeclaration() : undefined;
|
|
1285
|
+
const viaOverload = overload !== undefined && implementationOf(overload) !== overload ? overload : undefined;
|
|
1286
|
+
if (!resolved || (viaOverload === undefined && (!generic || generic === resolved)))
|
|
950
1287
|
return;
|
|
951
|
-
const declared = generic
|
|
1288
|
+
const declared = viaOverload ?? generic?.getDeclaration();
|
|
952
1289
|
if (!declared)
|
|
953
1290
|
return;
|
|
954
1291
|
const owner = implementationOf(declared);
|
|
955
|
-
let open = generic;
|
|
1292
|
+
let open = generic ?? resolved;
|
|
956
1293
|
if (owner !== declared) {
|
|
957
1294
|
const implementation = checker.getSignatureFromDeclaration(owner);
|
|
958
1295
|
// An implementation with no type parameters of its own is one function
|
|
@@ -971,6 +1308,36 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
971
1308
|
if (!pairs.has(composite))
|
|
972
1309
|
pairs.set(composite, closed);
|
|
973
1310
|
});
|
|
1311
|
+
// A written type argument states its parameter outright, and is the only
|
|
1312
|
+
// statement of one that no parameter type unifies against: `emit<K>(...args:
|
|
1313
|
+
// Parameters<E[K]>)` called as `emit<'started'>(event)` pairs the deferred
|
|
1314
|
+
// conditional with a closed tuple, which binds nothing, and a call whose
|
|
1315
|
+
// tuple is incomplete mints no copy at all -- the method was then read off
|
|
1316
|
+
// the instance as a dynamic property and aborted. Only for the declaration
|
|
1317
|
+
// the call resolved to: an implementation behind overloads names its own
|
|
1318
|
+
// parameters.
|
|
1319
|
+
const written = 'typeArguments' in node ? node.typeArguments : undefined;
|
|
1320
|
+
if (written && owner === declared) {
|
|
1321
|
+
for (const [index, parameter] of (open.getTypeParameters() ?? []).entries()) {
|
|
1322
|
+
const argument = written[index];
|
|
1323
|
+
const symbol = parameter.getSymbol();
|
|
1324
|
+
if (argument && symbol && !bound.has(symbol))
|
|
1325
|
+
bound.set(symbol, checker.getTypeFromTypeNode(argument));
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
const erased = owner === declared ? erasedAnyFillingsOf(node, open, bound) : null;
|
|
1329
|
+
if (erased !== null) {
|
|
1330
|
+
for (const [symbol, filling] of erased)
|
|
1331
|
+
bound.set(symbol, filling);
|
|
1332
|
+
erasedAnyRefilledSites.add(node);
|
|
1333
|
+
// The checker's resolved signature types every rebound position `any`;
|
|
1334
|
+
// pairing it with the copy would read those positions back as `any`.
|
|
1335
|
+
// The tuple is the whole statement, exactly as for an overload copy.
|
|
1336
|
+
recordTuple(owner, bound, node, 0, null, null, false, null);
|
|
1337
|
+
fromTypeReference(null, resolved.getReturnType(), true);
|
|
1338
|
+
fromImplementation(node, owner, bound);
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
974
1341
|
// No signature pair for a copy minted through an overload: the resolved
|
|
975
1342
|
// signature is the OVERLOAD's frame instantiated, not the implementation's
|
|
976
1343
|
// -- `some<T>(array, predicate?)` resolved through `some(array, predicate)`
|
|
@@ -1268,7 +1635,7 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
1268
1635
|
* instantiated exactly one way by the program -- the one case a hole a
|
|
1269
1636
|
* type owns has a single answer. See `fromValueUse`.
|
|
1270
1637
|
*/
|
|
1271
|
-
const holeOwnerOf = (hole) => ownerOf(hole
|
|
1638
|
+
const holeOwnerOf = (hole) => ownerOf(typeParameterDeclarationOf(hole));
|
|
1272
1639
|
const uniquelyInstantiatedTypeOwnersOf = (fillings) => {
|
|
1273
1640
|
const owners = [];
|
|
1274
1641
|
for (const filling of fillings) {
|
|
@@ -1358,6 +1725,66 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
1358
1725
|
};
|
|
1359
1726
|
for (const file of sourceFiles)
|
|
1360
1727
|
declareVisit(file);
|
|
1728
|
+
/**
|
|
1729
|
+
* The generic classes the program REINTERPRETS: casts one of their
|
|
1730
|
+
* instances, through `unknown` or `any`, to another instantiation of the
|
|
1731
|
+
* same class hierarchy -- mongodb's `AbstractCursor.map` composing a
|
|
1732
|
+
* transform and returning `this as unknown as AbstractCursor<T>`.
|
|
1733
|
+
*
|
|
1734
|
+
* That is one object viewed at two instantiations, and the program has
|
|
1735
|
+
* declared the relationship UNCHECKED: the `transform` field typed
|
|
1736
|
+
* `(doc: TSchema) => any` keeps receiving the raw documents whatever
|
|
1737
|
+
* `TSchema` the current view claims, and a closure composed in one view
|
|
1738
|
+
* forwards a value of another view's type. No per-copy layout is honest
|
|
1739
|
+
* for such a class -- the object cannot be converted between copies
|
|
1740
|
+
* without losing identity, and any concrete filling is a claim the program
|
|
1741
|
+
* itself has said it does not keep. So every copy folds onto ONE layout
|
|
1742
|
+
* whose type-parameter-dependent storage is filled with `any`
|
|
1743
|
+
* (`reinterpretationTuples`), the filling TypeScript gives the unchecked
|
|
1744
|
+
* top; values crossing into it are checked on the way out, never trusted.
|
|
1745
|
+
*/
|
|
1746
|
+
const reinterpretedClasses = new Set();
|
|
1747
|
+
const classOfInstance = (type) => {
|
|
1748
|
+
const thisClass = (type.flags & ts.TypeFlags.TypeParameter) !== 0 && type.getSymbol()?.declarations?.some((one) => ts.isClassLike(one)) === true;
|
|
1749
|
+
const instance = thisClass ? (checker.getBaseConstraintOfType(type) ?? type) : type;
|
|
1750
|
+
const symbol = instance.target?.getSymbol() ?? instance.getSymbol();
|
|
1751
|
+
const declaration = symbol ? mergedDeclarationOf(symbol) : null;
|
|
1752
|
+
return declaration && ts.isClassLike(declaration) ? declaration : null;
|
|
1753
|
+
};
|
|
1754
|
+
const baseClassOf = (declaration) => {
|
|
1755
|
+
const base = declaration.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
|
|
1756
|
+
return base ? classOfInstance(checker.getTypeAtLocation(base)) : null;
|
|
1757
|
+
};
|
|
1758
|
+
const ancestryOf = (declaration) => {
|
|
1759
|
+
const chain = [];
|
|
1760
|
+
for (let current = declaration; current && chain.length < 16; current = baseClassOf(current)) {
|
|
1761
|
+
if (chain.includes(current))
|
|
1762
|
+
break;
|
|
1763
|
+
chain.push(current);
|
|
1764
|
+
}
|
|
1765
|
+
return chain;
|
|
1766
|
+
};
|
|
1767
|
+
const noteReinterpretation = (node) => {
|
|
1768
|
+
let inner = node.expression;
|
|
1769
|
+
while (ts.isParenthesizedExpression(inner))
|
|
1770
|
+
inner = inner.expression;
|
|
1771
|
+
if (!ts.isAsExpression(inner) && !ts.isTypeAssertionExpression(inner))
|
|
1772
|
+
return;
|
|
1773
|
+
if ((checker.getTypeFromTypeNode(inner.type).flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) === 0)
|
|
1774
|
+
return;
|
|
1775
|
+
const target = checker.getTypeFromTypeNode(node.type);
|
|
1776
|
+
const source = checker.getTypeAtLocation(inner.expression);
|
|
1777
|
+
const targetClass = classOfInstance(target);
|
|
1778
|
+
const sourceClass = classOfInstance(source);
|
|
1779
|
+
if (!targetClass || !sourceClass || typeParametersOf(targetClass).length === 0)
|
|
1780
|
+
return;
|
|
1781
|
+
// Only a view of the SAME object: the target class is the source's own
|
|
1782
|
+
// class or one of its ancestors or descendants. A cast from an unrelated
|
|
1783
|
+
// value is a dynamic assertion, not a reinterpretation.
|
|
1784
|
+
if (!ancestryOf(sourceClass).includes(targetClass) && !ancestryOf(targetClass).includes(sourceClass))
|
|
1785
|
+
return;
|
|
1786
|
+
reinterpretedClasses.add(targetClass);
|
|
1787
|
+
};
|
|
1361
1788
|
const visit = (node) => {
|
|
1362
1789
|
// A PRUNED member is a site this compilation does not reach either, and
|
|
1363
1790
|
// statement-level reachability cannot say so: a dead method lives inside a
|
|
@@ -1375,6 +1802,8 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
1375
1802
|
// probe's 516 mandatory obligations, all from one method nothing calls.
|
|
1376
1803
|
if (reachable.memberIsPruned(node))
|
|
1377
1804
|
return;
|
|
1805
|
+
if (ts.isAsExpression(node) || ts.isTypeAssertionExpression(node))
|
|
1806
|
+
noteReinterpretation(node);
|
|
1378
1807
|
if (ts.isCallOrNewExpression(node) || ts.isTaggedTemplateExpression(node) || ts.isJsxOpeningLikeElement(node))
|
|
1379
1808
|
fromCall(node);
|
|
1380
1809
|
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node) || ts.isIdentifier(node) || ts.isPropertyAccessExpression(node))
|
|
@@ -1389,6 +1818,162 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
1389
1818
|
for (const file of sourceFiles)
|
|
1390
1819
|
for (const statement of reachable.statementsOf(file))
|
|
1391
1820
|
visit(statement);
|
|
1821
|
+
// A reinterpreted object is a whole object, so the fold reaches its whole
|
|
1822
|
+
// hierarchy: the ancestors whose storage it carries, and the descendants
|
|
1823
|
+
// it may really be -- `FindCursor.map` returns `super.map(t) as
|
|
1824
|
+
// FindCursor<T>`, a checked downcast that holds only if the `FindCursor`
|
|
1825
|
+
// being viewed is the one physical class the `FindCursor<T>` view names.
|
|
1826
|
+
const reinterpretationFamily = new Set();
|
|
1827
|
+
for (const declaration of reinterpretedClasses)
|
|
1828
|
+
for (const one of ancestryOf(declaration))
|
|
1829
|
+
reinterpretationFamily.add(one);
|
|
1830
|
+
if (reinterpretationFamily.size > 0)
|
|
1831
|
+
for (const declaration of declared)
|
|
1832
|
+
if (ts.isClassLike(declaration) && ancestryOf(declaration).some((one) => reinterpretationFamily.has(one)))
|
|
1833
|
+
for (const one of ancestryOf(declaration))
|
|
1834
|
+
reinterpretationFamily.add(one);
|
|
1835
|
+
/**
|
|
1836
|
+
* The one tuple every copy of a reinterpreted class folds onto: a copy's
|
|
1837
|
+
* own fillings with `any` at each layout-relevant position where the
|
|
1838
|
+
* copies disagree. `null` while the copies agree, which leaves the class
|
|
1839
|
+
* exactly as it was -- there is nothing to fold.
|
|
1840
|
+
*/
|
|
1841
|
+
const reinterpretationTupleOf = (declaration) => {
|
|
1842
|
+
if (!reinterpretationFamily.has(declaration) || !ts.isClassLike(declaration) || isAmbientDeclaration(declaration))
|
|
1843
|
+
return null;
|
|
1844
|
+
const seen = tuples.get(declaration) ?? [];
|
|
1845
|
+
const [first] = seen;
|
|
1846
|
+
if (first === undefined || seen.length < 2)
|
|
1847
|
+
return null;
|
|
1848
|
+
const layoutRelevant = layoutRelevantParameterIndices(checker, declaration);
|
|
1849
|
+
const any = checker.getAnyType();
|
|
1850
|
+
let differs = false;
|
|
1851
|
+
const tuple = first.map((filling, index) => {
|
|
1852
|
+
if (!layoutRelevant.has(index) || seen.every((other) => other[index] === filling))
|
|
1853
|
+
return filling;
|
|
1854
|
+
differs = true;
|
|
1855
|
+
return any;
|
|
1856
|
+
});
|
|
1857
|
+
return differs ? tuple : null;
|
|
1858
|
+
};
|
|
1859
|
+
/** Mint each reinterpreted class's folded copy, through `recordTuple` so its heritage is induced too. */
|
|
1860
|
+
const mintReinterpretationCopies = () => {
|
|
1861
|
+
let minted = false;
|
|
1862
|
+
for (const declaration of reinterpretationFamily) {
|
|
1863
|
+
const tuple = reinterpretationTupleOf(declaration);
|
|
1864
|
+
if (tuple === null || ordinalOfArguments(declaration, tuple) !== null)
|
|
1865
|
+
continue;
|
|
1866
|
+
const bound = new Map();
|
|
1867
|
+
typeParametersOf(declaration).forEach((parameter, index) => {
|
|
1868
|
+
const symbol = checker.getSymbolAtLocation(parameter.name);
|
|
1869
|
+
const filling = tuple[index];
|
|
1870
|
+
if (symbol && filling)
|
|
1871
|
+
bound.set(symbol, filling);
|
|
1872
|
+
});
|
|
1873
|
+
recordTuple(declaration, bound, null);
|
|
1874
|
+
minted = true;
|
|
1875
|
+
}
|
|
1876
|
+
return minted;
|
|
1877
|
+
};
|
|
1878
|
+
/**
|
|
1879
|
+
* The generic METHODS that override one another, as groups: a class's
|
|
1880
|
+
* generic method with a body, and every same-named instance method with a
|
|
1881
|
+
* body and as many type parameters along its class's ancestry.
|
|
1882
|
+
*
|
|
1883
|
+
* A receiver typed as the base runs whichever class allocated it, so every
|
|
1884
|
+
* copy a call through the base mints is a copy each override must have too:
|
|
1885
|
+
* mongodb's `OnDemandDocument.getNumber` calls `this.get(name, 'bool')`,
|
|
1886
|
+
* and a `MongoDBResponse` -- which overrides `get<T>` and is only ever
|
|
1887
|
+
* called at `'object'` itself -- must answer that call with its own body.
|
|
1888
|
+
* Minting only where a call is WRITTEN left the subclass with no copy at
|
|
1889
|
+
* that convention, and the whole dispatch family refused
|
|
1890
|
+
* (`projection/dispatch.ts`'s `copyAbsentFrom`). The other direction holds
|
|
1891
|
+
* for the same reason: a copy a subclass-typed call mints is a copy of the
|
|
1892
|
+
* family's member at that convention, which the base declares too.
|
|
1893
|
+
*/
|
|
1894
|
+
const overrideGroups = (() => {
|
|
1895
|
+
const nameOf = (member) => ts.isMethodDeclaration(member) && member.body !== undefined && (ts.isIdentifier(member.name) || ts.isStringLiteral(member.name))
|
|
1896
|
+
? member.name.text
|
|
1897
|
+
: null;
|
|
1898
|
+
const isInstance = (member) => !(ts.canHaveModifiers(member) && ts.getModifiers(member)?.some((one) => one.kind === ts.SyntaxKind.StaticKeyword));
|
|
1899
|
+
const parents = new Map();
|
|
1900
|
+
const find = (member) => {
|
|
1901
|
+
let root = member;
|
|
1902
|
+
while (parents.get(root) !== undefined && parents.get(root) !== root)
|
|
1903
|
+
root = parents.get(root);
|
|
1904
|
+
return root;
|
|
1905
|
+
};
|
|
1906
|
+
for (const member of declared) {
|
|
1907
|
+
const name = nameOf(member);
|
|
1908
|
+
if (name === null || !isInstance(member) || !ts.isClassLike(member.parent) || reachable.memberIsPruned(member))
|
|
1909
|
+
continue;
|
|
1910
|
+
const arity = typeParametersOf(member).length;
|
|
1911
|
+
for (const base of ancestryOf(member.parent).slice(1)) {
|
|
1912
|
+
const overridden = base.members.find((candidate) => nameOf(candidate) === name &&
|
|
1913
|
+
isInstance(candidate) &&
|
|
1914
|
+
typeParametersOf(candidate).length === arity &&
|
|
1915
|
+
!reachable.memberIsPruned(candidate));
|
|
1916
|
+
if (overridden === undefined)
|
|
1917
|
+
continue;
|
|
1918
|
+
if (!parents.has(member))
|
|
1919
|
+
parents.set(member, member);
|
|
1920
|
+
if (!parents.has(overridden))
|
|
1921
|
+
parents.set(overridden, overridden);
|
|
1922
|
+
parents.set(find(member), find(overridden));
|
|
1923
|
+
break;
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
const groups = new Map();
|
|
1927
|
+
for (const member of parents.keys()) {
|
|
1928
|
+
const root = find(member);
|
|
1929
|
+
const group = groups.get(root) ?? [];
|
|
1930
|
+
group.push(member);
|
|
1931
|
+
groups.set(root, group);
|
|
1932
|
+
}
|
|
1933
|
+
return [...groups.values()].filter((group) => group.length > 1);
|
|
1934
|
+
})();
|
|
1935
|
+
/**
|
|
1936
|
+
* Whether `member` can be instantiated at `tuple`: every filling satisfies
|
|
1937
|
+
* the member's own written constraint. An override may state its type
|
|
1938
|
+
* parameters differently from the method it overrides, and a copy outside
|
|
1939
|
+
* its constraint is one no call could make.
|
|
1940
|
+
*/
|
|
1941
|
+
const admitsTuple = (member, tuple) => typeParametersOf(member).every((parameter, index) => {
|
|
1942
|
+
const filling = tuple[index];
|
|
1943
|
+
if (filling === undefined)
|
|
1944
|
+
return false;
|
|
1945
|
+
if (parameter.constraint === undefined)
|
|
1946
|
+
return true;
|
|
1947
|
+
const constraint = checker.getTypeFromTypeNode(parameter.constraint);
|
|
1948
|
+
return !containsHole(constraint) && checker.isTypeAssignableTo(filling, constraint);
|
|
1949
|
+
});
|
|
1950
|
+
/** Mint, for each override group, every member's copy at every tuple another member has. */
|
|
1951
|
+
const mintOverrideCopies = () => {
|
|
1952
|
+
let minted = false;
|
|
1953
|
+
for (const group of overrideGroups) {
|
|
1954
|
+
const union = [];
|
|
1955
|
+
for (const member of group)
|
|
1956
|
+
for (const tuple of tuples.get(member) ?? [])
|
|
1957
|
+
if (!union.some((held) => held.length === tuple.length && held.every((one, index) => one === tuple[index])))
|
|
1958
|
+
union.push(tuple);
|
|
1959
|
+
for (const member of group) {
|
|
1960
|
+
for (const tuple of union) {
|
|
1961
|
+
if (ordinalOfArguments(member, tuple) !== null || !admitsTuple(member, tuple))
|
|
1962
|
+
continue;
|
|
1963
|
+
const bound = new Map();
|
|
1964
|
+
typeParametersOf(member).forEach((parameter, index) => {
|
|
1965
|
+
const symbol = checker.getSymbolAtLocation(parameter.name);
|
|
1966
|
+
const filling = tuple[index];
|
|
1967
|
+
if (symbol && filling)
|
|
1968
|
+
bound.set(symbol, filling);
|
|
1969
|
+
});
|
|
1970
|
+
recordTuple(member, bound, null);
|
|
1971
|
+
minted = true;
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
return minted;
|
|
1976
|
+
};
|
|
1392
1977
|
/**
|
|
1393
1978
|
* The generic declarations a node is written INSIDE, innermost first --
|
|
1394
1979
|
* exactly the scopes whose copies can fill a hole this node spells.
|
|
@@ -1421,10 +2006,10 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
1421
2006
|
// resolved signature `fillingOf` reads. A copy with no call behind it
|
|
1422
2007
|
// answers nothing and the site stays honestly uninstantiated.
|
|
1423
2008
|
const ordinal = ordinalOfArguments(owner, tuple);
|
|
1424
|
-
const image = ordinal === null ?
|
|
1425
|
-
return image !==
|
|
2009
|
+
const image = ordinal === null ? null : compositeImageOf(owner, ordinal, filling);
|
|
2010
|
+
return image !== null && !containsHole(image) ? image : null;
|
|
1426
2011
|
}
|
|
1427
|
-
const parameter = filling
|
|
2012
|
+
const parameter = typeParameterDeclarationOf(filling);
|
|
1428
2013
|
if (!parameter || !ts.isTypeParameterDeclaration(parameter))
|
|
1429
2014
|
return null;
|
|
1430
2015
|
const index = typeParametersOf(owner).indexOf(parameter);
|
|
@@ -1523,6 +2108,10 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
1523
2108
|
}
|
|
1524
2109
|
}
|
|
1525
2110
|
}
|
|
2111
|
+
if (mintReinterpretationCopies())
|
|
2112
|
+
minted = true;
|
|
2113
|
+
if (mintOverrideCopies())
|
|
2114
|
+
minted = true;
|
|
1526
2115
|
if (!minted)
|
|
1527
2116
|
break;
|
|
1528
2117
|
}
|
|
@@ -1538,19 +2127,69 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
1538
2127
|
// what it answered before.
|
|
1539
2128
|
for (const declaration of declared)
|
|
1540
2129
|
built.set(declaration, []);
|
|
2130
|
+
const constructingUnion = checker;
|
|
2131
|
+
const joinOf = (types) => {
|
|
2132
|
+
const distinct = [...new Set(types)];
|
|
2133
|
+
if (distinct.length === 1)
|
|
2134
|
+
return distinct[0] ?? null;
|
|
2135
|
+
return typeof constructingUnion.getUnionType === 'function' ? constructingUnion.getUnionType(distinct) : null;
|
|
2136
|
+
};
|
|
1541
2137
|
for (const [declaration, seen] of tuples) {
|
|
1542
2138
|
const parameters = typeParametersOf(declaration);
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
2139
|
+
// A generic function literal STORED in a cell that exists once -- a class
|
|
2140
|
+
// field or an object-literal property -- is ONE function at runtime, so
|
|
2141
|
+
// every call through the cell enters the same body. Minting a body per
|
|
2142
|
+
// instantiation and storing whichever the initializer's first implicit
|
|
2143
|
+
// return reaches keys the stored function to its first instantiation:
|
|
2144
|
+
// `cached = <Key extends keyof Readers>(key) => ...` held the `'text'`
|
|
2145
|
+
// copy, whose `key === 'text'` branch folded to true, and `count()`
|
|
2146
|
+
// read a string payload as a number. (A `const f = <T>...` binding is a
|
|
2147
|
+
// cell per copy -- the census forks the declaration -- so it is exempt.)
|
|
2148
|
+
// Every copy of such a literal is therefore the JOIN of the instantiations
|
|
2149
|
+
// the program makes: each parameter filled with the union of its fillings.
|
|
2150
|
+
// The ordinals stay (calls name them), the bodies agree.
|
|
2151
|
+
const joinedArguments = (() => {
|
|
2152
|
+
if (seen.length < 2 || !(ts.isArrowFunction(declaration) || ts.isFunctionExpression(declaration)))
|
|
2153
|
+
return null;
|
|
2154
|
+
const holder = declaration.parent;
|
|
2155
|
+
if (!(ts.isPropertyDeclaration(holder) || ts.isPropertyAssignment(holder)) || holder.initializer !== declaration)
|
|
2156
|
+
return null;
|
|
2157
|
+
const joined = [];
|
|
2158
|
+
for (let index = 0; index < parameters.length; index += 1) {
|
|
2159
|
+
const joinedType = joinOf(seen.map((tuple) => tuple[index]).filter((type) => type !== undefined));
|
|
2160
|
+
if (!joinedType)
|
|
2161
|
+
return null;
|
|
2162
|
+
joined.push(joinedType);
|
|
2163
|
+
}
|
|
2164
|
+
return joined;
|
|
2165
|
+
})();
|
|
2166
|
+
const joinedImage = (open) => {
|
|
2167
|
+
const images = seen.map((_, ordinal) => compositeImageOf(declaration, ordinal, open));
|
|
2168
|
+
return images.every((image) => image !== null) ? joinOf(images) : null;
|
|
2169
|
+
};
|
|
2170
|
+
built.set(declaration, seen.map((tuple, ordinal) => joinedArguments
|
|
2171
|
+
? {
|
|
2172
|
+
ordinal,
|
|
2173
|
+
arguments: joinedArguments,
|
|
2174
|
+
instantiated: null,
|
|
2175
|
+
instantiatedSignature: null,
|
|
2176
|
+
bindingOf: (parameter) => {
|
|
2177
|
+
const index = parameters.indexOf(parameter);
|
|
2178
|
+
return index >= 0 ? (joinedArguments[index] ?? null) : null;
|
|
2179
|
+
},
|
|
2180
|
+
fillingOf: joinedImage
|
|
2181
|
+
}
|
|
2182
|
+
: {
|
|
2183
|
+
ordinal,
|
|
2184
|
+
arguments: tuple,
|
|
2185
|
+
instantiated: spellings.get(declaration)?.[ordinal] ?? null,
|
|
2186
|
+
instantiatedSignature: signaturePairs.get(declaration)?.[ordinal] ?? null,
|
|
2187
|
+
bindingOf: (parameter) => {
|
|
2188
|
+
const index = parameters.indexOf(parameter);
|
|
2189
|
+
return index >= 0 ? (tuple[index] ?? null) : null;
|
|
2190
|
+
},
|
|
2191
|
+
fillingOf: (open) => compositeImageOf(declaration, ordinal, open)
|
|
2192
|
+
}));
|
|
1554
2193
|
}
|
|
1555
2194
|
/** Whether the program mints this copy at all, rather than only naming it. See `constructions`. */
|
|
1556
2195
|
const isConstructed = (declaration, ordinal) => constructions.get(declaration)?.[ordinal] ?? true;
|
|
@@ -1606,7 +2245,50 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
1606
2245
|
return copies.map((copy) => (copy === chosen ? copy : { ...chosen, ordinal: copy.ordinal }));
|
|
1607
2246
|
},
|
|
1608
2247
|
isGeneric: (declaration) => built.has(declaration),
|
|
1609
|
-
|
|
2248
|
+
admittedUnder: (declaration, copy, path) => {
|
|
2249
|
+
const parameters = typeParametersOf(declaration);
|
|
2250
|
+
for (const [index, parameter] of parameters.entries()) {
|
|
2251
|
+
const constraint = parameter.constraint;
|
|
2252
|
+
if (!constraint || !ts.isTypeOperatorNode(constraint) || constraint.operator !== ts.SyntaxKind.KeyOfKeyword)
|
|
2253
|
+
continue;
|
|
2254
|
+
const keyed = checker.getTypeFromTypeNode(constraint.type);
|
|
2255
|
+
const keyedSymbol = keyed.flags & ts.TypeFlags.TypeParameter ? keyed.getSymbol() : undefined;
|
|
2256
|
+
const keyedDeclaration = keyedSymbol ? mergedDeclarationOf(keyedSymbol) : null;
|
|
2257
|
+
if (!keyedDeclaration)
|
|
2258
|
+
continue;
|
|
2259
|
+
let bound = null;
|
|
2260
|
+
for (let step = path.length - 1; step >= 0 && bound === null; step -= 1) {
|
|
2261
|
+
const enclosing = path[step];
|
|
2262
|
+
if (enclosing)
|
|
2263
|
+
bound = census.specializationsOf(enclosing.owner)[enclosing.ordinal]?.bindingOf(keyedDeclaration) ?? null;
|
|
2264
|
+
}
|
|
2265
|
+
if (bound === null || openFilling(bound) || bound.getStringIndexType() !== undefined)
|
|
2266
|
+
continue;
|
|
2267
|
+
if ((bound.flags & (ts.TypeFlags.Object | ts.TypeFlags.Intersection)) === 0)
|
|
2268
|
+
continue;
|
|
2269
|
+
const filling = copy.arguments[index];
|
|
2270
|
+
if (!filling)
|
|
2271
|
+
continue;
|
|
2272
|
+
const arms = filling.isUnion() ? filling.types : [filling];
|
|
2273
|
+
if (!arms.every((arm) => arm.isStringLiteral()))
|
|
2274
|
+
continue;
|
|
2275
|
+
if (arms.some((arm) => arm.isStringLiteral() && !bound.getProperty(arm.value)))
|
|
2276
|
+
return false;
|
|
2277
|
+
}
|
|
2278
|
+
return true;
|
|
2279
|
+
},
|
|
2280
|
+
specializationOfInstance: (receiverType, substitute) => {
|
|
2281
|
+
// A polymorphic `this` is a type PARAMETER whose symbol is the class
|
|
2282
|
+
// itself: it has no type arguments of its own, and its constraint is the
|
|
2283
|
+
// class at its own parameters (`FindCursor<TSchema>`), which `substitute`
|
|
2284
|
+
// fills with the enclosing copy's fillings. Read as it was, every
|
|
2285
|
+
// `this.method()` in a copy answered "no copy" and ran the base at its
|
|
2286
|
+
// root -- the MongoDB driver's `FindCursor.maxTimeMS` calling
|
|
2287
|
+
// `this.throwIfInitialized()` against an `AbstractCursor` it does not
|
|
2288
|
+
// derive from.
|
|
2289
|
+
const thisClass = (receiverType.flags & ts.TypeFlags.TypeParameter) !== 0 &&
|
|
2290
|
+
receiverType.getSymbol()?.declarations?.some((one) => ts.isClassLike(one) || ts.isInterfaceDeclaration(one)) === true;
|
|
2291
|
+
const type = thisClass ? (checker.getBaseConstraintOfType(receiverType) ?? receiverType) : receiverType;
|
|
1610
2292
|
const symbol = type.getSymbol();
|
|
1611
2293
|
const declaration = symbol?.declarations?.find((one) => ts.isClassLike(one) || ts.isInterfaceDeclaration(one));
|
|
1612
2294
|
if (!declaration || !built.has(declaration))
|
|
@@ -1639,6 +2321,20 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
1639
2321
|
const sameFillings = (left, right) => left.length === right.length && left.every((one, index) => one === right[index]);
|
|
1640
2322
|
if (fillings.every((right) => sameFillings(fillings[0] ?? [], right)))
|
|
1641
2323
|
return false;
|
|
2324
|
+
// A reinterpreted class is one object at every instantiation, so it
|
|
2325
|
+
// is one layout; `canonicalLayoutFillings` names it.
|
|
2326
|
+
if (reinterpretationTupleOf(declaration) !== null)
|
|
2327
|
+
return false;
|
|
2328
|
+
// A base class that splits splits its derived classes with it: one
|
|
2329
|
+
// derived struct can extend only one base struct. mongodb's
|
|
2330
|
+
// `ListCollectionsCursor<T> extends AbstractCursor<T>` is held at
|
|
2331
|
+
// `CollectionInfo` and at its default union, which are assignable to
|
|
2332
|
+
// each other and would fold below -- while `AbstractCursor` keeps
|
|
2333
|
+
// `TSchema` in mutable storage and splits on the very same fillings,
|
|
2334
|
+
// so `cursor.toArray()` resolved against an `AbstractCursor` copy the
|
|
2335
|
+
// one folded struct did not extend.
|
|
2336
|
+
if (baseCopiesDiffer(declaration, copies))
|
|
2337
|
+
return true;
|
|
1642
2338
|
// Two copies may be separate STRUCTS only if the program can never put
|
|
1643
2339
|
// one where the other is declared. TypeScript's own assignability is
|
|
1644
2340
|
// that question: `Token<number>` is assignable to `Token<unknown>`, so
|
|
@@ -1677,10 +2373,37 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
1677
2373
|
// which `TransformStream` really does construct and enqueue into,
|
|
1678
2374
|
// apart from the `Token<unknown>` arm of a union that only ever
|
|
1679
2375
|
// receives a `Token<number>`.
|
|
1680
|
-
|
|
2376
|
+
//
|
|
2377
|
+
// The `any` licence covers a copy that is only ever SPELLED, never one
|
|
2378
|
+
// that is minted too. Two constructed copies, one at `any` and one
|
|
2379
|
+
// concrete, each write their own values into the stored position, and
|
|
2380
|
+
// one struct cannot hold both: `class CaseInsensitiveMap<V = any>
|
|
2381
|
+
// extends Map<string, V>`, constructed at its `any` default and at
|
|
2382
|
+
// `unknown[]`, folded onto the `unknown[]` copy, and
|
|
2383
|
+
// `new CaseInsensitiveMap([['ReplicaSet', 'rs0']])` stored `'rs0'` into
|
|
2384
|
+
// a map of arrays -- an abort at run time. A bare `any` filling is
|
|
2385
|
+
// therefore a real difference here; a filling that is merely OPEN (a
|
|
2386
|
+
// type parameter, or a type built over one) is not yet a filling.
|
|
2387
|
+
const unfilled = (type) => type !== undefined && (type.flags & ts.TypeFlags.Any) === 0 && openFilling(type);
|
|
2388
|
+
//
|
|
2389
|
+
// A bare `any` beside a concrete filling splits only where the two
|
|
2390
|
+
// copies would really write different data (`storedDataDiffers`):
|
|
2391
|
+
// hono's `Context<E>` keeps `E` only in dynamic, callable and
|
|
2392
|
+
// self-referencing members, and splitting it made the `Context` the
|
|
2393
|
+
// dispatcher builds a different type from the one every handler takes.
|
|
2394
|
+
const bareAny = (type) => type !== undefined && (type.flags & ts.TypeFlags.Any) !== 0;
|
|
2395
|
+
const written = copies.filter((copy) => isConstructed(declaration, copy.ordinal));
|
|
1681
2396
|
if ([...layoutRelevant]
|
|
1682
2397
|
.filter((index) => stored.has(index))
|
|
1683
|
-
.some((index) => written.some((left) => written.some((right) =>
|
|
2398
|
+
.some((index) => written.some((left) => written.some((right) => {
|
|
2399
|
+
const leftFilling = left.arguments[index];
|
|
2400
|
+
const rightFilling = right.arguments[index];
|
|
2401
|
+
if (leftFilling === rightFilling || unfilled(leftFilling) || unfilled(rightFilling))
|
|
2402
|
+
return false;
|
|
2403
|
+
if (!bareAny(leftFilling) && !bareAny(rightFilling))
|
|
2404
|
+
return true;
|
|
2405
|
+
return storedDataDiffers(checker, declaration, index, left, right);
|
|
2406
|
+
}))))
|
|
1684
2407
|
return true;
|
|
1685
2408
|
const flowsInto = (source, target) => source.length === target.length &&
|
|
1686
2409
|
source.every((one, index) => {
|
|
@@ -1712,6 +2435,12 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
1712
2435
|
// Only a class that must NOT split has one shared struct to name.
|
|
1713
2436
|
if (census.copiesMayDifferInLayout(declaration))
|
|
1714
2437
|
return null;
|
|
2438
|
+
// A reinterpreted class folds onto its `any` copy, never onto a
|
|
2439
|
+
// concrete one: every concrete filling is a view the program casts
|
|
2440
|
+
// away from (`reinterpretedClasses`).
|
|
2441
|
+
const reinterpreted = reinterpretationTupleOf(declaration);
|
|
2442
|
+
if (reinterpreted !== null)
|
|
2443
|
+
return ordinalOfArguments(declaration, reinterpreted) === null ? null : reinterpreted;
|
|
1715
2444
|
const copies = built.get(declaration) ?? [];
|
|
1716
2445
|
if (copies.length < 2)
|
|
1717
2446
|
return null;
|
|
@@ -1788,6 +2517,11 @@ export const censusSpecializations = (checker, sourceFiles, reachable, namespace
|
|
|
1788
2517
|
canonicalFillings.set(declaration, answer);
|
|
1789
2518
|
return answer;
|
|
1790
2519
|
},
|
|
2520
|
+
reinterpretedCopyOf: (declaration) => {
|
|
2521
|
+
const tuple = reinterpretationTupleOf(declaration);
|
|
2522
|
+
return tuple === null ? null : ordinalOfArguments(declaration, tuple);
|
|
2523
|
+
},
|
|
2524
|
+
erasedAnyRefilledAt: (node) => erasedAnyRefilledSites.has(node),
|
|
1791
2525
|
specializationAt: (node, substitute) => {
|
|
1792
2526
|
const site = sites.get(node);
|
|
1793
2527
|
if (!site)
|