@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
|
@@ -6,15 +6,21 @@ import { implicitArgumentsReadTypeAt, inferImplicitArgumentsTuple } from './impl
|
|
|
6
6
|
import { censusArgumentsObjects } from './arguments-objects.js';
|
|
7
7
|
import { censusRefusal } from './census-refusal.js';
|
|
8
8
|
import { classFamilyMemberReadTypeOf } from './flow/class-family-member-read.js';
|
|
9
|
+
import { sourceValueSessionOf } from './flow/source-value-session.js';
|
|
10
|
+
import { interfaceFlowImplementorsOf } from '../interface-implementors.js';
|
|
9
11
|
import { omissionStatedTypeOf, statedParameterWithOmission } from './omitted-stated-parameter.js';
|
|
10
|
-
import { indexValueFlow } from './flow/value-flow.js';
|
|
12
|
+
import { implementationOfOverload, indexValueFlow } from './flow/value-flow.js';
|
|
11
13
|
import { closedArrayCalleeAuthorityOf, hasClosedMemberCallableUses } from './flow/callable-reach.js';
|
|
12
14
|
import { deferredIntrinsicProtocolLedgerOf } from './deferred-intrinsic-protocols.js';
|
|
13
|
-
import { callbackContractParameterType, callbackParameterContractsFor } from './callback-parameter-contracts.js';
|
|
15
|
+
import { callbackContractParameterType, inlineJsxCallbackParameterType, callbackParameterContractsFor } from './callback-parameter-contracts.js';
|
|
14
16
|
import { declaredClosedTupleRestElementsOf, impliedPatternElementOfArms, impliedPatternPositionPresentEverywhere } from './parameter-slot.js';
|
|
15
17
|
import { iteratorYieldTypesOf } from './producers/iteration-yield.js';
|
|
16
|
-
import { annotationStatesNothing, exactEmptyObjectLiteralType, isNullishType, containsUnstatedPosition, derivedExpressionType, indexAliasEvidence, indexedTypeOf, explicitThisCallReturnType, overloadInvariantReturnTypeAt, indexNamedCallables, isStandardInterfaceType, isBindingOnlyReference, isCalleeOf, isTrackedCallable, isUnusableEvidence as statesNoStorage, carriesNoEvidence, disjointUnionMembersOf, disjointUnionTypeOf, joinOfWrites, jsDocTypeStatesNothing, literalMemberNameOf, narrowsOnlyUnstatedPositions, withoutUndefinedMember, memberTypeOf, objectAssignTargetType, nameOfCallable, synthesizedUnionArmsAt, widestOf, impliedPatternElementRootOf, impliedPatternParameterOf } from './derived-expression-type.js';
|
|
18
|
+
import { annotationStatesNothing, exactEmptyObjectLiteralType, isNullishType, containsUnstatedPosition, derivedExpressionType, indexAliasEvidence, indexedTypeOf, explicitThisCallReturnType, overloadInvariantReturnTypeAt, arrayFromCopyTypeAt, indexNamedCallables, isStandardInterfaceType, isBindingOnlyReference, isCalleeOf, isTrackedCallable, isUnusableEvidence as statesNoStorage, carriesNoEvidence, disjointUnionMembersOf, disjointUnionTypeOf, joinOfWrites, jsDocTypeStatesNothing, literalMemberNameOf, narrowsOnlyUnstatedPositions, isStructuralConstructorType, narrowsStructuralConstructorToClasses, narrowsArrayBufferViewToViews, statesAnArrayBufferView, isLibArrayBufferViewType, withoutUndefinedMember, memberTypeOf, objectAssignTargetType, nameOfCallable, synthesizedUnionArmsAt, widestOf, impliedPatternElementRootOf, impliedPatternParameterOf } from './derived-expression-type.js';
|
|
17
19
|
import { isUnreducedTypeForm } from './unreduced-type-form.js';
|
|
20
|
+
import { noHostProvidedNames, valueSymbolAt } from './unresolvable-names.js';
|
|
21
|
+
import { isHomelessRecordArm, recordArmUnionStatementOf, recordHomeArmsAtRead } from './record-home-arms.js';
|
|
22
|
+
import { classInstanceArmsPassed, plainRecordStatementOf } from './class-instance-record-statement.js';
|
|
23
|
+
import { overrideFieldArmsOf, overrideRecordStatementOf } from './override-field-arms.js';
|
|
18
24
|
import { forEachReachableStatement } from './reachability.js';
|
|
19
25
|
/** A census that binds nothing, for callers that state no program. */
|
|
20
26
|
export const emptyParameterBindingCensus = {
|
|
@@ -140,6 +146,22 @@ const isGenericCallableType = (type) => [...type.getCallSignatures(), ...type.ge
|
|
|
140
146
|
* (`derived-expression-type.js`) for what is deliberately NOT in it --
|
|
141
147
|
* `unknown`, a named empty type, an explicit `: any`.
|
|
142
148
|
*/
|
|
149
|
+
/**
|
|
150
|
+
* JavaScript does not check arity: a call that leaves a trailing formal out
|
|
151
|
+
* binds it to `undefined`, and the checker accepts it for a JS signature that
|
|
152
|
+
* states nothing (its untyped-JS-signature relaxation) without calling the
|
|
153
|
+
* formal optional. memory-pager's `Pager(pageSize, opts)`, reached only as
|
|
154
|
+
* `pager(pageSize)`, was refused `call-passes-no-argument`, so `opts` -- and
|
|
155
|
+
* through `this.deduplicate`, the `set` reassignment and `truncate` --
|
|
156
|
+
* `Page.buffer` were all boxed. A JSDoc `@param` or a type makes the
|
|
157
|
+
* signature typed, and then `isOptionalParameter` is the authority.
|
|
158
|
+
*/
|
|
159
|
+
const omissionIsUntypedJavaScript = (parameter) => (parameter.getSourceFile().flags & ts.NodeFlags.JavaScriptFile) !== 0 &&
|
|
160
|
+
parameter.type === undefined &&
|
|
161
|
+
!parameter.dotDotDotToken &&
|
|
162
|
+
ts.isIdentifier(parameter.name) &&
|
|
163
|
+
ts.getJSDocParameterTags(parameter).length === 0 &&
|
|
164
|
+
ts.getJSDocType(parameter) === undefined;
|
|
143
165
|
const isUnannotated = (checker, parameter) => {
|
|
144
166
|
if (parameter.dotDotDotToken)
|
|
145
167
|
return false;
|
|
@@ -172,7 +194,12 @@ const isUnannotated = (checker, parameter) => {
|
|
|
172
194
|
}
|
|
173
195
|
const jsDocParamTags = ts.getJSDocParameterTags(parameter);
|
|
174
196
|
const jsDocType = ts.getJSDocType(parameter) ?? jsDocParamTags[0]?.typeExpression?.type;
|
|
175
|
-
|
|
197
|
+
// A tag with no `{type}` -- `@param [opts]`, which `declarationOverlayTransform`
|
|
198
|
+
// writes for memory-pager's `opts` because `@types/memory-pager` declares
|
|
199
|
+
// only `pageSize` -- states optionality and a description, never a type, so
|
|
200
|
+
// the parameter is as unannotated as one with no tag and falls through to
|
|
201
|
+
// the site-type test below.
|
|
202
|
+
if (jsDocType) {
|
|
176
203
|
// HELD, not landed: candidacy itself is sound (see the doc above), but
|
|
177
204
|
// admitting it before `.call`/`.apply` attribution exists (see
|
|
178
205
|
// `unwrapExplicitThisCall`) measurably regressed `EventDispatcher.
|
|
@@ -201,8 +228,7 @@ const isUnannotated = (checker, parameter) => {
|
|
|
201
228
|
// `jsDocTypeIsUninformative`; the remaining 17-18% resolve to a real type
|
|
202
229
|
// (`number | Vector3`, ...) and keep being excluded here, same as before
|
|
203
230
|
// this change.
|
|
204
|
-
if (!jsDocType ||
|
|
205
|
-
!(jsDocTypeStatesNothing(checker, jsDocType) || annotationStatesNothing(checker, jsDocType, checker.getTypeFromTypeNode(jsDocType))))
|
|
231
|
+
if (!(jsDocTypeStatesNothing(checker, jsDocType) || annotationStatesNothing(checker, jsDocType, checker.getTypeFromTypeNode(jsDocType))))
|
|
206
232
|
return false;
|
|
207
233
|
// Admit it HERE, rather than falling through to the `isAnyType(checker.
|
|
208
234
|
// getTypeAtLocation(parameter))` test below -- that test is written for
|
|
@@ -268,6 +294,39 @@ export const carriesUnsubstitutedGeneric = (checker, type, depth = 0) => {
|
|
|
268
294
|
return false;
|
|
269
295
|
return checker.getTypeArguments(reference).some((part) => carriesUnsubstitutedGeneric(checker, part, depth + 1));
|
|
270
296
|
};
|
|
297
|
+
/** Whether every value of `type` is an object -- so ToBoolean answers `true` for it. */
|
|
298
|
+
const isAlwaysTruthyType = (type) => type.isUnion()
|
|
299
|
+
? type.types.every(isAlwaysTruthyType)
|
|
300
|
+
: (type.flags & (ts.TypeFlags.Object | ts.TypeFlags.NonPrimitive)) !== 0 &&
|
|
301
|
+
(type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) === 0;
|
|
302
|
+
/**
|
|
303
|
+
* Whether `value` is the right-hand side of `p = value` written as the whole
|
|
304
|
+
* consequent of `if (!p)`, for the parameter `symbol` -- a write that runs only
|
|
305
|
+
* while the parameter holds a falsy value.
|
|
306
|
+
*/
|
|
307
|
+
const isFalsyGuardedWriteOf = (checker, value, symbol) => {
|
|
308
|
+
const unwrap = (node) => (ts.isParenthesizedExpression(node) ? unwrap(node.expression) : node);
|
|
309
|
+
const namesParameter = (node) => {
|
|
310
|
+
const bare = unwrap(node);
|
|
311
|
+
return ts.isIdentifier(bare) && checker.getSymbolAtLocation(bare) === symbol;
|
|
312
|
+
};
|
|
313
|
+
let assignment = value;
|
|
314
|
+
while (ts.isParenthesizedExpression(assignment.parent))
|
|
315
|
+
assignment = assignment.parent;
|
|
316
|
+
const binary = assignment.parent;
|
|
317
|
+
if (!ts.isBinaryExpression(binary) || binary.operatorToken.kind !== ts.SyntaxKind.EqualsToken || binary.right !== assignment)
|
|
318
|
+
return false;
|
|
319
|
+
if (!namesParameter(binary.left) || !ts.isExpressionStatement(binary.parent))
|
|
320
|
+
return false;
|
|
321
|
+
let consequent = binary.parent;
|
|
322
|
+
if (ts.isBlock(consequent.parent) && consequent.parent.statements.length === 1)
|
|
323
|
+
consequent = consequent.parent;
|
|
324
|
+
const guard = consequent.parent;
|
|
325
|
+
if (!ts.isIfStatement(guard) || guard.thenStatement !== consequent)
|
|
326
|
+
return false;
|
|
327
|
+
const condition = unwrap(guard.expression);
|
|
328
|
+
return ts.isPrefixUnaryExpression(condition) && condition.operator === ts.SyntaxKind.ExclamationToken && namesParameter(condition.operand);
|
|
329
|
+
};
|
|
271
330
|
/**
|
|
272
331
|
* A parameter the program DID type, whose statement is still only an UPPER
|
|
273
332
|
* BOUND -- one with an `any`/`unknown`/bare-`Function` position somewhere
|
|
@@ -299,7 +358,9 @@ const statedUpperBound = (checker, parameter) => {
|
|
|
299
358
|
return null;
|
|
300
359
|
if (isUnusableEvidence(declared))
|
|
301
360
|
return null;
|
|
302
|
-
if (!containsUnstatedPosition(checker, parameter.type, declared)
|
|
361
|
+
if (!containsUnstatedPosition(checker, parameter.type, declared) &&
|
|
362
|
+
!statesOnlyAConstructionConvention(declared) &&
|
|
363
|
+
!statesAnArrayBufferView(declared))
|
|
303
364
|
return null;
|
|
304
365
|
// A DEFAULTED or OPTIONAL parameter's statement is `T | undefined` to its
|
|
305
366
|
// callers, whatever its annotation spells: the absence is what the default
|
|
@@ -315,6 +376,23 @@ const statedUpperBound = (checker, parameter) => {
|
|
|
315
376
|
const absent = parameter.initializer !== undefined || parameter.questionToken !== undefined;
|
|
316
377
|
return absent ? checker.getNullableType(declared, ts.TypeFlags.Undefined) : declared;
|
|
317
378
|
};
|
|
379
|
+
/**
|
|
380
|
+
* A stated structural constructor type, alone or beside absence: the class it
|
|
381
|
+
* constructs is the one position it leaves open -- see
|
|
382
|
+
* `narrowsStructuralConstructorToClasses`.
|
|
383
|
+
*/
|
|
384
|
+
const statesOnlyAConstructionConvention = (declared) => {
|
|
385
|
+
const present = (declared.isUnion() ? declared.types : [declared]).filter((part) => (part.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined)) === 0);
|
|
386
|
+
return present.length === 1 && present[0] !== undefined && isStructuralConstructorType(present[0]);
|
|
387
|
+
};
|
|
388
|
+
/**
|
|
389
|
+
* Whether `actual` differs from the statement only where it said nothing: the
|
|
390
|
+
* shared `narrowsOnlyUnstatedPositions` test, or a closed set of classes
|
|
391
|
+
* standing in for a structural constructor type's open class identity.
|
|
392
|
+
*/
|
|
393
|
+
const narrowsStatement = (checker, anchor, stated, actual) => narrowsOnlyUnstatedPositions(checker, anchor, stated, actual) ||
|
|
394
|
+
narrowsStructuralConstructorToClasses(checker, stated, actual) ||
|
|
395
|
+
narrowsArrayBufferViewToViews(checker, stated, actual);
|
|
318
396
|
/**
|
|
319
397
|
* A pure open object dictionary whose values the program explicitly leaves
|
|
320
398
|
* dynamic.
|
|
@@ -332,12 +410,45 @@ const openDynamicObjectUpperBound = (checker, parameter) => {
|
|
|
332
410
|
if (!parameter.type || !ts.isIdentifier(parameter.name) || parameter.dotDotDotToken)
|
|
333
411
|
return null;
|
|
334
412
|
const declared = checker.getTypeFromTypeNode(parameter.type);
|
|
335
|
-
if (checker
|
|
413
|
+
if (isOpenDynamicObject(checker, declared))
|
|
414
|
+
return declared;
|
|
415
|
+
// mongodb's `decorateDecryptionResult(decrypted: Document & {
|
|
416
|
+
// [kDecoratedKeys]?: Array<string> })`: the open document beside members
|
|
417
|
+
// keyed only by program symbols, all optional. No caller's string key can
|
|
418
|
+
// name one, so the document is exactly as open as it is alone -- and the
|
|
419
|
+
// function recurses with `decrypted[k]`, an `any` that is a string or a
|
|
420
|
+
// number as often as an object, which the body's own `typeof` guard is for.
|
|
421
|
+
if (declared.isIntersection()) {
|
|
422
|
+
const open = declared.types.filter((member) => isOpenDynamicObject(checker, member));
|
|
423
|
+
const symbolKeyedOnly = (member) => (member.flags & ts.TypeFlags.Object) !== 0 &&
|
|
424
|
+
member.getCallSignatures().length === 0 &&
|
|
425
|
+
member.getConstructSignatures().length === 0 &&
|
|
426
|
+
checker.getIndexInfosOfType(member).length === 0 &&
|
|
427
|
+
checker
|
|
428
|
+
.getPropertiesOfType(member)
|
|
429
|
+
.every((property) => (property.flags & ts.SymbolFlags.Optional) !== 0 && String(property.escapedName).startsWith('__@'));
|
|
430
|
+
return open.length === 1 && declared.types.every((member) => open.includes(member) || symbolKeyedOnly(member)) ? declared : null;
|
|
431
|
+
}
|
|
432
|
+
// mongodb's `ifItFitsItSits(key, value: Record<string, any> | string)`: the
|
|
433
|
+
// open dictionary is one arm of a union whose other arms are primitives.
|
|
434
|
+
// Those primitives state their whole carrier and have no container a
|
|
435
|
+
// caller's Map could be mistaken for, so the dictionary arm is exactly as
|
|
436
|
+
// open as it is alone and the union is the same upper bound.
|
|
437
|
+
if (!declared.isUnion())
|
|
336
438
|
return null;
|
|
337
|
-
const
|
|
439
|
+
const primitive = ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BooleanLike | ts.TypeFlags.Undefined | ts.TypeFlags.Null;
|
|
440
|
+
const open = declared.types.filter((member) => isOpenDynamicObject(checker, member));
|
|
441
|
+
const rest = declared.types.filter((member) => !open.includes(member));
|
|
442
|
+
return open.length === 1 && rest.every((member) => (member.flags & primitive) !== 0) ? declared : null;
|
|
443
|
+
};
|
|
444
|
+
const isOpenDynamicObject = (checker, declared) => {
|
|
445
|
+
if ((declared.flags & ts.TypeFlags.Object) === 0)
|
|
446
|
+
return false;
|
|
447
|
+
if (checker.getPropertiesOfType(declared).length !== 0)
|
|
448
|
+
return false;
|
|
449
|
+
return checker
|
|
338
450
|
.getIndexInfosOfType(declared)
|
|
339
|
-
.
|
|
340
|
-
return dynamicStringIndex ? declared : null;
|
|
451
|
+
.some((index) => (index.keyType.flags & ts.TypeFlags.String) !== 0 && (index.type.flags & ts.TypeFlags.Any) !== 0);
|
|
341
452
|
};
|
|
342
453
|
/**
|
|
343
454
|
* A flow narrowing that changes the value's physical container identity.
|
|
@@ -349,6 +460,13 @@ const openDynamicObjectUpperBound = (checker, parameter) => {
|
|
|
349
460
|
* names to dictionary properties; treating that view as a second allocation
|
|
350
461
|
* kind loses negative narrowing when control leaves the predicate branch.
|
|
351
462
|
*/
|
|
463
|
+
/** `{ [key: string]: any }` -- mongodb's and bson's `Document`, the one object type that can view an Array or a Map. */
|
|
464
|
+
const isOpenDocumentBound = (checker, type) => {
|
|
465
|
+
if ((type.flags & ts.TypeFlags.Object) === 0 || checker.isArrayType(type) || checker.isTupleType(type))
|
|
466
|
+
return false;
|
|
467
|
+
const index = checker.getIndexInfoOfType(type, ts.IndexKind.String);
|
|
468
|
+
return index !== undefined && (index.type.flags & ts.TypeFlags.Any) !== 0 && type.getCallSignatures().length === 0;
|
|
469
|
+
};
|
|
352
470
|
const isFlowContainerType = (checker, anchor, type) => checker.isArrayType(type) || ['Map', 'Set', 'WeakMap', 'WeakSet'].some((name) => isStandardInterfaceType(checker, anchor, name, type));
|
|
353
471
|
export const indexParameterBindingProgram = (checker, files, reachable, valueFlow = indexValueFlow(checker, files, reachable), argumentsObjects = censusArgumentsObjects(checker, files)) => {
|
|
354
472
|
// `GEA_INDEX_TIMING=1` prints what one build of this index costs. It is the
|
|
@@ -358,8 +476,12 @@ export const indexParameterBindingProgram = (checker, files, reachable, valueFlo
|
|
|
358
476
|
// five without the hoist, one with it.
|
|
359
477
|
const startedAt = process.env['GEA_INDEX_TIMING'] ? performance.now() : 0;
|
|
360
478
|
const candidates = [];
|
|
479
|
+
const jsxCallbackParameters = new Map();
|
|
361
480
|
const restParameterCandidates = [];
|
|
362
481
|
const omissionSites = [];
|
|
482
|
+
const recordHomeSites = [];
|
|
483
|
+
const classInstanceSites = [];
|
|
484
|
+
const overrideRecordSites = [];
|
|
363
485
|
const assigned = new Set();
|
|
364
486
|
// An update, logical assignment, destructuring assignment, or loop binding
|
|
365
487
|
// also replaces a parameter. Sharing the write inventory prevents the
|
|
@@ -417,8 +539,11 @@ export const indexParameterBindingProgram = (checker, files, reachable, valueFlo
|
|
|
417
539
|
const visit = (node) => {
|
|
418
540
|
if (reachable.memberIsPruned(node))
|
|
419
541
|
return;
|
|
420
|
-
if (isTrackedCallable(node)) {
|
|
542
|
+
if (isTrackedCallable(node) || ts.isMethodSignature(node)) {
|
|
421
543
|
runtimeParametersOf(node).forEach((parameter, index) => {
|
|
544
|
+
const contextual = inlineJsxCallbackParameterType(checker, parameter);
|
|
545
|
+
if (contextual !== null)
|
|
546
|
+
jsxCallbackParameters.set(parameter, contextual);
|
|
422
547
|
// An UNANNOTATED rest parameter is a candidate for its OWN
|
|
423
548
|
// element-wise join (`restElementTypeAt`), never for the ordinary
|
|
424
549
|
// fixed-position sweep below -- `isUnannotated` returns `false` for
|
|
@@ -447,6 +572,15 @@ export const indexParameterBindingProgram = (checker, files, reachable, valueFlo
|
|
|
447
572
|
const omissionStated = omissionStatedTypeOf(checker, parameter);
|
|
448
573
|
if (omissionStated)
|
|
449
574
|
omissionSites.push({ declaration: node, parameter, index, stated: omissionStated });
|
|
575
|
+
const recordUnion = recordArmUnionStatementOf(checker, node, parameter);
|
|
576
|
+
if (recordUnion)
|
|
577
|
+
recordHomeSites.push({ declaration: node, parameter, index, stated: recordUnion });
|
|
578
|
+
const recordStatement = plainRecordStatementOf(checker, parameter);
|
|
579
|
+
if (recordStatement)
|
|
580
|
+
classInstanceSites.push({ declaration: node, parameter, index, stated: recordStatement });
|
|
581
|
+
const overrideStatement = overrideRecordStatementOf(checker, node, parameter);
|
|
582
|
+
if (overrideStatement)
|
|
583
|
+
overrideRecordSites.push({ declaration: node, parameter, index, stated: overrideStatement });
|
|
450
584
|
}
|
|
451
585
|
}
|
|
452
586
|
});
|
|
@@ -625,6 +759,24 @@ export const indexParameterBindingProgram = (checker, files, reachable, valueFlo
|
|
|
625
759
|
}
|
|
626
760
|
return result;
|
|
627
761
|
})();
|
|
762
|
+
const interfaceMemberBodies = new Map();
|
|
763
|
+
// The interface carrier census already proves that every store into these
|
|
764
|
+
// contracts holds one of these classes. Its physical methods must receive
|
|
765
|
+
// the contract's call-site evidence even when receiver escape analysis cannot
|
|
766
|
+
// independently close the whole object graph. This adds evidence only; the
|
|
767
|
+
// method's existing escape obligation still decides whether narrowing is safe.
|
|
768
|
+
for (const [contract, implementations] of interfaceFlowImplementorsOf(checker, files)) {
|
|
769
|
+
for (const member of contract.members) {
|
|
770
|
+
if (!ts.isMethodSignature(member))
|
|
771
|
+
continue;
|
|
772
|
+
const symbol = checker.getSymbolAtLocation(member.name);
|
|
773
|
+
if (!symbol)
|
|
774
|
+
continue;
|
|
775
|
+
const bodies = implementations.flatMap((implementation) => (checker.getPropertyOfType(checker.getTypeAtLocation(implementation), symbol.getName())?.declarations ?? []).filter((declaration) => ts.isMethodDeclaration(declaration) && declaration.body !== undefined));
|
|
776
|
+
if (bodies.length > 0)
|
|
777
|
+
interfaceMemberBodies.set(member, [...new Set(bodies)]);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
628
780
|
if (process.env['GEA_INDEX_TIMING']) {
|
|
629
781
|
process.stderr.write(`[INDEX] parameter-binding program index built in ${(performance.now() - startedAt).toFixed(0)}ms\n`);
|
|
630
782
|
}
|
|
@@ -632,10 +784,14 @@ export const indexParameterBindingProgram = (checker, files, reachable, valueFlo
|
|
|
632
784
|
implicitArgumentsUses: argumentsObjects.usesByOwner,
|
|
633
785
|
valueFlow,
|
|
634
786
|
candidates,
|
|
787
|
+
jsxCallbackParameters,
|
|
635
788
|
restParameterCandidates,
|
|
636
789
|
notReassigned,
|
|
637
790
|
reassigned,
|
|
638
791
|
omissionSites,
|
|
792
|
+
recordHomeSites,
|
|
793
|
+
classInstanceSites,
|
|
794
|
+
overrideRecordSites,
|
|
639
795
|
assigned,
|
|
640
796
|
assignedEvidence,
|
|
641
797
|
allCalls,
|
|
@@ -643,7 +799,8 @@ export const indexParameterBindingProgram = (checker, files, reachable, valueFlo
|
|
|
643
799
|
invocationOperands,
|
|
644
800
|
aliasEvidence,
|
|
645
801
|
overridesOfBaseMethod,
|
|
646
|
-
siblingMemberDeclarations
|
|
802
|
+
siblingMemberDeclarations,
|
|
803
|
+
interfaceMemberBodies
|
|
647
804
|
});
|
|
648
805
|
};
|
|
649
806
|
/**
|
|
@@ -737,7 +894,15 @@ index = indexParameterBindingProgram(checker, files, reachable),
|
|
|
737
894
|
* A one-shot census can use its index's flow; a composed census must receive
|
|
738
895
|
* the same round snapshot as the field, local, return and collection censuses.
|
|
739
896
|
*/
|
|
740
|
-
valueFlow = index.valueFlow
|
|
897
|
+
valueFlow = index.valueFlow,
|
|
898
|
+
/**
|
|
899
|
+
* Which copy of a generic body each call reaches -- see `copyTypeAt`. Absent
|
|
900
|
+
* for a caller that states no generics, which then binds per declaration
|
|
901
|
+
* exactly as before.
|
|
902
|
+
*/
|
|
903
|
+
specializations,
|
|
904
|
+
/** `UnresolvableNameCensus.hostProvidedNames`, so a name this census resolves resolves as the reference producer does. */
|
|
905
|
+
hostProvided = noHostProvidedNames) => {
|
|
741
906
|
/** Every call this program makes, grouped by the declaration its signature resolved to. */
|
|
742
907
|
const callsByDeclaration = new Map();
|
|
743
908
|
const callTargets = new Map();
|
|
@@ -760,12 +925,17 @@ valueFlow = index.valueFlow) => {
|
|
|
760
925
|
* see its doc. `callsByDeclaration` above is the one index that is NOT
|
|
761
926
|
* shared: `attributeCalls` rewrites it as bindings improve.
|
|
762
927
|
*/
|
|
763
|
-
const { allCalls, checkerAttribution, invocationOperands, aliasEvidence, overridesOfBaseMethod, siblingMemberDeclarations, assignedEvidence } = index;
|
|
928
|
+
const { allCalls, checkerAttribution, invocationOperands, aliasEvidence, overridesOfBaseMethod, siblingMemberDeclarations, interfaceMemberBodies, assignedEvidence } = index;
|
|
764
929
|
const protocolLedger = deferredIntrinsicProtocolLedgerOf(valueFlow);
|
|
765
930
|
const protocolRequirements = new Map();
|
|
766
931
|
const upstreamProtocolRequirements = protocolLedger?.requirements() ?? [];
|
|
767
932
|
/** What each bound parameter declaration now holds. */
|
|
768
933
|
const bindings = new Map();
|
|
934
|
+
for (const [parameter, type] of index.jsxCallbackParameters) {
|
|
935
|
+
const symbol = checker.getSymbolAtLocation(parameter.name);
|
|
936
|
+
if (symbol && !index.assigned.has(symbol))
|
|
937
|
+
bindings.set(parameter, type);
|
|
938
|
+
}
|
|
769
939
|
/** Synthesized union arms for a disjointly-disagreeing parameter -- see `agreedArgumentType`. */
|
|
770
940
|
const unionArms = new Map();
|
|
771
941
|
// A synthesized parameter union is also a value read by sibling parameter
|
|
@@ -784,11 +954,68 @@ valueFlow = index.valueFlow) => {
|
|
|
784
954
|
unionTypes.set(parameter, disjointUnionTypeOf(checker, arms));
|
|
785
955
|
return unionTypes.get(parameter) ?? null;
|
|
786
956
|
};
|
|
957
|
+
/**
|
|
958
|
+
* The STATED parameters `statedUnionArmsRefusal` admitted a synthesized
|
|
959
|
+
* union for. Their cell holds different arms at different points of the
|
|
960
|
+
* body -- `isSuperset`'s `set` is the caller's `string[]` until
|
|
961
|
+
* `set = Array.isArray(set) ? new Set(set) : set` rebinds it -- and the
|
|
962
|
+
* checker's control flow says which one a read sees. A read the flow
|
|
963
|
+
* narrowed to exactly one arm is typed as that arm (`flowArmOf`), and its
|
|
964
|
+
* binding read projects the arm out of the cell with the runtime-checked
|
|
965
|
+
* exact-arm projection (`narrowedBindingRead`, the operand's `asserted`).
|
|
966
|
+
*/
|
|
967
|
+
const statedUnionParameters = new Set();
|
|
968
|
+
const flowArmOf = (node, parameter) => {
|
|
969
|
+
if (flowCarrierArms.has(parameter)) {
|
|
970
|
+
const carried = flowCarrierArmsOf(node, parameter);
|
|
971
|
+
return carried?.length === 1 ? carried[0] : null;
|
|
972
|
+
}
|
|
973
|
+
if (!statedUnionParameters.has(parameter))
|
|
974
|
+
return null;
|
|
975
|
+
const arms = unionArms.get(parameter);
|
|
976
|
+
if (!arms)
|
|
977
|
+
return null;
|
|
978
|
+
const flow = checker.getTypeAtLocation(node);
|
|
979
|
+
const matching = arms.filter((arm) => arm === flow || (checker.isTypeAssignableTo(arm, flow) && checker.isTypeAssignableTo(flow, arm)));
|
|
980
|
+
return matching.length === 1 ? matching[0] : null;
|
|
981
|
+
};
|
|
787
982
|
/** What each array-pattern element reads before its default -- see `patternReadTypeAt`. */
|
|
788
983
|
const patternReadTypes = new Map();
|
|
789
984
|
/** Physical object arms proven by flow narrowing of an open dynamic-object upper bound. */
|
|
790
985
|
const flowCarrierArms = new Map();
|
|
791
986
|
const flowCarrierBounds = new Map();
|
|
987
|
+
/** A stated record union's declared arms plus the callers' records it had no single home for -- see `record-home-arms.ts`. */
|
|
988
|
+
const recordHomeArms = new Map();
|
|
989
|
+
/**
|
|
990
|
+
* The one physical arm a read of an open-document cell holds where the
|
|
991
|
+
* checker's flow narrowed it to a container: bson's `makeFrame(sourceObject:
|
|
992
|
+
* Document)` reads `sourceObject` as `any[]` under `Array.isArray`. The cell
|
|
993
|
+
* is the arm union, and typing that read as the whole cell let the store
|
|
994
|
+
* into a `Document` slot select the dictionary arm out of an array --
|
|
995
|
+
* certified, and reading the array's bytes as a dictionary. A read at the
|
|
996
|
+
* upper bound itself is the whole cell (`null`, `unionArmsAt` answers it).
|
|
997
|
+
* `any[]` matches every array arm -- a caller's `number[]` beside the
|
|
998
|
+
* body's own `any[]` -- and `Array.isArray` is true of each, so such a read
|
|
999
|
+
* is the sub-union of those arms, never one picked from among them.
|
|
1000
|
+
*/
|
|
1001
|
+
const flowCarrierArmsOf = (node, parameter) => {
|
|
1002
|
+
const arms = flowCarrierArms.get(parameter);
|
|
1003
|
+
const upper = flowCarrierBounds.get(parameter);
|
|
1004
|
+
if (!arms || !upper)
|
|
1005
|
+
return null;
|
|
1006
|
+
const flow = checker.getNonNullableType(checker.getTypeAtLocation(node));
|
|
1007
|
+
if (!isFlowContainerType(checker, node, flow))
|
|
1008
|
+
return null;
|
|
1009
|
+
// The open document itself stays an arm of an Array or Map read: it may
|
|
1010
|
+
// VIEW one (`gea::dictionary::aliasOf`) -- a caller's `Document` that
|
|
1011
|
+
// holds a Map passes `instanceof Map` exactly as the Map arm does.
|
|
1012
|
+
const viewable = checker.isArrayType(flow) || isStandardInterfaceType(checker, node, 'Map', flow);
|
|
1013
|
+
const bounds = upper.isUnion() ? upper.types : [upper];
|
|
1014
|
+
const matching = arms.filter((arm) => arm === flow ||
|
|
1015
|
+
(checker.isTypeAssignableTo(arm, flow) && checker.isTypeAssignableTo(flow, arm)) ||
|
|
1016
|
+
(viewable && bounds.includes(arm) && !isFlowContainerType(checker, node, arm) && isOpenDocumentBound(checker, arm)));
|
|
1017
|
+
return matching.length === 0 ? null : matching;
|
|
1018
|
+
};
|
|
792
1019
|
/**
|
|
793
1020
|
* Whether every reference to this function's name is a call this census
|
|
794
1021
|
* counted. A function nothing holds as a value has exactly the callers this
|
|
@@ -1012,6 +1239,17 @@ valueFlow = index.valueFlow) => {
|
|
|
1012
1239
|
};
|
|
1013
1240
|
const escapeReason = (declaration, requireCountedReferences = false) => {
|
|
1014
1241
|
memberOpenUses.delete(declaration);
|
|
1242
|
+
if (ts.isMethodSignature(declaration)) {
|
|
1243
|
+
// An interface has no executable body to escape. Its physical call
|
|
1244
|
+
// frame can follow the caller census only when the joint value graph
|
|
1245
|
+
// closes every receiver and implementation used through this signature.
|
|
1246
|
+
const calls = callsByDeclaration.get(declaration) ?? [];
|
|
1247
|
+
const sourceValues = sourceValueSessionOf(checker, valueFlow);
|
|
1248
|
+
return calls.length > 0 &&
|
|
1249
|
+
calls.every((call) => ts.isCallExpression(call) && sourceValues.ownsInvocation(call) && (sourceValues.invocationTargetsOf(call)?.length ?? 0) > 0)
|
|
1250
|
+
? null
|
|
1251
|
+
: 'function-escapes:uncounted-member-reference';
|
|
1252
|
+
}
|
|
1015
1253
|
const name = nameOfCallable(declaration);
|
|
1016
1254
|
if (!name)
|
|
1017
1255
|
return `function-escapes:unnamed:${declaration.parent ? ts.SyntaxKind[declaration.parent.kind] : 'root'}`;
|
|
@@ -1308,10 +1546,17 @@ valueFlow = index.valueFlow) => {
|
|
|
1308
1546
|
if (declaration && ts.isBindingElement(declaration) && impliedPatternElementRootOf(checker, declaration) !== null)
|
|
1309
1547
|
return null;
|
|
1310
1548
|
}
|
|
1549
|
+
// The checker's `any[]` for an `Array.from` it instantiated over an
|
|
1550
|
+
// `any` source is not what the census knows the source holds: the
|
|
1551
|
+
// resolver's own answer (`arrayFromCopyTypeAt`) is.
|
|
1552
|
+
if (ts.isCallExpression(node) && arrayFromCopyTypeAt(checker, node, (operand) => known(operand) ?? resolve(operand)) !== null)
|
|
1553
|
+
return null;
|
|
1311
1554
|
return type;
|
|
1312
1555
|
};
|
|
1313
1556
|
const declarationOf = (node) => {
|
|
1314
|
-
|
|
1557
|
+
// `{ x }` reads the binding `x` exactly as `{ x: x }` does; the name's
|
|
1558
|
+
// own symbol is the literal's property, which holds no cell.
|
|
1559
|
+
const symbol = valueSymbolAt(checker, node, hostProvided);
|
|
1315
1560
|
const declarations = symbol?.declarations;
|
|
1316
1561
|
return declarations && declarations.length === 1 ? (declarations[0] ?? null) : null;
|
|
1317
1562
|
};
|
|
@@ -1359,7 +1604,7 @@ valueFlow = index.valueFlow) => {
|
|
|
1359
1604
|
* member initializer reads back through the same member.
|
|
1360
1605
|
*/
|
|
1361
1606
|
const propertyTypeOf = (receiver, name, at) => {
|
|
1362
|
-
const answer = memberTypeOf(checker, receiver, name, at, valueFlow);
|
|
1607
|
+
const answer = memberTypeOf(checker, receiver, name, at, valueFlow, upstream);
|
|
1363
1608
|
if (answer !== null && !isUnusableEvidence(answer))
|
|
1364
1609
|
return answer;
|
|
1365
1610
|
// A member only some classes of the receiver's closed family declare:
|
|
@@ -1654,7 +1899,7 @@ valueFlow = index.valueFlow) => {
|
|
|
1654
1899
|
if (!declaration)
|
|
1655
1900
|
return null;
|
|
1656
1901
|
if (ts.isParameter(declaration))
|
|
1657
|
-
return parameterTypeOf(declaration);
|
|
1902
|
+
return flowArmOf(node, declaration) ?? parameterTypeOf(declaration);
|
|
1658
1903
|
// A binding holds what is written into it, and EVERY write counts. Its
|
|
1659
1904
|
// initializer is one; so is every later assignment -- `let _gl = context;
|
|
1660
1905
|
// ... _gl = getContext( contextName, contextAttributes );` in
|
|
@@ -1992,7 +2237,7 @@ valueFlow = index.valueFlow) => {
|
|
|
1992
2237
|
// discarded all their supplied configuration evidence. Absence is a
|
|
1993
2238
|
// real incoming value, including when every caller omits the argument;
|
|
1994
2239
|
// only a default replaces it before the body observes the binding.
|
|
1995
|
-
if (!argument && checker.isOptionalParameter(parameter)) {
|
|
2240
|
+
if (!argument && (checker.isOptionalParameter(parameter) || omissionIsUntypedJavaScript(parameter))) {
|
|
1996
2241
|
sawOmitted = true;
|
|
1997
2242
|
if (parameter.initializer === undefined)
|
|
1998
2243
|
passed.push(checker.getUndefinedType());
|
|
@@ -2063,9 +2308,75 @@ valueFlow = index.valueFlow) => {
|
|
|
2063
2308
|
}
|
|
2064
2309
|
return { passed, sawBackEdge, sawOmitted, sawSilentSite, deferredRecursiveArguments };
|
|
2065
2310
|
};
|
|
2311
|
+
/**
|
|
2312
|
+
* The statement a GENERIC declaration makes at this parameter, as its
|
|
2313
|
+
* callers instantiate it.
|
|
2314
|
+
*
|
|
2315
|
+
* mongodb's `setDifference<T>(setA: Iterable<T>, setB: Iterable<T>)` states
|
|
2316
|
+
* `Iterable<T>`, and no concrete argument is assignable to an open `T` -- so
|
|
2317
|
+
* the upper-bound census refused a `Set<string>` and a `string[]` and the
|
|
2318
|
+
* parameters fell back to a record layout for the protocol view. What the
|
|
2319
|
+
* statement says to each caller is the signature the checker resolved there
|
|
2320
|
+
* (`Iterable<string>`); when every direct caller resolves the SAME closed
|
|
2321
|
+
* statement, that is the statement this parameter's storage answers to, and
|
|
2322
|
+
* holding the agreed argument to it is exactly the non-generic test. Callers
|
|
2323
|
+
* that disagree, a callback contract (no resolved call to read), or a
|
|
2324
|
+
* statement still open at a call site keep the refusal.
|
|
2325
|
+
*/
|
|
2326
|
+
const instantiatedStatement = (declaration, parameter, parameterIndex, stated, calls = callsByDeclaration.get(declaration) ?? []) => {
|
|
2327
|
+
if (!carriesUnsubstitutedGeneric(checker, stated))
|
|
2328
|
+
return stated;
|
|
2329
|
+
if ((contractsFor(declaration)?.length ?? 0) > 0)
|
|
2330
|
+
return null;
|
|
2331
|
+
if (calls.length === 0)
|
|
2332
|
+
return null;
|
|
2333
|
+
let agreed = null;
|
|
2334
|
+
for (const call of calls) {
|
|
2335
|
+
const signature = checker.getResolvedSignature(call);
|
|
2336
|
+
const symbol = signature?.parameters[parameterIndex];
|
|
2337
|
+
if (!symbol)
|
|
2338
|
+
return null;
|
|
2339
|
+
const instantiated = checker.getTypeOfSymbol(symbol);
|
|
2340
|
+
if (carriesUnsubstitutedGeneric(checker, instantiated))
|
|
2341
|
+
return null;
|
|
2342
|
+
if (agreed !== null && agreed !== instantiated)
|
|
2343
|
+
return null;
|
|
2344
|
+
agreed = instantiated;
|
|
2345
|
+
}
|
|
2346
|
+
if (agreed === null)
|
|
2347
|
+
return null;
|
|
2348
|
+
const absent = parameter.initializer !== undefined || parameter.questionToken !== undefined;
|
|
2349
|
+
return absent ? checker.getNullableType(agreed, ts.TypeFlags.Undefined) : agreed;
|
|
2350
|
+
};
|
|
2351
|
+
/**
|
|
2352
|
+
* Whether a synthesized disjoint union of call-site types may stand for a
|
|
2353
|
+
* STATED parameter: held to the statement exactly as a single agreed type
|
|
2354
|
+
* is, with the arms read together as the one union they are. mongodb's
|
|
2355
|
+
* `isSuperset(set: Set<any> | any[], ...)` is passed a `string[]` and
|
|
2356
|
+
* rebinds itself to `new Set(set)`: the cell holds `string[] | Set<string>`,
|
|
2357
|
+
* each arm the statement's own member with only its `any` element refined.
|
|
2358
|
+
* `null` when admitted, otherwise the refusal to record.
|
|
2359
|
+
*/
|
|
2360
|
+
const statedUnionArmsRefusal = (candidate, arms, recursive) => {
|
|
2361
|
+
if (candidate.stated === null)
|
|
2362
|
+
return 'stated-parameter-synthesized-union';
|
|
2363
|
+
if (recursive)
|
|
2364
|
+
return 'recursive-derived-argument-synthesized-union';
|
|
2365
|
+
if (arms.some((arm) => carriesUnsubstitutedGeneric(checker, arm)))
|
|
2366
|
+
return 'stated-parameter-open-generic';
|
|
2367
|
+
const stated = instantiatedStatement(candidate.declaration, candidate.parameter, candidate.index, candidate.stated);
|
|
2368
|
+
if (stated === null || !arms.every((arm) => checker.isTypeAssignableTo(arm, stated)))
|
|
2369
|
+
return 'stated-parameter-argument-not-assignable';
|
|
2370
|
+
const constructing = checker;
|
|
2371
|
+
const union = typeof constructing.getUnionType === 'function' ? constructing.getUnionType(arms) : null;
|
|
2372
|
+
if (union === null)
|
|
2373
|
+
return 'stated-parameter-synthesized-union';
|
|
2374
|
+
if (!narrowsStatement(checker, candidate.parameter, stated, union))
|
|
2375
|
+
return 'stated-parameter-narrows-a-stated-position';
|
|
2376
|
+
return null;
|
|
2377
|
+
};
|
|
2066
2378
|
/** The type every call site passes at this position, or the reason there is no single one. */
|
|
2067
|
-
const agreedArgumentType = (declaration, parameter, parameterIndex, skipSilentSites) => {
|
|
2068
|
-
const calls = callsByDeclaration.get(declaration) ?? [];
|
|
2379
|
+
const agreedArgumentType = (declaration, parameter, parameterIndex, skipSilentSites, calls = callsByDeclaration.get(declaration) ?? []) => {
|
|
2069
2380
|
const contracts = contractsFor(declaration) ?? [];
|
|
2070
2381
|
const contractTypes = [];
|
|
2071
2382
|
for (const contract of contracts) {
|
|
@@ -2144,10 +2455,24 @@ valueFlow = index.valueFlow) => {
|
|
|
2144
2455
|
// the assignment expression itself, where the operator states the result;
|
|
2145
2456
|
// every other write is resolved like any other value expression.
|
|
2146
2457
|
const parameterSymbol = ts.isIdentifier(parameter.name) ? checker.getSymbolAtLocation(parameter.name) : undefined;
|
|
2147
|
-
const
|
|
2148
|
-
const
|
|
2458
|
+
const allWrites = (parameterSymbol && assignedEvidence.get(parameterSymbol)) || [];
|
|
2459
|
+
const allWrittenTypes = allWrites.map((write) => write.operatorTyped
|
|
2149
2460
|
? checker.getTypeAtLocation(write.expression)
|
|
2150
2461
|
: (propagating.known(write.expression) ?? propagating.resolve(write.expression)));
|
|
2462
|
+
// `if (!opts) opts = {}` runs only when the cell holds a falsy value. When
|
|
2463
|
+
// every value that can reach the guard -- each supplied argument and every
|
|
2464
|
+
// OTHER write -- is an object, the guard cannot pass and the write never
|
|
2465
|
+
// executes, so it is not evidence about the cell (sparse-bitfield's
|
|
2466
|
+
// `Bitfield(opts)`, called only as `bitfield({ buffer })`). An omitted or
|
|
2467
|
+
// unresolved argument may be `undefined`, so either keeps every write.
|
|
2468
|
+
const falsyGuarded = allWrites.map((write) => !write.operatorTyped && parameterSymbol !== undefined && isFalsyGuardedWriteOf(checker, write.expression, parameterSymbol));
|
|
2469
|
+
const guardedWritesAreDead = falsyGuarded.some(Boolean) &&
|
|
2470
|
+
!resolution.sawOmitted &&
|
|
2471
|
+
!resolution.sawSilentSite &&
|
|
2472
|
+
resolution.passed.length > 0 &&
|
|
2473
|
+
[...resolution.passed, ...contractTypes, ...allWrittenTypes.filter((_, position) => !falsyGuarded[position])].every((type) => type !== null && type !== undefined && isAlwaysTruthyType(type));
|
|
2474
|
+
const writes = guardedWritesAreDead ? allWrites.filter((_, position) => !falsyGuarded[position]) : allWrites;
|
|
2475
|
+
const writtenTypes = guardedWritesAreDead ? allWrittenTypes.filter((_, position) => !falsyGuarded[position]) : allWrittenTypes;
|
|
2151
2476
|
// A complete numeric incoming frame can seed a numeric storage invariant.
|
|
2152
2477
|
// Test EVERY write under that hypothesis before publishing it. In
|
|
2153
2478
|
// particular, += is operand-sensitive: its checker answer stays any for an
|
|
@@ -2443,6 +2768,14 @@ valueFlow = index.valueFlow) => {
|
|
|
2443
2768
|
pushCall(declaration, call);
|
|
2444
2769
|
if (ts.isFunctionLike(declaration))
|
|
2445
2770
|
resolvedCallDeclarations.set(call, declaration);
|
|
2771
|
+
// An overload signature is a compile-time view: the body that runs,
|
|
2772
|
+
// and whose parameters these arguments land in, is the one
|
|
2773
|
+
// implementation. mongodb's `Connection.command` is called only
|
|
2774
|
+
// through its three overloads, so its implementation saw no call
|
|
2775
|
+
// site at all and every parameter of it stayed the annotation.
|
|
2776
|
+
const implementation = implementationOfOverload(checker, declaration);
|
|
2777
|
+
if (implementation !== null)
|
|
2778
|
+
pushCall(implementation, call);
|
|
2446
2779
|
}
|
|
2447
2780
|
// ALIAS value flow: a call through a resolved member/selector-result
|
|
2448
2781
|
// whose VALUE is a known function is a real call site of that
|
|
@@ -2452,6 +2785,17 @@ valueFlow = index.valueFlow) => {
|
|
|
2452
2785
|
if (ts.isCallExpression(call)) {
|
|
2453
2786
|
for (const aliased of aliasDeclarationsFor(call))
|
|
2454
2787
|
pushCall(aliased, call);
|
|
2788
|
+
// A structural interface signature is not the body receiving the
|
|
2789
|
+
// arguments. Attribute its closed source targets too; otherwise one
|
|
2790
|
+
// direct call can narrow a method while its interface callers vanish.
|
|
2791
|
+
const sourceValues = sourceValueSessionOf(checker, valueFlow);
|
|
2792
|
+
if (sourceValues.ownsInvocation(call)) {
|
|
2793
|
+
const implementations = sourceValues.invocationTargetsOf(call);
|
|
2794
|
+
for (const implementation of implementations ?? [])
|
|
2795
|
+
pushCall(implementation, call);
|
|
2796
|
+
if (implementations?.length === 1)
|
|
2797
|
+
resolvedCallDeclarations.set(call, implementations[0]);
|
|
2798
|
+
}
|
|
2455
2799
|
}
|
|
2456
2800
|
}
|
|
2457
2801
|
// Close the declaration relation with a worklist. A single pass depends on
|
|
@@ -2460,7 +2804,11 @@ valueFlow = index.valueFlow) => {
|
|
|
2460
2804
|
const pending = [...callsByDeclaration].flatMap(([declaration, calls]) => calls.map((call) => ({ declaration, call })));
|
|
2461
2805
|
for (let cursor = 0; cursor < pending.length; cursor++) {
|
|
2462
2806
|
const { declaration, call } = pending[cursor];
|
|
2463
|
-
const destinations = [
|
|
2807
|
+
const destinations = [
|
|
2808
|
+
...(overridesOfBaseMethod.get(declaration) ?? []),
|
|
2809
|
+
...(siblingMemberDeclarations.get(declaration) ?? []),
|
|
2810
|
+
...(interfaceMemberBodies.get(declaration) ?? [])
|
|
2811
|
+
];
|
|
2464
2812
|
for (const destination of destinations) {
|
|
2465
2813
|
if (callsByDeclaration.get(destination)?.includes(call))
|
|
2466
2814
|
continue;
|
|
@@ -2507,6 +2855,11 @@ valueFlow = index.valueFlow) => {
|
|
|
2507
2855
|
refuse('parameter-reassigned', describeParameter(candidate.parameter));
|
|
2508
2856
|
/** The subset of `bindings` that came from a STATED annotation -- see `statedTypeAt`. */
|
|
2509
2857
|
const statedBindings = new Map();
|
|
2858
|
+
for (const parameter of index.jsxCallbackParameters.keys()) {
|
|
2859
|
+
const bound = bindings.get(parameter);
|
|
2860
|
+
if (bound)
|
|
2861
|
+
statedBindings.set(parameter, bound);
|
|
2862
|
+
}
|
|
2510
2863
|
let lastRefusal = new Map();
|
|
2511
2864
|
/**
|
|
2512
2865
|
* An optional parameter with no default binds `T | undefined` in its body, whatever
|
|
@@ -2615,19 +2968,30 @@ valueFlow = index.valueFlow) => {
|
|
|
2615
2968
|
// census builds for `table.intern`, never a `ts.Type` the statement can
|
|
2616
2969
|
// be tested against, so there is nothing to hold it to.
|
|
2617
2970
|
if (candidate.stated) {
|
|
2971
|
+
if ('unionArms' in answer) {
|
|
2972
|
+
const refusal = statedUnionArmsRefusal(candidate, answer.unionArms, answer.deferredRecursiveArguments.length > 0);
|
|
2973
|
+
if (refusal !== null) {
|
|
2974
|
+
lastRefusal.set(candidate.parameter, refusal);
|
|
2975
|
+
return false;
|
|
2976
|
+
}
|
|
2977
|
+
unionArms.set(candidate.parameter, withDeclaredAbsenceArms(candidate.parameter, answer.unionArms));
|
|
2978
|
+
statedUnionParameters.add(candidate.parameter);
|
|
2979
|
+
return true;
|
|
2980
|
+
}
|
|
2618
2981
|
if (!('type' in answer)) {
|
|
2619
|
-
lastRefusal.set(candidate.parameter,
|
|
2982
|
+
lastRefusal.set(candidate.parameter, answer.refused);
|
|
2620
2983
|
return false;
|
|
2621
2984
|
}
|
|
2622
2985
|
if (carriesUnsubstitutedGeneric(checker, answer.type)) {
|
|
2623
2986
|
lastRefusal.set(candidate.parameter, 'stated-parameter-open-generic');
|
|
2624
2987
|
return false;
|
|
2625
2988
|
}
|
|
2626
|
-
|
|
2989
|
+
const stated = instantiatedStatement(candidate.declaration, candidate.parameter, candidate.index, candidate.stated);
|
|
2990
|
+
if (stated === null || !checker.isTypeAssignableTo(answer.type, stated)) {
|
|
2627
2991
|
lastRefusal.set(candidate.parameter, 'stated-parameter-argument-not-assignable');
|
|
2628
2992
|
return false;
|
|
2629
2993
|
}
|
|
2630
|
-
if (!
|
|
2994
|
+
if (!narrowsStatement(checker, candidate.parameter, stated, answer.type)) {
|
|
2631
2995
|
lastRefusal.set(candidate.parameter, 'stated-parameter-narrows-a-stated-position');
|
|
2632
2996
|
return false;
|
|
2633
2997
|
}
|
|
@@ -2810,59 +3174,135 @@ valueFlow = index.valueFlow) => {
|
|
|
2810
3174
|
// checker exposes under a pure `[string]: any` upper bound, alongside the
|
|
2811
3175
|
// dictionary arm used by unnarrowed reads. Preserve the complete finite
|
|
2812
3176
|
// member set, as the ordinary synthesized-union path does.
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
const references = symbol ? valueFlow.memberReferencesToSymbol(symbol) : [];
|
|
2819
|
-
const narrowed = [];
|
|
2820
|
-
for (const reference of references) {
|
|
2821
|
-
const type = checker.getTypeAtLocation(reference);
|
|
2822
|
-
if ((type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never)) !== 0)
|
|
2823
|
-
continue;
|
|
2824
|
-
if (!isFlowContainerType(checker, reference, type))
|
|
2825
|
-
continue;
|
|
2826
|
-
if (!checker.isTypeAssignableTo(type, upper))
|
|
2827
|
-
continue;
|
|
2828
|
-
if (checker.isTypeAssignableTo(upper, type))
|
|
3177
|
+
const publishFlowCarrierArms = () => {
|
|
3178
|
+
let grew = false;
|
|
3179
|
+
for (const candidate of notReassigned) {
|
|
3180
|
+
const upper = candidate.flowCarrierUpperBound;
|
|
3181
|
+
if (!upper || !ts.isIdentifier(candidate.parameter.name))
|
|
2829
3182
|
continue;
|
|
2830
|
-
|
|
3183
|
+
const symbol = checker.getSymbolAtLocation(candidate.parameter.name);
|
|
3184
|
+
const references = symbol ? valueFlow.memberReferencesToSymbol(symbol) : [];
|
|
3185
|
+
const narrowed = [];
|
|
3186
|
+
// The union form (`Record<string, any> | string`) is admitted for what
|
|
3187
|
+
// callers physically hand over, not for what a body guard could imagine:
|
|
3188
|
+
// mongodb's `normalizeHintField(hint?: string | Document)` tests
|
|
3189
|
+
// `Array.isArray(hint)` though no caller passes an array, and a speculative
|
|
3190
|
+
// array arm there only makes every later object read a three-way sum.
|
|
3191
|
+
for (const reference of upper.isUnion() ? [] : references) {
|
|
3192
|
+
const type = checker.getTypeAtLocation(reference);
|
|
3193
|
+
if ((type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never)) !== 0)
|
|
3194
|
+
continue;
|
|
3195
|
+
if (!isFlowContainerType(checker, reference, type))
|
|
3196
|
+
continue;
|
|
3197
|
+
if (!checker.isTypeAssignableTo(type, upper))
|
|
3198
|
+
continue;
|
|
3199
|
+
if (checker.isTypeAssignableTo(upper, type))
|
|
3200
|
+
continue;
|
|
3201
|
+
if (narrowed.some((seen) => checker.isTypeAssignableTo(type, seen) && checker.isTypeAssignableTo(seen, type)))
|
|
3202
|
+
continue;
|
|
3203
|
+
narrowed.push(type);
|
|
3204
|
+
}
|
|
3205
|
+
// A call that explicitly crosses this boundary from `any` contributes a
|
|
3206
|
+
// real dynamic arm. Plain runtime objects must remain the boxes they are;
|
|
3207
|
+
// rebuilding them as dictionaries would change identity and lose
|
|
3208
|
+
// prototype/accessor behavior. Concrete Document/Array/Map callers keep
|
|
3209
|
+
// their native arms beside it.
|
|
3210
|
+
let dynamicCallArm = null;
|
|
3211
|
+
for (const call of callsByDeclaration.get(candidate.declaration) ?? []) {
|
|
3212
|
+
const args = invocationOperands.get(call).args;
|
|
3213
|
+
const argument = args?.[candidate.index];
|
|
3214
|
+
if (!argument)
|
|
3215
|
+
continue;
|
|
3216
|
+
// Another open-document cell handed over whole hands over every arm it
|
|
3217
|
+
// holds: `describe(source: Document)` passing `source` on to
|
|
3218
|
+
// `keysOf(d: Document)` passes the array a caller put in `source`, and
|
|
3219
|
+
// a `d` that holds only the dictionary arm selected it out of the array.
|
|
3220
|
+
const forwarded = forwardedFlowCarrierArms(argument);
|
|
3221
|
+
if (forwarded !== null) {
|
|
3222
|
+
for (const arm of forwarded) {
|
|
3223
|
+
if ((arm.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0)
|
|
3224
|
+
dynamicCallArm ??= arm;
|
|
3225
|
+
else if (isFlowContainerType(checker, argument, arm) && checker.isTypeAssignableTo(arm, upper) && !narrowed.includes(arm))
|
|
3226
|
+
narrowed.push(arm);
|
|
3227
|
+
}
|
|
3228
|
+
continue;
|
|
3229
|
+
}
|
|
3230
|
+
const passed = checker.getTypeAtLocation(argument);
|
|
3231
|
+
if ((passed.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0) {
|
|
3232
|
+
dynamicCallArm ??= passed;
|
|
3233
|
+
continue;
|
|
3234
|
+
}
|
|
3235
|
+
// A caller handing over a Map, Set or Array hands over THAT object:
|
|
3236
|
+
// `makeClientMetadata` passes its `os` Map and keeps deleting from it
|
|
3237
|
+
// afterwards, so a dictionary rebuilt from it would be a copy the
|
|
3238
|
+
// caller's later writes never reach. Its container is a carrier arm of
|
|
3239
|
+
// this cell exactly as a body `instanceof Map` narrowing makes one.
|
|
3240
|
+
// A caller's own union hands over each of its members: mongodb's
|
|
3241
|
+
// `updateOne(filter, update: UpdateFilter<TSchema> | Document[])`
|
|
3242
|
+
// passes `update` on to `UpdateOneOperation(..., update: Document)`,
|
|
3243
|
+
// whose cell then holds the pipeline array as well as the document.
|
|
3244
|
+
for (const member of passed.isUnion() ? passed.types : [passed]) {
|
|
3245
|
+
if (!isFlowContainerType(checker, argument, member))
|
|
3246
|
+
continue;
|
|
3247
|
+
if (!checker.isTypeAssignableTo(member, upper))
|
|
3248
|
+
continue;
|
|
3249
|
+
// Identity, not mutual assignability: `Map<any, any>` and `Map<string,
|
|
3250
|
+
// string | Int32>` assign both ways, but they are two storages, and an
|
|
3251
|
+
// arm of one cannot hold the other without a copy.
|
|
3252
|
+
if (narrowed.includes(member))
|
|
3253
|
+
continue;
|
|
3254
|
+
narrowed.push(member);
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
const arms = [...(upper.isUnion() ? upper.types : [upper]), ...narrowed, ...(dynamicCallArm ? [dynamicCallArm] : [])];
|
|
3258
|
+
if (arms.length === (upper.isUnion() ? upper.types.length : 1))
|
|
2831
3259
|
continue;
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
// real dynamic arm. Plain runtime objects must remain the boxes they are;
|
|
2836
|
-
// rebuilding them as dictionaries would change identity and lose
|
|
2837
|
-
// prototype/accessor behavior. Concrete Document/Array/Map callers keep
|
|
2838
|
-
// their native arms beside it.
|
|
2839
|
-
let dynamicCallArm = null;
|
|
2840
|
-
for (const call of callsByDeclaration.get(candidate.declaration) ?? []) {
|
|
2841
|
-
const args = invocationOperands.get(call).args;
|
|
2842
|
-
const argument = args?.[candidate.index];
|
|
2843
|
-
if (!argument)
|
|
3260
|
+
const published = withDeclaredAbsenceArms(candidate.parameter, arms);
|
|
3261
|
+
const previous = flowCarrierArms.get(candidate.parameter);
|
|
3262
|
+
if (previous !== undefined && previous.length === published.length && previous.every((arm, index) => arm === published[index]))
|
|
2844
3263
|
continue;
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
3264
|
+
grew = true;
|
|
3265
|
+
// This late flow-container publication is a second synthesized-arm entry
|
|
3266
|
+
// point. It must preserve the same declared absence as the ordinary
|
|
3267
|
+
// `unionArms` path above; otherwise an optional open-document parameter
|
|
3268
|
+
// (BSON's `DBRef(..., fields?: Document)`) binds a required body union
|
|
3269
|
+
// while its callable slot remains optional.
|
|
3270
|
+
flowCarrierArms.set(candidate.parameter, published);
|
|
3271
|
+
flowCarrierBounds.set(candidate.parameter, upper);
|
|
3272
|
+
// The union is the cell's placement. A same-annotation binding learned
|
|
3273
|
+
// from call sites would otherwise outrank it in `parameterOf`.
|
|
3274
|
+
bindings.delete(candidate.parameter);
|
|
3275
|
+
statedBindings.delete(candidate.parameter);
|
|
3276
|
+
lastRefusal.delete(candidate.parameter);
|
|
2850
3277
|
}
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
3278
|
+
return grew;
|
|
3279
|
+
};
|
|
3280
|
+
/**
|
|
3281
|
+
* The arms an argument hands over when it is itself a read of an
|
|
3282
|
+
* open-document cell: the whole cell at its upper bound, the matching arms
|
|
3283
|
+
* where the caller's flow narrowed it, `null` for any other argument.
|
|
3284
|
+
*/
|
|
3285
|
+
const forwardedFlowCarrierArms = (argument) => {
|
|
3286
|
+
let unwrapped = argument;
|
|
3287
|
+
while (ts.isParenthesizedExpression(unwrapped))
|
|
3288
|
+
unwrapped = unwrapped.expression;
|
|
3289
|
+
if (!ts.isIdentifier(unwrapped))
|
|
3290
|
+
return null;
|
|
3291
|
+
const parameter = valueSymbolAt(checker, unwrapped, hostProvided)?.declarations?.find(ts.isParameter);
|
|
3292
|
+
const arms = parameter ? flowCarrierArms.get(parameter) : undefined;
|
|
3293
|
+
const upper = parameter ? flowCarrierBounds.get(parameter) : undefined;
|
|
3294
|
+
if (!parameter || !arms || !upper)
|
|
3295
|
+
return null;
|
|
3296
|
+
const read = checker.getNonNullableType(checker.getTypeAtLocation(unwrapped));
|
|
3297
|
+
if (checker.isTypeAssignableTo(read, upper) && checker.isTypeAssignableTo(upper, read))
|
|
3298
|
+
return arms;
|
|
3299
|
+
return flowCarrierArmsOf(unwrapped, parameter);
|
|
3300
|
+
};
|
|
3301
|
+
// A cell's arms feed the cells it is passed on to, so the publication runs
|
|
3302
|
+
// until no cell gains an arm; arms only ever grow, and each is a type some
|
|
3303
|
+
// caller or guard already states, so the set is finite.
|
|
3304
|
+
for (let round = 0; round <= notReassigned.length && publishFlowCarrierArms(); round++) {
|
|
3305
|
+
// A cell that grew may forward its new arms to the cells it is passed to.
|
|
2866
3306
|
}
|
|
2867
3307
|
// A stated JS parameter the census does not infer can still be left out by
|
|
2868
3308
|
// a caller: three's `colorBuffer.setClear( 0, 0, 0, 1 )` against the
|
|
@@ -2901,6 +3341,171 @@ valueFlow = index.valueFlow) => {
|
|
|
2901
3341
|
if (process.env['GEA_BINDING_DEBUG'])
|
|
2902
3342
|
console.error(`[STATED-OMISSION] ${describeParameter(site.parameter)} :: ${checker.typeToString(answer.type)}`);
|
|
2903
3343
|
}
|
|
3344
|
+
// A record a caller hands to a stated record union with no single home for
|
|
3345
|
+
// it -- see `record-home-arms.ts`. Asked of the settled attribution, like the
|
|
3346
|
+
// omission rule above; not gated on escape for the same reason: the declared
|
|
3347
|
+
// arms stay, so a caller the census cannot see is still held to them, and
|
|
3348
|
+
// the arm only adds the value a caller the census DOES see provably passes.
|
|
3349
|
+
for (const site of index.recordHomeSites) {
|
|
3350
|
+
if (!ts.isIdentifier(site.parameter.name) || !site.stated.isUnion())
|
|
3351
|
+
continue;
|
|
3352
|
+
const declaredArms = site.stated.types;
|
|
3353
|
+
const symbol = checker.getSymbolAtLocation(site.parameter.name);
|
|
3354
|
+
if (!symbol || index.assigned.has(symbol))
|
|
3355
|
+
continue;
|
|
3356
|
+
const added = [];
|
|
3357
|
+
for (const call of callsByDeclaration.get(site.declaration) ?? []) {
|
|
3358
|
+
const argument = invocationOperands.get(call)?.args?.[site.index];
|
|
3359
|
+
if (!argument)
|
|
3360
|
+
continue;
|
|
3361
|
+
const passed = checker.getTypeAtLocation(argument);
|
|
3362
|
+
for (const member of passed.isUnion() ? passed.types : [passed]) {
|
|
3363
|
+
if (added.includes(member) || carriesUnsubstitutedGeneric(checker, member))
|
|
3364
|
+
continue;
|
|
3365
|
+
if (isHomelessRecordArm(checker, site.stated, member))
|
|
3366
|
+
added.push(member);
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
if (added.length === 0)
|
|
3370
|
+
continue;
|
|
3371
|
+
recordHomeArms.set(site.parameter, withDeclaredAbsenceArms(site.parameter, [...declaredArms, ...added]));
|
|
3372
|
+
if (process.env['GEA_BINDING_DEBUG'])
|
|
3373
|
+
console.error(`[RECORD-HOME] ${describeParameter(site.parameter)} :: ${added.map((arm) => checker.typeToString(arm)).join(' | ')}`);
|
|
3374
|
+
}
|
|
3375
|
+
// A class instance a caller hands to a stated data record -- see
|
|
3376
|
+
// `class-instance-record-statement.ts`. The class joins the statement as
|
|
3377
|
+
// one more arm of the cell, exactly as a homeless record joins its union
|
|
3378
|
+
// above, and for the same reason needs no proof that the census found every
|
|
3379
|
+
// caller: the statement's own arm stays, so a caller it cannot see still
|
|
3380
|
+
// converts into it, and the class arm only holds what a caller it CAN see
|
|
3381
|
+
// provably passes -- the object itself, never a copy of it.
|
|
3382
|
+
for (const site of index.classInstanceSites) {
|
|
3383
|
+
if (bindings.has(site.parameter) || unionArms.has(site.parameter) || recordHomeArms.has(site.parameter))
|
|
3384
|
+
continue;
|
|
3385
|
+
if (!ts.isIdentifier(site.parameter.name))
|
|
3386
|
+
continue;
|
|
3387
|
+
const symbol = checker.getSymbolAtLocation(site.parameter.name);
|
|
3388
|
+
if (!symbol || index.assigned.has(symbol))
|
|
3389
|
+
continue;
|
|
3390
|
+
const passed = [];
|
|
3391
|
+
for (const call of callsByDeclaration.get(site.declaration) ?? []) {
|
|
3392
|
+
const argument = invocationOperands.get(call)?.args?.[site.index];
|
|
3393
|
+
if (argument)
|
|
3394
|
+
passed.push(propagating.known(argument) ?? propagating.resolve(argument) ?? checker.getTypeAtLocation(argument));
|
|
3395
|
+
}
|
|
3396
|
+
const classes = classInstanceArmsPassed(checker, site.stated, passed).filter((arm) => !carriesUnsubstitutedGeneric(checker, arm));
|
|
3397
|
+
if (classes.length === 0)
|
|
3398
|
+
continue;
|
|
3399
|
+
const declaredArms = site.stated.isUnion() ? site.stated.types : [site.stated];
|
|
3400
|
+
recordHomeArms.set(site.parameter, withDeclaredAbsenceArms(site.parameter, [...declaredArms, ...classes]));
|
|
3401
|
+
if (process.env['GEA_BINDING_DEBUG'])
|
|
3402
|
+
console.error(`[CLASS-INSTANCE] ${describeParameter(site.parameter)} :: ${classes.map((arm) => checker.typeToString(arm)).join(' | ')}`);
|
|
3403
|
+
}
|
|
3404
|
+
// A record a subclass redeclared a field as, handed to its base's
|
|
3405
|
+
// constructor -- see `override-field-arms.ts`'s `overrideRecordStatementOf`.
|
|
3406
|
+
// The same one-more-arm rule as the class instance above, on the same terms.
|
|
3407
|
+
const overrideArms = overrideFieldArmsOf(checker, files);
|
|
3408
|
+
for (const site of overrideArms.chainClasses.size === 0 ? [] : index.overrideRecordSites) {
|
|
3409
|
+
if (bindings.has(site.parameter) || unionArms.has(site.parameter) || recordHomeArms.has(site.parameter))
|
|
3410
|
+
continue;
|
|
3411
|
+
if (!ts.isIdentifier(site.parameter.name))
|
|
3412
|
+
continue;
|
|
3413
|
+
const symbol = checker.getSymbolAtLocation(site.parameter.name);
|
|
3414
|
+
if (!symbol || index.assigned.has(symbol))
|
|
3415
|
+
continue;
|
|
3416
|
+
const records = (overrideArms.parameterArms.get(site.parameter) ?? []).filter((arm) => !carriesUnsubstitutedGeneric(checker, arm));
|
|
3417
|
+
if (records.length === 0)
|
|
3418
|
+
continue;
|
|
3419
|
+
const declaredArms = site.stated.isUnion() ? site.stated.types : [site.stated];
|
|
3420
|
+
recordHomeArms.set(site.parameter, withDeclaredAbsenceArms(site.parameter, [...declaredArms, ...records]));
|
|
3421
|
+
if (process.env['GEA_BINDING_DEBUG'])
|
|
3422
|
+
console.error(`[OVERRIDE-RECORD] ${describeParameter(site.parameter)} :: ${records.map((arm) => checker.typeToString(arm)).join(' | ')}`);
|
|
3423
|
+
}
|
|
3424
|
+
// ONE STATED PARAMETER PER COPY.
|
|
3425
|
+
//
|
|
3426
|
+
// Everything above answers per DECLARATION, and holds every caller to one
|
|
3427
|
+
// agreed type. A generic body is not one body: monomorphization gives it one
|
|
3428
|
+
// copy per instantiation (`specialization.ts`), each with its own frame, so
|
|
3429
|
+
// "what does this parameter receive" is a question about the callers of ONE
|
|
3430
|
+
// copy. mongodb's `shuffle<T>(sequence: Iterable<T>)` is called with a
|
|
3431
|
+
// `Set<string>`, a `HostAddress[]` and a `ServerDescription[]`: across the
|
|
3432
|
+
// declaration those disagree and no single carrier holds all three, but each
|
|
3433
|
+
// copy is called with exactly one of them. Refused per declaration, every
|
|
3434
|
+
// copy's slot stayed the `Iterable` protocol's record, which no concrete
|
|
3435
|
+
// collection converts into without a copy -- three certification refusals.
|
|
3436
|
+
//
|
|
3437
|
+
// Asked only where the declaration-wide answer refused, of the same evidence
|
|
3438
|
+
// under the same statement tests, restricted to the calls that reach each
|
|
3439
|
+
// copy. A copy whose own callers disagree keeps the refusal, exactly as the
|
|
3440
|
+
// declaration did. The partition has to be COMPLETE: a call the census cannot
|
|
3441
|
+
// place in a copy from the root scope -- one written inside another generic
|
|
3442
|
+
// body, whose copy depends on which copy of THAT body is asking -- could
|
|
3443
|
+
// reach any of them, so one such call withholds every copy of the parameter.
|
|
3444
|
+
const copyBindings = new Map();
|
|
3445
|
+
if (specializations) {
|
|
3446
|
+
propagating.reset();
|
|
3447
|
+
for (const candidate of notReassigned) {
|
|
3448
|
+
const { declaration, parameter } = candidate;
|
|
3449
|
+
if (!candidate.stated || bindings.has(parameter) || unionArms.has(parameter) || flowCarrierArms.has(parameter))
|
|
3450
|
+
continue;
|
|
3451
|
+
if (!specializations.isGeneric(declaration))
|
|
3452
|
+
continue;
|
|
3453
|
+
const copies = specializations.specializationsOf(declaration);
|
|
3454
|
+
if (copies.length < 2)
|
|
3455
|
+
continue;
|
|
3456
|
+
if (escapeReason(declaration) !== null || (contractsFor(declaration)?.length ?? 0) > 0)
|
|
3457
|
+
continue;
|
|
3458
|
+
const calls = callsByDeclaration.get(declaration) ?? [];
|
|
3459
|
+
const callsByCopy = new Map();
|
|
3460
|
+
let complete = calls.length > 0;
|
|
3461
|
+
for (const call of calls) {
|
|
3462
|
+
const site = specializations.specializationAt(call);
|
|
3463
|
+
if (!site || site.declaration !== declaration) {
|
|
3464
|
+
complete = false;
|
|
3465
|
+
break;
|
|
3466
|
+
}
|
|
3467
|
+
const group = callsByCopy.get(site.ordinal);
|
|
3468
|
+
if (group)
|
|
3469
|
+
group.push(call);
|
|
3470
|
+
else
|
|
3471
|
+
callsByCopy.set(site.ordinal, [call]);
|
|
3472
|
+
}
|
|
3473
|
+
if (!complete)
|
|
3474
|
+
continue;
|
|
3475
|
+
const perCopy = new Map();
|
|
3476
|
+
const requirements = [];
|
|
3477
|
+
for (const [ordinal, copyCalls] of callsByCopy) {
|
|
3478
|
+
const bindCopy = () => {
|
|
3479
|
+
const answer = agreedArgumentType(declaration, parameter, candidate.index, false, copyCalls);
|
|
3480
|
+
if (!('type' in answer) || answer.sawSilentSite || answer.deferredRecursiveArguments.length > 0)
|
|
3481
|
+
return null;
|
|
3482
|
+
if (carriesUnsubstitutedGeneric(checker, answer.type))
|
|
3483
|
+
return null;
|
|
3484
|
+
const stated = instantiatedStatement(declaration, parameter, candidate.index, candidate.stated, copyCalls);
|
|
3485
|
+
if (stated === null || !checker.isTypeAssignableTo(answer.type, stated))
|
|
3486
|
+
return null;
|
|
3487
|
+
if (!narrowsStatement(checker, parameter, stated, answer.type))
|
|
3488
|
+
return null;
|
|
3489
|
+
return withDeclaredAbsence(parameter, answer.type);
|
|
3490
|
+
};
|
|
3491
|
+
const captured = protocolLedger?.capture(bindCopy) ?? { value: bindCopy(), requirements: [] };
|
|
3492
|
+
if (captured.value === null)
|
|
3493
|
+
continue;
|
|
3494
|
+
perCopy.set(ordinal, captured.value);
|
|
3495
|
+
requirements.push(...captured.requirements);
|
|
3496
|
+
}
|
|
3497
|
+
if (perCopy.size === 0)
|
|
3498
|
+
continue;
|
|
3499
|
+
copyBindings.set(parameter, perCopy);
|
|
3500
|
+
protocolRequirements.set(parameter, requirements);
|
|
3501
|
+
// The declaration-wide refusal stands for any copy still unbound.
|
|
3502
|
+
if (perCopy.size === copies.length)
|
|
3503
|
+
lastRefusal.delete(parameter);
|
|
3504
|
+
if (process.env['GEA_BINDING_DEBUG'])
|
|
3505
|
+
for (const [ordinal, type] of perCopy)
|
|
3506
|
+
console.error(`[COPY-BINDING] ${describeParameter(parameter)} #${ordinal} :: ${checker.typeToString(type)}`);
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
2904
3509
|
for (const [parameter, reason] of lastRefusal)
|
|
2905
3510
|
refuse(reason, describeParameter(parameter));
|
|
2906
3511
|
/**
|
|
@@ -2929,6 +3534,37 @@ valueFlow = index.valueFlow) => {
|
|
|
2929
3534
|
return narrowed;
|
|
2930
3535
|
return withoutUndefinedMember(checker, narrowed);
|
|
2931
3536
|
};
|
|
3537
|
+
/**
|
|
3538
|
+
* A READ of a narrowed parameter keeps the absence the checker's own flow
|
|
3539
|
+
* analysis already removed there. `responseType ? new responseType(b) : u`
|
|
3540
|
+
* reads the cell inside a truthiness guard: the checker types that read
|
|
3541
|
+
* without `undefined`, and handing it the whole `typeof Reply | undefined`
|
|
3542
|
+
* binding instead made the construction's callee an `optional` with no
|
|
3543
|
+
* construct path. Only the absence members are taken from the checker --
|
|
3544
|
+
* everything else the read holds is still the census's answer.
|
|
3545
|
+
*/
|
|
3546
|
+
const withReadAbsenceOf = (read, bound) => {
|
|
3547
|
+
if (!bound.isUnion())
|
|
3548
|
+
return bound;
|
|
3549
|
+
const checked = checker.getTypeAtLocation(read);
|
|
3550
|
+
if ((checked.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0)
|
|
3551
|
+
return bound;
|
|
3552
|
+
const present = (checked.isUnion() ? checked.types : [checked]).reduce((flags, part) => flags | part.flags, 0);
|
|
3553
|
+
const dropped = (ts.TypeFlags.Undefined | ts.TypeFlags.Null) & ~present;
|
|
3554
|
+
// A narrowed `BufferSource` read under `ArrayBuffer.isView(data)` is an
|
|
3555
|
+
// `ArrayBufferView` to the checker: the arms its flow ruled out are the
|
|
3556
|
+
// callers' arms not assignable to what it reads there.
|
|
3557
|
+
const viewRead = (checked.isUnion() ? checked.types : [checked]).some(isLibArrayBufferViewType);
|
|
3558
|
+
if (dropped === 0 && !viewRead)
|
|
3559
|
+
return bound;
|
|
3560
|
+
const kept = bound.types.filter((part) => (part.flags & dropped) === 0 && (!viewRead || (part.flags & ts.TypeFlags.Object) === 0 || checker.isTypeAssignableTo(part, checked)));
|
|
3561
|
+
if (kept.length === bound.types.length || kept.length === 0)
|
|
3562
|
+
return bound;
|
|
3563
|
+
if (kept.length === 1 && kept[0] !== undefined)
|
|
3564
|
+
return kept[0];
|
|
3565
|
+
const constructing = checker;
|
|
3566
|
+
return typeof constructing.getUnionType === 'function' ? constructing.getUnionType(kept) : bound;
|
|
3567
|
+
};
|
|
2932
3568
|
// Publication reads a settled binding set, so its memo is built once, after
|
|
2933
3569
|
// the fixpoint stops -- unlike the propagating one, which is thrown away
|
|
2934
3570
|
// each round because the answers it caches are answers to a smaller view.
|
|
@@ -2985,11 +3621,58 @@ valueFlow = index.valueFlow) => {
|
|
|
2985
3621
|
if (!ts.isParameter(declaration))
|
|
2986
3622
|
continue;
|
|
2987
3623
|
const narrowed = statedBindings.get(declaration);
|
|
2988
|
-
if (narrowed)
|
|
2989
|
-
|
|
3624
|
+
if (!narrowed)
|
|
3625
|
+
continue;
|
|
3626
|
+
if (guardNarrowsDynamicBinding(node, narrowed))
|
|
3627
|
+
return null;
|
|
3628
|
+
return withReadAbsenceOf(node, bodyBindingOf(declaration, narrowed));
|
|
2990
3629
|
}
|
|
2991
3630
|
return null;
|
|
2992
3631
|
};
|
|
3632
|
+
/**
|
|
3633
|
+
* A read inside a guard over a cell whose callers all handed it a dynamic
|
|
3634
|
+
* value: `function touch(value: unknown)` called with `held[0]` binds
|
|
3635
|
+
* `unknown`, and `if (value instanceof Date) value.setUTCFullYear(...)` reads
|
|
3636
|
+
* the cell where the checker has proved it holds a Date. The binding states
|
|
3637
|
+
* nothing about that read -- `unknown` is the cell's storage, not a claim
|
|
3638
|
+
* about what a guard found in it -- so answering the binding there kept the
|
|
3639
|
+
* branch on the box and turned every member access into a dynamic `[[Get]]`
|
|
3640
|
+
* on it. The checker's narrowing is the read's type, exactly as for a
|
|
3641
|
+
* parameter DECLARED `any`, which this census never binds; the narrowed
|
|
3642
|
+
* read then converts out of the dynamic cell once, at the read. A dead
|
|
3643
|
+
* branch (`never`) and an unnarrowed read keep the binding.
|
|
3644
|
+
*/
|
|
3645
|
+
const guardNarrowsDynamicBinding = (read, bound) => {
|
|
3646
|
+
if ((bound.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) === 0)
|
|
3647
|
+
return false;
|
|
3648
|
+
const flow = checker.getTypeAtLocation(read);
|
|
3649
|
+
return (flow.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never)) === 0;
|
|
3650
|
+
};
|
|
3651
|
+
/** The copy-bound parameter a node is, or reads -- memoized, since every node of every copy asks. */
|
|
3652
|
+
const copyParameters = new Map();
|
|
3653
|
+
const copyParameterOf = (node) => {
|
|
3654
|
+
if (ts.isParameter(node))
|
|
3655
|
+
return copyBindings.has(node) ? node : null;
|
|
3656
|
+
if (!ts.isIdentifier(node))
|
|
3657
|
+
return null;
|
|
3658
|
+
const remembered = copyParameters.get(node);
|
|
3659
|
+
if (remembered !== undefined)
|
|
3660
|
+
return remembered;
|
|
3661
|
+
const parameter = checker.getSymbolAtLocation(node)?.declarations?.find(ts.isParameter) ?? null;
|
|
3662
|
+
const answer = parameter && copyBindings.has(parameter) ? parameter : null;
|
|
3663
|
+
copyParameters.set(node, answer);
|
|
3664
|
+
return answer;
|
|
3665
|
+
};
|
|
3666
|
+
const copyTypeAt = (node, ordinalOf) => {
|
|
3667
|
+
const parameter = copyParameterOf(node);
|
|
3668
|
+
if (!parameter)
|
|
3669
|
+
return null;
|
|
3670
|
+
const ordinal = ordinalOf(parameter.parent);
|
|
3671
|
+
const narrowed = ordinal === null ? undefined : copyBindings.get(parameter)?.get(ordinal);
|
|
3672
|
+
if (!narrowed)
|
|
3673
|
+
return null;
|
|
3674
|
+
return node === parameter || !ts.isIdentifier(node) ? narrowed : withReadAbsenceOf(node, bodyBindingOf(parameter, narrowed));
|
|
3675
|
+
};
|
|
2993
3676
|
// Implicit slots have an owning signature but no parameter declaration.
|
|
2994
3677
|
// Reuse the settled call attribution and resolver; never start a second
|
|
2995
3678
|
// call-site inventory or infer from only the successfully typed callers.
|
|
@@ -3260,6 +3943,7 @@ valueFlow = index.valueFlow) => {
|
|
|
3260
3943
|
publishing.resolve(element);
|
|
3261
3944
|
return patternReadTypes.get(element) ?? null;
|
|
3262
3945
|
},
|
|
3946
|
+
...(copyBindings.size === 0 ? {} : { copyTypeAt }),
|
|
3263
3947
|
statedTypeAt: (node) => {
|
|
3264
3948
|
// Memoized, and safe to memoize only HERE: this is the published view,
|
|
3265
3949
|
// returned after the fixpoint has stopped, so `statedBindings` and
|
|
@@ -3286,7 +3970,7 @@ valueFlow = index.valueFlow) => {
|
|
|
3286
3970
|
const declaration = ts.isParameter(node)
|
|
3287
3971
|
? node
|
|
3288
3972
|
: ts.isIdentifier(node)
|
|
3289
|
-
? checker
|
|
3973
|
+
? valueSymbolAt(checker, node, hostProvided)?.declarations?.find(ts.isParameter)
|
|
3290
3974
|
: undefined;
|
|
3291
3975
|
if (declaration) {
|
|
3292
3976
|
const arms = flowCarrierArms.get(declaration);
|
|
@@ -3304,12 +3988,22 @@ valueFlow = index.valueFlow) => {
|
|
|
3304
3988
|
const present = checker.getNonNullableType(read);
|
|
3305
3989
|
if (checker.isTypeAssignableTo(present, upper) && checker.isTypeAssignableTo(upper, present))
|
|
3306
3990
|
return arms;
|
|
3307
|
-
return null;
|
|
3991
|
+
return ts.isIdentifier(node) ? flowCarrierArmsOf(node, declaration) : null;
|
|
3308
3992
|
}
|
|
3309
3993
|
}
|
|
3994
|
+
const recordArms = declaration ? recordHomeArms.get(declaration) : undefined;
|
|
3995
|
+
if (recordArms)
|
|
3996
|
+
return ts.isParameter(node) ? recordArms : recordHomeArmsAtRead(checker, recordArms, checker.getTypeAtLocation(node));
|
|
3997
|
+
// A stated-union read the checker's flow narrowed to one arm is typed
|
|
3998
|
+
// as that arm (`flowArmOf`), not as the cell's whole union: a one-arm
|
|
3999
|
+
// list, which `structural.ts`'s `parameter-union-arms` rule publishes
|
|
4000
|
+
// as the arm itself.
|
|
4001
|
+
const flowArm = declaration && ts.isIdentifier(node) ? flowArmOf(node, declaration) : null;
|
|
4002
|
+
if (flowArm !== null)
|
|
4003
|
+
return [flowArm];
|
|
3310
4004
|
return synthesizedUnionArmsAt(checker, node, unionArms);
|
|
3311
4005
|
},
|
|
3312
|
-
boundCount: bindings.size + unionArms.size + flowCarrierArms.size + implicitTuples.size,
|
|
4006
|
+
boundCount: bindings.size + unionArms.size + flowCarrierArms.size + recordHomeArms.size + implicitTuples.size,
|
|
3313
4007
|
refusals,
|
|
3314
4008
|
refusalOf: (parameter) => lastRefusal.get(parameter) ?? null,
|
|
3315
4009
|
debugReport: () => {
|
|
@@ -3337,3 +4031,29 @@ valueFlow = index.valueFlow) => {
|
|
|
3337
4031
|
}
|
|
3338
4032
|
};
|
|
3339
4033
|
};
|
|
4034
|
+
/**
|
|
4035
|
+
* The census as ONE COPY of a generic body sees it: `typeAt` and
|
|
4036
|
+
* `statedTypeAt` answer a copy-bound parameter (`copyTypeAt`) with what that
|
|
4037
|
+
* copy's own callers pass, and everything else exactly as the program-wide
|
|
4038
|
+
* census does. `path` is the copy chain the asking view is inside, innermost
|
|
4039
|
+
* last; the root scope, and a census that bound no copy, get the census back
|
|
4040
|
+
* unchanged.
|
|
4041
|
+
*/
|
|
4042
|
+
export const parameterCensusForCopy = (census, path) => {
|
|
4043
|
+
const copyTypeAt = census.copyTypeAt;
|
|
4044
|
+
if (!copyTypeAt || path.length === 0)
|
|
4045
|
+
return census;
|
|
4046
|
+
const ordinalOf = (owner) => {
|
|
4047
|
+
for (let index = path.length - 1; index >= 0; index -= 1) {
|
|
4048
|
+
const step = path[index];
|
|
4049
|
+
if (step && step.owner === owner)
|
|
4050
|
+
return step.ordinal;
|
|
4051
|
+
}
|
|
4052
|
+
return null;
|
|
4053
|
+
};
|
|
4054
|
+
return {
|
|
4055
|
+
...census,
|
|
4056
|
+
typeAt: (node) => (ts.isParameter(node) ? copyTypeAt(node, ordinalOf) : null) ?? census.typeAt(node),
|
|
4057
|
+
statedTypeAt: (node) => copyTypeAt(node, ordinalOf) ?? census.statedTypeAt(node)
|
|
4058
|
+
};
|
|
4059
|
+
};
|