@geastack/compiler 1.0.20 → 1.0.21
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 +118 -28
- package/dist/conversion/algebra.d.ts +16 -1
- package/dist/conversion/algebra.js +2 -0
- package/dist/conversion/build.js +16 -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.js +15 -5
- 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/certify/carrier-keys.d.ts +58 -1
- package/dist/ir/certify/carrier-keys.js +158 -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 +182 -28
- 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 +196 -3
- package/dist/ir/queries.js +35 -1
- package/dist/ir/reflection-demand.d.ts +9 -4
- package/dist/ir/reflection-demand.js +400 -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 +164 -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 +21 -0
- package/dist/semantics/class-alias.js +45 -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 +177 -19
- 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 +357 -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 +26 -0
- package/dist/semantics/normalize/commonjs-require.js +355 -121
- 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/identities.js +49 -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 +10 -0
- 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 +801 -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 +1420 -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 +145 -14
- package/dist/semantics/stable-checker.d.ts +1 -1
- package/dist/semantics/stable-checker.js +7 -2
- 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 +535 -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 +375 -46
- 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 +107 -8
- 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 +1321 -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 +6 -5
- 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 +18096 -4876
- package/src/targets/cpp/runtime/gea_runtime_builtins.cpp +7 -45
- package/src/targets/cpp/runtime/gea_runtime_rtc.h +247 -0
|
@@ -0,0 +1,866 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
const protocolTags = new Map([
|
|
3
|
+
['gea-event-listen', 'listen'],
|
|
4
|
+
['gea-event-emit', 'emit'],
|
|
5
|
+
['gea-event-listeners', 'listeners'],
|
|
6
|
+
['gea-event-listener-state', 'listener-state']
|
|
7
|
+
]);
|
|
8
|
+
const strip = (expression) => {
|
|
9
|
+
let current = expression;
|
|
10
|
+
while (ts.isParenthesizedExpression(current) ||
|
|
11
|
+
ts.isAsExpression(current) ||
|
|
12
|
+
ts.isNonNullExpression(current) ||
|
|
13
|
+
ts.isSatisfiesExpression(current) ||
|
|
14
|
+
ts.isTypeAssertionExpression(current)) {
|
|
15
|
+
current = current.expression;
|
|
16
|
+
}
|
|
17
|
+
return current;
|
|
18
|
+
};
|
|
19
|
+
const memberNameText = (name) => name && (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isPrivateIdentifier(name)) ? name.text : null;
|
|
20
|
+
export const deadEventCallsOf = (checker, files, identities, heritage) => {
|
|
21
|
+
let dead = null;
|
|
22
|
+
return (call) => {
|
|
23
|
+
dead ??= solve(checker, files, identities, heritage);
|
|
24
|
+
return dead.get(call);
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const solve = (checker, files, identities, heritage) => {
|
|
28
|
+
const none = new Map();
|
|
29
|
+
const classes = new Map();
|
|
30
|
+
const protocolOfMember = new Map();
|
|
31
|
+
const protocolOfName = new Map();
|
|
32
|
+
const protocolOwners = new Set();
|
|
33
|
+
const forwarders = new Map();
|
|
34
|
+
const registrationHooks = [];
|
|
35
|
+
const collectClasses = (node) => {
|
|
36
|
+
if ((ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node)) && node.body) {
|
|
37
|
+
for (const tag of ts.getJSDocTags(node)) {
|
|
38
|
+
if (tag.tagName.text !== 'gea-event-listen-via')
|
|
39
|
+
continue;
|
|
40
|
+
const [emitter, name] = (ts.getTextOfJSDocComment(tag.comment) ?? '').trim().split(/\s+/).map(Number);
|
|
41
|
+
if (Number.isInteger(emitter) && Number.isInteger(name))
|
|
42
|
+
forwarders.set(node, { emitter: emitter, name: name });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (ts.isClassLike(node)) {
|
|
46
|
+
const id = identities.declarationIdOf(node);
|
|
47
|
+
classes.set(id, node);
|
|
48
|
+
for (const member of node.members) {
|
|
49
|
+
if (!ts.isMethodDeclaration(member) || !member.body)
|
|
50
|
+
continue;
|
|
51
|
+
const name = memberNameText(member.name);
|
|
52
|
+
if (name === null)
|
|
53
|
+
continue;
|
|
54
|
+
for (const tag of ts.getJSDocTags(member)) {
|
|
55
|
+
if (tag.tagName.text === 'gea-event-registration-hook')
|
|
56
|
+
registrationHooks.push({ owner: id, member, name });
|
|
57
|
+
const protocol = protocolTags.get(tag.tagName.text);
|
|
58
|
+
if (!protocol)
|
|
59
|
+
continue;
|
|
60
|
+
protocolOfMember.set(member, protocol);
|
|
61
|
+
protocolOfName.set(name, protocol);
|
|
62
|
+
protocolOwners.add(id);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
ts.forEachChild(node, collectClasses);
|
|
67
|
+
};
|
|
68
|
+
for (const file of files)
|
|
69
|
+
collectClasses(file);
|
|
70
|
+
if (protocolOfName.size === 0)
|
|
71
|
+
return none;
|
|
72
|
+
const ancestorsOf = (id) => heritage.get(id) ?? [];
|
|
73
|
+
const descendants = new Map();
|
|
74
|
+
for (const [id, ancestors] of heritage) {
|
|
75
|
+
for (const ancestor of ancestors) {
|
|
76
|
+
const list = descendants.get(ancestor);
|
|
77
|
+
if (list)
|
|
78
|
+
list.push(id);
|
|
79
|
+
else
|
|
80
|
+
descendants.set(ancestor, [id]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const related = (a, b) => a === b || ancestorsOf(a).includes(b) || ancestorsOf(b).includes(a);
|
|
84
|
+
const aliases = (a, b) => a === null || b === null || related(a, b);
|
|
85
|
+
const isEmitterClass = (id) => [...protocolOwners].some((owner) => related(id, owner));
|
|
86
|
+
const overlaps = (a, b) => a === null || b === null || a.some((name) => b.includes(name));
|
|
87
|
+
// The member a call dispatches to on an instance of `id`: the nearest
|
|
88
|
+
// class in its chain declaring that name. `undefined` when no class in the
|
|
89
|
+
// program declares it (an ambient or dynamic answer).
|
|
90
|
+
const implementationCache = new Map();
|
|
91
|
+
const implementationOf = (id, name) => {
|
|
92
|
+
const key = `${id}\u0000${name}`;
|
|
93
|
+
if (implementationCache.has(key))
|
|
94
|
+
return implementationCache.get(key);
|
|
95
|
+
let found;
|
|
96
|
+
for (const owner of [id, ...ancestorsOf(id)]) {
|
|
97
|
+
const node = classes.get(owner);
|
|
98
|
+
// Instance dispatch: a static member of the same name is not reached.
|
|
99
|
+
found = node?.members.find((member) => !ts.isConstructorDeclaration(member) &&
|
|
100
|
+
(ts.getCombinedModifierFlags(member) & ts.ModifierFlags.Static) === 0 &&
|
|
101
|
+
memberNameText(member.name) === name);
|
|
102
|
+
if (found)
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
implementationCache.set(key, found);
|
|
106
|
+
return found;
|
|
107
|
+
};
|
|
108
|
+
// The protocol every instance an `id`-typed receiver can hold dispatches
|
|
109
|
+
// `name` to, or `null` when some instance (the class itself or any
|
|
110
|
+
// subclass) reaches a member that does not carry it.
|
|
111
|
+
const exactProtocolOf = (id, name) => {
|
|
112
|
+
const implementation = implementationOf(id, name);
|
|
113
|
+
const protocol = implementation ? protocolOfMember.get(implementation) : undefined;
|
|
114
|
+
if (!protocol)
|
|
115
|
+
return null;
|
|
116
|
+
for (const descendant of descendants.get(id) ?? []) {
|
|
117
|
+
if (implementationOf(descendant, name) !== implementation)
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
return protocol;
|
|
121
|
+
};
|
|
122
|
+
const emitterTypes = [...protocolOwners].map((owner) => {
|
|
123
|
+
const node = classes.get(owner);
|
|
124
|
+
const symbol = node.name ? checker.getSymbolAtLocation(node.name) : undefined;
|
|
125
|
+
return symbol ? checker.getDeclaredTypeOfSymbol(symbol) : undefined;
|
|
126
|
+
});
|
|
127
|
+
// Whether a value of this static type can be an emitter: structurally, an
|
|
128
|
+
// instance of a protocol-owning class must be assignable to it. `any` and
|
|
129
|
+
// `unknown` admit one; an options record whose `once` is a boolean does not.
|
|
130
|
+
const admitsEmitter = (type) => {
|
|
131
|
+
if (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown))
|
|
132
|
+
return true;
|
|
133
|
+
return emitterTypes.some((emitter) => emitter === undefined || checker.isTypeAssignableTo(emitter, type));
|
|
134
|
+
};
|
|
135
|
+
const receiverOf = (expression) => {
|
|
136
|
+
// `super.m()` runs on `this`, an instance of the enclosing class.
|
|
137
|
+
if (expression.kind === ts.SyntaxKind.SuperKeyword) {
|
|
138
|
+
const owner = ts.findAncestor(expression, ts.isClassLike);
|
|
139
|
+
if (owner)
|
|
140
|
+
return identities.declarationIdOf(owner);
|
|
141
|
+
}
|
|
142
|
+
let type = checker.getTypeAtLocation(expression);
|
|
143
|
+
if (type.isTypeParameter())
|
|
144
|
+
type = checker.getBaseConstraintOfType(type) ?? type;
|
|
145
|
+
const node = type.isUnionOrIntersection()
|
|
146
|
+
? undefined
|
|
147
|
+
: type.getSymbol()?.declarations?.find((declaration) => ts.isClassLike(declaration));
|
|
148
|
+
if (node && ts.isClassLike(node))
|
|
149
|
+
return identities.declarationIdOf(node);
|
|
150
|
+
return admitsEmitter(checker.getNonNullableType(type)) ? null : 'none';
|
|
151
|
+
};
|
|
152
|
+
const receiverClassOf = (expression) => {
|
|
153
|
+
const receiver = receiverOf(expression);
|
|
154
|
+
return receiver === 'none' ? null : receiver;
|
|
155
|
+
};
|
|
156
|
+
// Whether a computed key can evaluate to a string that names a listen method.
|
|
157
|
+
const keyMayNameListen = (key) => keyMayName(key, (protocol) => protocol === 'listen');
|
|
158
|
+
const anyProtocol = (protocol) => protocol !== undefined;
|
|
159
|
+
const keyMayName = (key, accepts) => {
|
|
160
|
+
const type = checker.getTypeAtLocation(key);
|
|
161
|
+
if (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.String))
|
|
162
|
+
return true;
|
|
163
|
+
const members = type.isUnion() ? type.types : [type];
|
|
164
|
+
return members.some((member) => member.flags &
|
|
165
|
+
(ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.String | ts.TypeFlags.TemplateLiteral | ts.TypeFlags.StringMapping) ||
|
|
166
|
+
(member.isStringLiteral() && accepts(protocolOfName.get(member.value))));
|
|
167
|
+
};
|
|
168
|
+
const namesOf = (expression) => {
|
|
169
|
+
if (!expression)
|
|
170
|
+
return null;
|
|
171
|
+
const type = checker.getTypeAtLocation(expression);
|
|
172
|
+
if (type.isStringLiteral())
|
|
173
|
+
return [type.value];
|
|
174
|
+
if (type.isUnion() && type.types.every((member) => member.isStringLiteral())) {
|
|
175
|
+
return type.types.map((member) => member.value);
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
};
|
|
179
|
+
const registrations = [];
|
|
180
|
+
const candidates = new Map();
|
|
181
|
+
// Every protocol emit with a known receiver and a finite name set, removable or not.
|
|
182
|
+
const emitSites = new Map();
|
|
183
|
+
// What can observe whether a listener is registered, beyond its effects:
|
|
184
|
+
// a listeners query (`listeners`, `listenerCount`, ...), and an emit whose
|
|
185
|
+
// result -- true when some listener is registered -- is read.
|
|
186
|
+
const queries = [];
|
|
187
|
+
const observers = [];
|
|
188
|
+
const topLevelFunctionsOfInterest = new Map();
|
|
189
|
+
let abandoned = false;
|
|
190
|
+
const debug = process.env.GEA_EVENT_LIVENESS_DEBUG === '1';
|
|
191
|
+
const where = (node) => {
|
|
192
|
+
const file = node.getSourceFile();
|
|
193
|
+
const { line } = file.getLineAndCharacterOfPosition(node.getStart());
|
|
194
|
+
return `${file.fileName}:${line + 1}`;
|
|
195
|
+
};
|
|
196
|
+
const abandon = (node) => {
|
|
197
|
+
abandoned = true;
|
|
198
|
+
if (debug)
|
|
199
|
+
console.error(`[event-liveness] abandoned at ${where(node)}`);
|
|
200
|
+
};
|
|
201
|
+
const protocolAtCall = (receiver, name) => {
|
|
202
|
+
const protocol = protocolOfName.get(name);
|
|
203
|
+
if (!protocol)
|
|
204
|
+
return null;
|
|
205
|
+
if (receiver === null)
|
|
206
|
+
return 'possible';
|
|
207
|
+
if (!isEmitterClass(receiver))
|
|
208
|
+
return null;
|
|
209
|
+
return exactProtocolOf(receiver, name) ?? 'possible';
|
|
210
|
+
};
|
|
211
|
+
const resultUnobserved = (call) => {
|
|
212
|
+
const parent = call.parent;
|
|
213
|
+
if (ts.isExpressionStatement(parent) || ts.isVoidExpression(parent))
|
|
214
|
+
return true;
|
|
215
|
+
// The expression body of a listener argument: the dispatch discards it.
|
|
216
|
+
if ((ts.isArrowFunction(parent) && parent.body === call) || isSoleReturn(call)) {
|
|
217
|
+
const fn = ts.isArrowFunction(parent) ? parent : enclosingFunctionOf(call);
|
|
218
|
+
const site = fn ? listenerArgumentSite(fn) : null;
|
|
219
|
+
return site !== null;
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
};
|
|
223
|
+
const isSoleReturn = (call) => ts.isReturnStatement(call.parent) && ts.isBlock(call.parent.parent) && call.parent.parent.statements.length === 1;
|
|
224
|
+
const enclosingFunctionOf = (node) => {
|
|
225
|
+
for (let current = node.parent; current; current = current.parent) {
|
|
226
|
+
if (ts.isArrowFunction(current) || ts.isFunctionExpression(current))
|
|
227
|
+
return current;
|
|
228
|
+
if (ts.isFunctionLike(current))
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
};
|
|
233
|
+
// The registration call a function literal is the listener argument of.
|
|
234
|
+
const listenerArgumentSite = (fn) => {
|
|
235
|
+
let current = fn;
|
|
236
|
+
while (ts.isParenthesizedExpression(current.parent) || ts.isAsExpression(current.parent))
|
|
237
|
+
current = current.parent;
|
|
238
|
+
const call = current.parent;
|
|
239
|
+
if (!ts.isCallExpression(call) || call.arguments[1] !== current)
|
|
240
|
+
return null;
|
|
241
|
+
const callee = call.expression;
|
|
242
|
+
if (!ts.isPropertyAccessExpression(callee))
|
|
243
|
+
return null;
|
|
244
|
+
return protocolOfName.get(callee.name.text) === 'listen' ? call : null;
|
|
245
|
+
};
|
|
246
|
+
const spreadsAreArrays = (call) => call.arguments.every((argument) => {
|
|
247
|
+
if (!ts.isSpreadElement(argument))
|
|
248
|
+
return true;
|
|
249
|
+
const type = checker.getTypeAtLocation(strip(argument.expression));
|
|
250
|
+
return checker.isArrayType(type) || checker.isTupleType(type);
|
|
251
|
+
});
|
|
252
|
+
const isDynamic = (expression) => (checker.getTypeAtLocation(expression).flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0;
|
|
253
|
+
const isDefaultLibrary = (symbol) => (symbol?.declarations ?? []).some((declaration) => declaration.getSourceFile().hasNoDefaultLib);
|
|
254
|
+
// A dynamically typed function value invoked with an explicit receiver
|
|
255
|
+
// that may be an emitter: `f.call(emitter, ...)`, `f.apply(emitter, ...)`,
|
|
256
|
+
// `f.bind(emitter)` or `Reflect.apply(f, emitter, ...)` with `f` untyped
|
|
257
|
+
// can be a listen method reached through a key nothing resolves.
|
|
258
|
+
const explicitReceiverMayRegister = (call, accepts) => {
|
|
259
|
+
const callee = strip(call.expression);
|
|
260
|
+
if (!ts.isPropertyAccessExpression(callee))
|
|
261
|
+
return false;
|
|
262
|
+
const name = callee.name.text;
|
|
263
|
+
if ((name === 'call' || name === 'apply' || name === 'bind') && computedMethodValue(callee.expression, accepts)) {
|
|
264
|
+
const receiver = call.arguments[0];
|
|
265
|
+
return receiver !== undefined && admitsEmitter(checker.getNonNullableType(checker.getTypeAtLocation(receiver)));
|
|
266
|
+
}
|
|
267
|
+
if (name === 'apply' && isDefaultLibrary(checker.getSymbolAtLocation(callee)) && call.arguments.length >= 2) {
|
|
268
|
+
const [fn, receiver] = call.arguments;
|
|
269
|
+
return computedMethodValue(fn, accepts) && admitsEmitter(checker.getNonNullableType(checker.getTypeAtLocation(receiver)));
|
|
270
|
+
}
|
|
271
|
+
return false;
|
|
272
|
+
};
|
|
273
|
+
// An untyped function value that came from a string-keyed computed read --
|
|
274
|
+
// directly, or through the variable it initialized. Every other way to
|
|
275
|
+
// obtain a listen method names it, and a named read is caught where it
|
|
276
|
+
// happens.
|
|
277
|
+
const computedMethodValue = (value, accepts) => {
|
|
278
|
+
if (!isDynamic(value))
|
|
279
|
+
return false;
|
|
280
|
+
const bare = strip(value);
|
|
281
|
+
if (ts.isElementAccessExpression(bare))
|
|
282
|
+
return keyMayName(strip(bare.argumentExpression), accepts);
|
|
283
|
+
if (!ts.isIdentifier(bare))
|
|
284
|
+
return false;
|
|
285
|
+
const declaration = checker.getSymbolAtLocation(bare)?.valueDeclaration;
|
|
286
|
+
const initializer = declaration && ts.isVariableDeclaration(declaration) ? declaration.initializer : undefined;
|
|
287
|
+
const source = initializer ? strip(initializer) : undefined;
|
|
288
|
+
return source !== undefined && ts.isElementAccessExpression(source) && keyMayName(strip(source.argumentExpression), accepts);
|
|
289
|
+
};
|
|
290
|
+
// The event library's own machinery: the protocol members already model
|
|
291
|
+
// what its internal queries and emits do.
|
|
292
|
+
const insideProtocolOwner = (node) => {
|
|
293
|
+
const owner = ts.findAncestor(node.parent, ts.isClassLike);
|
|
294
|
+
return owner !== undefined && protocolOwners.has(identities.declarationIdOf(owner));
|
|
295
|
+
};
|
|
296
|
+
const insideForwarder = (node) => {
|
|
297
|
+
for (let current = node.parent; current; current = current.parent)
|
|
298
|
+
if (forwarders.has(current))
|
|
299
|
+
return true;
|
|
300
|
+
return false;
|
|
301
|
+
};
|
|
302
|
+
const forwarderOf = (call) => {
|
|
303
|
+
const declaration = checker.getResolvedSignature(call)?.declaration;
|
|
304
|
+
if (!declaration)
|
|
305
|
+
return undefined;
|
|
306
|
+
const direct = forwarders.get(declaration);
|
|
307
|
+
if (direct)
|
|
308
|
+
return direct;
|
|
309
|
+
const symbol = ts.isConstructorDeclaration(declaration)
|
|
310
|
+
? undefined
|
|
311
|
+
: checker.getSymbolAtLocation(declaration.name ?? declaration);
|
|
312
|
+
for (const candidate of symbol?.declarations ?? []) {
|
|
313
|
+
const found = forwarders.get(candidate);
|
|
314
|
+
if (found)
|
|
315
|
+
return found;
|
|
316
|
+
}
|
|
317
|
+
return undefined;
|
|
318
|
+
};
|
|
319
|
+
const isStaticMember = (name) => {
|
|
320
|
+
const declaration = checker.getSymbolAtLocation(name)?.valueDeclaration;
|
|
321
|
+
return declaration !== undefined && (ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Static) !== 0;
|
|
322
|
+
};
|
|
323
|
+
// A forwarder read as a value into an untyped slot is called where no
|
|
324
|
+
// signature resolves, so its registrations cannot be seen.
|
|
325
|
+
const forwarderValueEscapesUntyped = (node) => {
|
|
326
|
+
const parent = node.parent;
|
|
327
|
+
if ((ts.isCallExpression(parent) || ts.isNewExpression(parent)) && parent.expression === node)
|
|
328
|
+
return false;
|
|
329
|
+
if (ts.isPropertyAccessExpression(parent) && parent.expression === node)
|
|
330
|
+
return false;
|
|
331
|
+
if (ts.isIdentifier(node) && ts.isPropertyAccessExpression(parent) && parent.name === node)
|
|
332
|
+
return false;
|
|
333
|
+
const declaration = checker.getSymbolAtLocation(ts.isIdentifier(node) ? node : node.name)?.valueDeclaration;
|
|
334
|
+
if (!declaration || !forwarders.has(declaration))
|
|
335
|
+
return false;
|
|
336
|
+
const contextual = checker.getContextualType(node);
|
|
337
|
+
return contextual !== undefined && (contextual.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0;
|
|
338
|
+
};
|
|
339
|
+
const visit = (node) => {
|
|
340
|
+
if (abandoned && !debug)
|
|
341
|
+
return;
|
|
342
|
+
if ((ts.isCallExpression(node) || ts.isNewExpression(node)) && forwarders.size > 0) {
|
|
343
|
+
const forwarder = forwarderOf(node);
|
|
344
|
+
if (forwarder && !insideForwarder(node)) {
|
|
345
|
+
const args = node.arguments ?? [];
|
|
346
|
+
const emitter = args[forwarder.emitter];
|
|
347
|
+
registrations.push({
|
|
348
|
+
node,
|
|
349
|
+
receiver: emitter ? receiverClassOf(emitter) : null,
|
|
350
|
+
names: namesOf(args[forwarder.name]),
|
|
351
|
+
listener: { kind: 'effect' }
|
|
352
|
+
});
|
|
353
|
+
noteEnclosingTopLevelFunction(node);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (forwarders.size > 0 && (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node)) && forwarderValueEscapesUntyped(node))
|
|
357
|
+
abandon(node);
|
|
358
|
+
if (ts.isPropertyAccessExpression(node) && protocolOfName.has(node.name.text) && !isStaticMember(node.name)) {
|
|
359
|
+
const call = node.parent;
|
|
360
|
+
const called = ts.isCallExpression(call) && call.expression === node;
|
|
361
|
+
const resolved = receiverOf(node.expression);
|
|
362
|
+
const receiver = resolved === 'none' ? null : resolved;
|
|
363
|
+
const protocol = resolved === 'none' ? null : protocolAtCall(receiver, node.name.text);
|
|
364
|
+
if (protocol !== null) {
|
|
365
|
+
if (!called) {
|
|
366
|
+
// Read as a value, it can be bound, stored or applied anywhere.
|
|
367
|
+
if (protocolOfName.get(node.name.text) === 'listen')
|
|
368
|
+
abandon(node);
|
|
369
|
+
else
|
|
370
|
+
observers.push({ node, receiver, names: null });
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
classifyCall(call, node, receiver, protocol);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
else if (ts.isElementAccessExpression(node)) {
|
|
378
|
+
const key = strip(node.argumentExpression);
|
|
379
|
+
const receiver = receiverOf(node.expression);
|
|
380
|
+
const called = ts.isCallExpression(node.parent) && node.parent.expression === node;
|
|
381
|
+
// On an unknown receiver a computed READ yields a value that registers
|
|
382
|
+
// only once invoked with an emitter receiver -- which the explicit-this
|
|
383
|
+
// rule below catches; a computed CALL invokes it on the receiver itself.
|
|
384
|
+
if (receiver !== 'none' &&
|
|
385
|
+
(called || receiver !== null) &&
|
|
386
|
+
(receiver === null || isEmitterClass(receiver)) &&
|
|
387
|
+
keyMayNameListen(key)) {
|
|
388
|
+
abandon(node);
|
|
389
|
+
}
|
|
390
|
+
else if (receiver !== 'none' &&
|
|
391
|
+
(called || receiver !== null) &&
|
|
392
|
+
(receiver === null || isEmitterClass(receiver)) &&
|
|
393
|
+
keyMayName(key, anyProtocol)) {
|
|
394
|
+
observers.push({ node, receiver, names: null });
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
else if (ts.isCallExpression(node) && explicitReceiverMayRegister(node, (protocol) => protocol === 'listen')) {
|
|
398
|
+
abandon(node);
|
|
399
|
+
}
|
|
400
|
+
else if (ts.isCallExpression(node) && explicitReceiverMayRegister(node, anyProtocol)) {
|
|
401
|
+
observers.push({ node, receiver: null, names: null });
|
|
402
|
+
}
|
|
403
|
+
ts.forEachChild(node, visit);
|
|
404
|
+
};
|
|
405
|
+
const classifyCall = (call, callee, receiver, protocol) => {
|
|
406
|
+
const nameProtocol = protocolOfName.get(callee.name.text);
|
|
407
|
+
if (nameProtocol === 'listen') {
|
|
408
|
+
if (insideForwarder(call) || forwardsToSuper(call, callee))
|
|
409
|
+
return;
|
|
410
|
+
const through = parameterForwardingOf(call, callee);
|
|
411
|
+
registrations.push({
|
|
412
|
+
node: call,
|
|
413
|
+
receiver,
|
|
414
|
+
names: namesOf(call.arguments[0]),
|
|
415
|
+
listener: listenerSourceOf(call),
|
|
416
|
+
...(through ? { through } : {})
|
|
417
|
+
});
|
|
418
|
+
noteEnclosingTopLevelFunction(call);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (nameProtocol === 'listeners' || nameProtocol === 'listener-state') {
|
|
422
|
+
if (insideProtocolOwner(call))
|
|
423
|
+
return;
|
|
424
|
+
const through = parameterForwardingOf(call, callee);
|
|
425
|
+
queries.push({
|
|
426
|
+
node: call,
|
|
427
|
+
receiver,
|
|
428
|
+
names: namesOf(call.arguments[0]),
|
|
429
|
+
listener: { kind: 'effect' },
|
|
430
|
+
...(through ? { through } : {})
|
|
431
|
+
});
|
|
432
|
+
noteEnclosingTopLevelFunction(call);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (nameProtocol === 'emit' && !insideProtocolOwner(call) && !resultUnobserved(call)) {
|
|
436
|
+
observers.push({ node: call, receiver, names: namesOf(call.arguments[0]) });
|
|
437
|
+
}
|
|
438
|
+
if (protocol !== 'emit' || receiver === null)
|
|
439
|
+
return;
|
|
440
|
+
if (call.questionDotToken || callee.questionDotToken)
|
|
441
|
+
return;
|
|
442
|
+
const names = namesOf(call.arguments[0]);
|
|
443
|
+
if (names === null || !spreadsAreArrays(call))
|
|
444
|
+
return;
|
|
445
|
+
emitSites.set(call, { receiver, names });
|
|
446
|
+
if (names.includes('error') || !resultUnobserved(call))
|
|
447
|
+
return;
|
|
448
|
+
candidates.set(call, { receiver, names });
|
|
449
|
+
};
|
|
450
|
+
const parameterForwardingOf = (call, callee) => {
|
|
451
|
+
const parameterOf = (expression) => {
|
|
452
|
+
const bare = expression ? strip(expression) : undefined;
|
|
453
|
+
if (!bare || !ts.isIdentifier(bare))
|
|
454
|
+
return null;
|
|
455
|
+
const symbol = checker.getSymbolAtLocation(bare);
|
|
456
|
+
const found = parameterIndexOf(symbol);
|
|
457
|
+
return found && !isWrittenIn(symbol, found.fn) ? found : null;
|
|
458
|
+
};
|
|
459
|
+
const receiver = parameterOf(callee.expression);
|
|
460
|
+
const name = parameterOf(call.arguments[0]);
|
|
461
|
+
const fn = receiver?.fn ?? name?.fn;
|
|
462
|
+
if (!fn || (receiver && receiver.fn !== fn) || (name && name.fn !== fn))
|
|
463
|
+
return null;
|
|
464
|
+
const symbol = topLevelFunctionSymbolOf(fn);
|
|
465
|
+
return symbol ? { fn: symbol, receiver: receiver?.index ?? -1, name: name?.index ?? -1 } : null;
|
|
466
|
+
};
|
|
467
|
+
// An override of a listen method handing its own `(name, listener)` to the
|
|
468
|
+
// base: every call to the override is already a registration.
|
|
469
|
+
const forwardsToSuper = (call, callee) => {
|
|
470
|
+
if (callee.expression.kind !== ts.SyntaxKind.SuperKeyword)
|
|
471
|
+
return false;
|
|
472
|
+
const method = ts.findAncestor(call, ts.isMethodDeclaration);
|
|
473
|
+
if (!method || memberNameText(method.name) !== callee.name.text)
|
|
474
|
+
return false;
|
|
475
|
+
const [name, listener] = call.arguments;
|
|
476
|
+
const parameter = (argument) => {
|
|
477
|
+
const bare = argument ? strip(argument) : undefined;
|
|
478
|
+
if (!bare || !ts.isIdentifier(bare))
|
|
479
|
+
return -1;
|
|
480
|
+
const found = parameterIndexOf(checker.getSymbolAtLocation(bare));
|
|
481
|
+
return found && found.fn === method ? found.index : -1;
|
|
482
|
+
};
|
|
483
|
+
return parameter(name) === 0 && parameter(listener) === 1;
|
|
484
|
+
};
|
|
485
|
+
const parameterIndexOf = (symbol) => {
|
|
486
|
+
const declaration = symbol?.valueDeclaration;
|
|
487
|
+
if (!declaration || !ts.isParameter(declaration))
|
|
488
|
+
return null;
|
|
489
|
+
const fn = declaration.parent;
|
|
490
|
+
return { fn, index: fn.parameters.indexOf(declaration) };
|
|
491
|
+
};
|
|
492
|
+
const listenerSourceOf = (registration) => {
|
|
493
|
+
const argument = registration.arguments[1];
|
|
494
|
+
if (!argument)
|
|
495
|
+
return { kind: 'effect' };
|
|
496
|
+
const listener = strip(argument);
|
|
497
|
+
if (ts.isArrowFunction(listener) || ts.isFunctionExpression(listener)) {
|
|
498
|
+
const relay = relayEmitOf(listener);
|
|
499
|
+
return relay ? { kind: 'relay', emit: relay, forwardsName: forwardsRegisteredName(registration, relay) } : { kind: 'effect' };
|
|
500
|
+
}
|
|
501
|
+
if (!ts.isIdentifier(listener))
|
|
502
|
+
return { kind: 'effect' };
|
|
503
|
+
const symbol = checker.getSymbolAtLocation(listener);
|
|
504
|
+
const parameter = parameterIndexOf(symbol);
|
|
505
|
+
if (parameter && parameter.index === 1) {
|
|
506
|
+
const nameArgument = registration.arguments[0] ? strip(registration.arguments[0]) : undefined;
|
|
507
|
+
const nameParameter = nameArgument && ts.isIdentifier(nameArgument) ? parameterIndexOf(checker.getSymbolAtLocation(nameArgument)) : null;
|
|
508
|
+
const outer = listenerArgumentSite(parameter.fn);
|
|
509
|
+
if (nameParameter && nameParameter.fn === parameter.fn && nameParameter.index === 0 && outer) {
|
|
510
|
+
const outerNames = namesOf(outer.arguments[0]);
|
|
511
|
+
const outerCallee = outer.expression;
|
|
512
|
+
if (outerNames !== null && outerNames.length === 1 && outerNames[0] === 'newListener') {
|
|
513
|
+
return { kind: 'mirror-new-listener', source: receiverClassOf(outerCallee.expression) };
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return { kind: 'effect' };
|
|
517
|
+
}
|
|
518
|
+
const declaration = symbol?.valueDeclaration;
|
|
519
|
+
if (declaration && ts.isVariableDeclaration(declaration) && ts.isVariableDeclarationList(declaration.parent)) {
|
|
520
|
+
const loop = declaration.parent.parent;
|
|
521
|
+
if (ts.isForOfStatement(loop) && loop.initializer === declaration.parent && !isWrittenIn(symbol, loop.statement)) {
|
|
522
|
+
const source = strip(loop.expression);
|
|
523
|
+
if (ts.isCallExpression(source) && ts.isPropertyAccessExpression(source.expression)) {
|
|
524
|
+
const query = source.expression;
|
|
525
|
+
if (protocolOfName.get(query.name.text) === 'listeners') {
|
|
526
|
+
return { kind: 'mirror-listeners', source: receiverClassOf(query.expression), names: namesOf(source.arguments[0]) };
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return { kind: 'effect' };
|
|
532
|
+
};
|
|
533
|
+
const forwardsRegisteredName = (registration, emit) => {
|
|
534
|
+
const registered = registration.arguments[0] ? strip(registration.arguments[0]) : undefined;
|
|
535
|
+
const emitted = emit.arguments[0] ? strip(emit.arguments[0]) : undefined;
|
|
536
|
+
if (!registered || !emitted || !ts.isIdentifier(registered) || !ts.isIdentifier(emitted))
|
|
537
|
+
return false;
|
|
538
|
+
const symbol = checker.getSymbolAtLocation(registered);
|
|
539
|
+
const declaration = symbol?.valueDeclaration;
|
|
540
|
+
if (!symbol || symbol !== checker.getSymbolAtLocation(emitted) || !declaration || !ts.isVariableDeclaration(declaration))
|
|
541
|
+
return false;
|
|
542
|
+
return ts.isVariableDeclarationList(declaration.parent) && (declaration.parent.flags & ts.NodeFlags.Const) !== 0;
|
|
543
|
+
};
|
|
544
|
+
const isWrittenIn = (symbol, body) => {
|
|
545
|
+
let written = false;
|
|
546
|
+
const scan = (node) => {
|
|
547
|
+
if (written)
|
|
548
|
+
return;
|
|
549
|
+
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(node.left)) {
|
|
550
|
+
if (checker.getSymbolAtLocation(node.left) === symbol)
|
|
551
|
+
written = true;
|
|
552
|
+
}
|
|
553
|
+
ts.forEachChild(node, scan);
|
|
554
|
+
};
|
|
555
|
+
scan(body);
|
|
556
|
+
return written;
|
|
557
|
+
};
|
|
558
|
+
// A listener whose whole body is one emit call with trivially evaluated
|
|
559
|
+
// arguments: calling it has no effect beyond that emit's own.
|
|
560
|
+
const relayEmitOf = (fn) => {
|
|
561
|
+
let body;
|
|
562
|
+
if (ts.isBlock(fn.body)) {
|
|
563
|
+
if (fn.body.statements.length !== 1)
|
|
564
|
+
return null;
|
|
565
|
+
const statement = fn.body.statements[0];
|
|
566
|
+
if (ts.isExpressionStatement(statement))
|
|
567
|
+
body = statement.expression;
|
|
568
|
+
else if (ts.isReturnStatement(statement))
|
|
569
|
+
body = statement.expression;
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
body = fn.body;
|
|
573
|
+
}
|
|
574
|
+
if (!body)
|
|
575
|
+
return null;
|
|
576
|
+
const call = strip(body);
|
|
577
|
+
if (!ts.isCallExpression(call) || !ts.isPropertyAccessExpression(call.expression))
|
|
578
|
+
return null;
|
|
579
|
+
if (!isTrivial(call.expression.expression))
|
|
580
|
+
return null;
|
|
581
|
+
if (!call.arguments.every((argument) => isTrivial(ts.isSpreadElement(argument) ? argument.expression : argument)))
|
|
582
|
+
return null;
|
|
583
|
+
return call;
|
|
584
|
+
};
|
|
585
|
+
const isTrivial = (expression) => {
|
|
586
|
+
const bare = strip(expression);
|
|
587
|
+
return ts.isIdentifier(bare) || bare.kind === ts.SyntaxKind.ThisKeyword || ts.isStringLiteralLike(bare);
|
|
588
|
+
};
|
|
589
|
+
// A registration inside a function or class nothing references is never
|
|
590
|
+
// made. Only declarations reachable by NAME alone qualify -- a function or
|
|
591
|
+
// class declaration, a function-valued variable, or a static method of a
|
|
592
|
+
// class whose constructor never escapes as a value -- because an instance
|
|
593
|
+
// method can be reached through a computed key the checker never resolves.
|
|
594
|
+
const isStaticNamedMethod = (node) => ts.isMethodDeclaration(node) &&
|
|
595
|
+
ts.isIdentifier(node.name) &&
|
|
596
|
+
(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Static) !== 0 &&
|
|
597
|
+
ts.isClassDeclaration(node.parent) &&
|
|
598
|
+
node.parent.name !== undefined;
|
|
599
|
+
const topLevelFunctionSymbolOf = (node) => {
|
|
600
|
+
if ((ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) && node.name)
|
|
601
|
+
return checker.getSymbolAtLocation(node.name);
|
|
602
|
+
if (isStaticNamedMethod(node))
|
|
603
|
+
return checker.getSymbolAtLocation(node.name);
|
|
604
|
+
if ((ts.isArrowFunction(node) || ts.isFunctionExpression(node)) &&
|
|
605
|
+
ts.isVariableDeclaration(node.parent) &&
|
|
606
|
+
node.parent.initializer === node &&
|
|
607
|
+
ts.isIdentifier(node.parent.name)) {
|
|
608
|
+
return checker.getSymbolAtLocation(node.parent.name);
|
|
609
|
+
}
|
|
610
|
+
return undefined;
|
|
611
|
+
};
|
|
612
|
+
const noteEnclosingTopLevelFunction = (node) => {
|
|
613
|
+
for (let current = node.parent; current; current = current.parent) {
|
|
614
|
+
const symbol = topLevelFunctionSymbolOf(current);
|
|
615
|
+
if (!symbol)
|
|
616
|
+
continue;
|
|
617
|
+
const set = topLevelFunctionsOfInterest.get(symbol.name);
|
|
618
|
+
if (set)
|
|
619
|
+
set.add(symbol);
|
|
620
|
+
else
|
|
621
|
+
topLevelFunctionsOfInterest.set(symbol.name, new Set([symbol]));
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
for (const file of files)
|
|
625
|
+
visit(file);
|
|
626
|
+
if (debug)
|
|
627
|
+
console.error(`[event-liveness] scanned: abandoned=${abandoned} registrations=${registrations.length} candidates=${candidates.size}`);
|
|
628
|
+
if (abandoned || candidates.size === 0)
|
|
629
|
+
return none;
|
|
630
|
+
// The classes owning a static method of interest: a constructor that
|
|
631
|
+
// escapes as a value can have any static reached through a computed key.
|
|
632
|
+
const staticOwners = new Map();
|
|
633
|
+
for (const symbols of topLevelFunctionsOfInterest.values()) {
|
|
634
|
+
for (const symbol of symbols) {
|
|
635
|
+
const declaration = symbol.valueDeclaration;
|
|
636
|
+
if (!declaration || !isStaticNamedMethod(declaration))
|
|
637
|
+
continue;
|
|
638
|
+
const owner = checker.getSymbolAtLocation(declaration.parent.name);
|
|
639
|
+
if (!owner)
|
|
640
|
+
continue;
|
|
641
|
+
const set = staticOwners.get(owner.name);
|
|
642
|
+
if (set)
|
|
643
|
+
set.add(owner);
|
|
644
|
+
else
|
|
645
|
+
staticOwners.set(owner.name, new Set([owner]));
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
const escapedConstructors = new Set();
|
|
649
|
+
const referenced = new Set();
|
|
650
|
+
const directCalls = new Map();
|
|
651
|
+
const escapedFunctions = new Set();
|
|
652
|
+
const resolve = (node) => {
|
|
653
|
+
const symbol = checker.getSymbolAtLocation(node);
|
|
654
|
+
return symbol && symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
655
|
+
};
|
|
656
|
+
const constructorUseIsStatic = (node) => {
|
|
657
|
+
const parent = node.parent;
|
|
658
|
+
return ((ts.isPropertyAccessExpression(parent) && parent.expression === node) ||
|
|
659
|
+
(ts.isNewExpression(parent) && parent.expression === node) ||
|
|
660
|
+
ts.isExpressionWithTypeArguments(parent) ||
|
|
661
|
+
(ts.isBinaryExpression(parent) && parent.right === node && parent.operatorToken.kind === ts.SyntaxKind.InstanceOfKeyword) ||
|
|
662
|
+
ts.isExportSpecifier(parent) ||
|
|
663
|
+
ts.isImportSpecifier(parent) ||
|
|
664
|
+
ts.isImportClause(parent));
|
|
665
|
+
};
|
|
666
|
+
const scanReferences = (node) => {
|
|
667
|
+
if (ts.isIdentifier(node) && !isDeclarationName(node) && !ts.isPartOfTypeNode(node)) {
|
|
668
|
+
if (topLevelFunctionsOfInterest.has(node.text) && !ts.isExportSpecifier(node.parent)) {
|
|
669
|
+
const symbol = resolve(node);
|
|
670
|
+
if (symbol) {
|
|
671
|
+
referenced.add(symbol);
|
|
672
|
+
const parent = node.parent;
|
|
673
|
+
if (ts.isCallExpression(parent) && parent.expression === node) {
|
|
674
|
+
const calls = directCalls.get(symbol);
|
|
675
|
+
if (calls)
|
|
676
|
+
calls.push(parent);
|
|
677
|
+
else
|
|
678
|
+
directCalls.set(symbol, [parent]);
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
escapedFunctions.add(symbol);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
if (staticOwners.has(node.text) && !constructorUseIsStatic(node)) {
|
|
686
|
+
const symbol = resolve(node);
|
|
687
|
+
if (symbol && staticOwners.get(node.text).has(symbol))
|
|
688
|
+
escapedConstructors.add(symbol);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
ts.forEachChild(node, scanReferences);
|
|
692
|
+
};
|
|
693
|
+
// A declaration's own name, or an import binding: an import that nothing
|
|
694
|
+
// then reads calls nothing.
|
|
695
|
+
const isDeclarationName = (node) => {
|
|
696
|
+
const parent = node.parent;
|
|
697
|
+
if (ts.isImportSpecifier(parent) || ts.isImportClause(parent) || ts.isNamespaceImport(parent) || ts.isImportEqualsDeclaration(parent))
|
|
698
|
+
return true;
|
|
699
|
+
return parent.name === node && (ts.isDeclarationStatement(parent) || ts.isVariableDeclaration(parent) || ts.isParameter(parent));
|
|
700
|
+
};
|
|
701
|
+
for (const file of files)
|
|
702
|
+
scanReferences(file);
|
|
703
|
+
const reachable = (registration) => {
|
|
704
|
+
for (let current = registration.node.parent; current; current = current.parent) {
|
|
705
|
+
const symbol = topLevelFunctionSymbolOf(current);
|
|
706
|
+
// Only a function whose references were scanned can be judged unused.
|
|
707
|
+
if (!symbol || referenced.has(symbol) || !topLevelFunctionsOfInterest.get(symbol.name)?.has(symbol))
|
|
708
|
+
continue;
|
|
709
|
+
if (isStaticNamedMethod(current)) {
|
|
710
|
+
const owner = checker.getSymbolAtLocation(current.parent.name);
|
|
711
|
+
if (owner && escapedConstructors.has(owner))
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
716
|
+
return true;
|
|
717
|
+
};
|
|
718
|
+
const expand = (registration) => {
|
|
719
|
+
const through = registration.through;
|
|
720
|
+
if (!through || escapedFunctions.has(through.fn))
|
|
721
|
+
return [registration];
|
|
722
|
+
return (directCalls.get(through.fn) ?? []).map((site) => {
|
|
723
|
+
const receiverArgument = through.receiver >= 0 ? site.arguments[through.receiver] : undefined;
|
|
724
|
+
return {
|
|
725
|
+
node: site,
|
|
726
|
+
receiver: through.receiver >= 0 ? (receiverArgument ? receiverClassOf(receiverArgument) : null) : registration.receiver,
|
|
727
|
+
names: through.name >= 0 ? namesOf(site.arguments[through.name]) : registration.names,
|
|
728
|
+
listener: registration.listener
|
|
729
|
+
};
|
|
730
|
+
});
|
|
731
|
+
};
|
|
732
|
+
const live = registrations.flatMap(expand).filter(reachable);
|
|
733
|
+
const liveQueries = queries.flatMap(expand).filter(reachable);
|
|
734
|
+
const result = new Set(candidates.keys());
|
|
735
|
+
// `this`, a variable, or a chain of plain field reads on one: evaluating it
|
|
736
|
+
// runs no code.
|
|
737
|
+
const isInertReceiver = (expression) => {
|
|
738
|
+
const bare = strip(expression);
|
|
739
|
+
if (bare.kind === ts.SyntaxKind.ThisKeyword || ts.isIdentifier(bare))
|
|
740
|
+
return true;
|
|
741
|
+
if (!ts.isPropertyAccessExpression(bare) || bare.questionDotToken)
|
|
742
|
+
return false;
|
|
743
|
+
const declaration = checker.getSymbolAtLocation(bare.name)?.valueDeclaration;
|
|
744
|
+
return declaration !== undefined && ts.isPropertyDeclaration(declaration) && isInertReceiver(bare.expression);
|
|
745
|
+
};
|
|
746
|
+
const hookUnchanged = (receiver, member, name) => [receiver, ...(descendants.get(receiver) ?? [])].every((id) => implementationOf(id, name) === member);
|
|
747
|
+
const listenerLive = (registration, names, visiting) => {
|
|
748
|
+
const listener = registration.listener;
|
|
749
|
+
switch (listener.kind) {
|
|
750
|
+
case 'effect':
|
|
751
|
+
return true;
|
|
752
|
+
case 'relay': {
|
|
753
|
+
// Per name, an emit is live exactly when a live listener observes that
|
|
754
|
+
// name -- whether or not the emit site as a whole can be removed, which
|
|
755
|
+
// also needs its result unobserved and no `'error'` among its names.
|
|
756
|
+
const inner = listener.forwardsName ? emitSites.get(listener.emit) : undefined;
|
|
757
|
+
if (!inner)
|
|
758
|
+
return !result.has(listener.emit);
|
|
759
|
+
const forwarded = names.filter((name) => inner.names.includes(name));
|
|
760
|
+
if (forwarded.length === 0)
|
|
761
|
+
return false;
|
|
762
|
+
if (forwarded.includes('error'))
|
|
763
|
+
return true;
|
|
764
|
+
if (visiting.has(registration))
|
|
765
|
+
return false;
|
|
766
|
+
visiting.add(registration);
|
|
767
|
+
const answer = live.some((target) => aliases(target.receiver, inner.receiver) && overlaps(forwarded, target.names) && listenerLive(target, forwarded, visiting));
|
|
768
|
+
visiting.delete(registration);
|
|
769
|
+
return answer;
|
|
770
|
+
}
|
|
771
|
+
case 'mirror-new-listener':
|
|
772
|
+
case 'mirror-listeners': {
|
|
773
|
+
if (visiting.has(registration))
|
|
774
|
+
return false;
|
|
775
|
+
visiting.add(registration);
|
|
776
|
+
const sourceNames = listener.kind === 'mirror-listeners' ? listener.names : null;
|
|
777
|
+
const answer = live.some((source) => source !== registration &&
|
|
778
|
+
aliases(source.receiver, listener.source) &&
|
|
779
|
+
overlaps(names, source.names) &&
|
|
780
|
+
overlaps(source.names, sourceNames) &&
|
|
781
|
+
!(source.names?.length === 1 && source.names[0] === 'newListener') &&
|
|
782
|
+
listenerLive(source, names, visiting));
|
|
783
|
+
visiting.delete(registration);
|
|
784
|
+
return answer;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
for (let changed = true; changed;) {
|
|
789
|
+
changed = false;
|
|
790
|
+
for (const call of [...result]) {
|
|
791
|
+
const candidate = candidates.get(call);
|
|
792
|
+
const reviver = live.find((registration) => aliases(candidate.receiver, registration.receiver) &&
|
|
793
|
+
overlaps(candidate.names, registration.names) &&
|
|
794
|
+
listenerLive(registration, candidate.names, new Set()));
|
|
795
|
+
if (reviver) {
|
|
796
|
+
if (debug) {
|
|
797
|
+
console.error(`[event-liveness] revived ${where(call)} [${candidate.names.join(',')}] by ${where(reviver.node)} (${reviver.listener.kind}, receiver ${reviver.receiver ?? 'unknown'}, names ${reviver.names?.join(',') ?? 'unknown'})`);
|
|
798
|
+
}
|
|
799
|
+
result.delete(call);
|
|
800
|
+
changed = true;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
// A registration whose listener can never have an effect is removed too,
|
|
805
|
+
// when nothing can tell it was made: no listeners query and no read emit
|
|
806
|
+
// result on an aliasing receiver for an overlapping name, no
|
|
807
|
+
// `'newListener'`/`'removeListener'` listener there, and no override of the
|
|
808
|
+
// library's registration hook in the receiver's family. Only a registration
|
|
809
|
+
// made directly, in statement position, on a side-effect-free receiver
|
|
810
|
+
// qualifies. (A listener-count warning past the maximum is the one
|
|
811
|
+
// difference it can make: with fewer listeners it may not print.)
|
|
812
|
+
const answer = new Map();
|
|
813
|
+
const bookkeeping = ['error', 'newListener', 'removeListener'];
|
|
814
|
+
const registrationKeptBecause = (registration) => {
|
|
815
|
+
const call = registration.node;
|
|
816
|
+
if (!ts.isCallExpression(call) || registration.through || registration.receiver === null || registration.names === null)
|
|
817
|
+
return 'shape';
|
|
818
|
+
if (registration.listener.kind !== 'relay' || !ts.isExpressionStatement(call.parent))
|
|
819
|
+
return 'not a statement relay';
|
|
820
|
+
const names = registration.names;
|
|
821
|
+
const receiver = registration.receiver;
|
|
822
|
+
const callee = call.expression;
|
|
823
|
+
if (!ts.isPropertyAccessExpression(callee) || callee.questionDotToken || !isInertReceiver(callee.expression))
|
|
824
|
+
return 'receiver';
|
|
825
|
+
if (names.some((name) => bookkeeping.includes(name)))
|
|
826
|
+
return 'bookkeeping name';
|
|
827
|
+
if (exactProtocolOf(receiver, callee.name.text) !== 'listen') {
|
|
828
|
+
const found = implementationOf(receiver, callee.name.text);
|
|
829
|
+
const overriding = (descendants.get(receiver) ?? []).find((id) => implementationOf(id, callee.name.text) !== found);
|
|
830
|
+
return `protocol (implementation ${found ? where(found) : 'none'}, overridden in ${overriding ? where(classes.get(overriding)) : 'none'})`;
|
|
831
|
+
}
|
|
832
|
+
if (!live.includes(registration) || listenerLive(registration, names, new Set()))
|
|
833
|
+
return 'listener live';
|
|
834
|
+
if (liveQueries.some((query) => aliases(query.receiver, receiver) && overlaps(query.names, names)))
|
|
835
|
+
return 'queried';
|
|
836
|
+
const observer = observers.find((candidate) => aliases(candidate.receiver, receiver) && overlaps(candidate.names, names));
|
|
837
|
+
if (observer)
|
|
838
|
+
return `emit result read at ${where(observer.node)}`;
|
|
839
|
+
if (live.some((other) => aliases(other.receiver, receiver) && overlaps(other.names, bookkeeping.slice(1))))
|
|
840
|
+
return 'registration observed';
|
|
841
|
+
if (registrationHooks.some((hook) => related(receiver, hook.owner) && !hookUnchanged(receiver, hook.member, hook.name)))
|
|
842
|
+
return 'hook overridden';
|
|
843
|
+
return null;
|
|
844
|
+
};
|
|
845
|
+
for (const call of result)
|
|
846
|
+
answer.set(call, 'emission');
|
|
847
|
+
for (const registration of registrations) {
|
|
848
|
+
const reason = registrationKeptBecause(registration);
|
|
849
|
+
if (reason !== null) {
|
|
850
|
+
if (debug && registration.listener.kind === 'relay')
|
|
851
|
+
console.error(`[event-liveness] kept registration ${where(registration.node)}: ${reason}`);
|
|
852
|
+
continue;
|
|
853
|
+
}
|
|
854
|
+
const call = registration.node;
|
|
855
|
+
answer.set(call, 'registration');
|
|
856
|
+
}
|
|
857
|
+
if (debug) {
|
|
858
|
+
for (const [call, kind] of answer)
|
|
859
|
+
if (kind === 'registration')
|
|
860
|
+
console.error(`[event-liveness] elided registration ${where(call)}`);
|
|
861
|
+
console.error(`[event-liveness] registrations=${registrations.length} reachable=${live.length} candidates=${candidates.size} dead=${result.size}`);
|
|
862
|
+
for (const call of result)
|
|
863
|
+
console.error(`[event-liveness] dead ${where(call)}`);
|
|
864
|
+
}
|
|
865
|
+
return answer;
|
|
866
|
+
};
|