@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Representation } from '../representation/model.js';
|
|
2
2
|
import type { ConversionNode, ConversionNodeId } from './algebra.js';
|
|
3
3
|
import type { CoercionOperation, ConversionRuntimeRegistry } from './registry.js';
|
|
4
|
+
import type { FamilyMemberKeys } from './record-view.js';
|
|
4
5
|
/**
|
|
5
6
|
* The conversion census: ONE node per (source, target) pair, minted on
|
|
6
7
|
* demand and remembered.
|
|
@@ -62,6 +63,72 @@ export interface ConversionCensus {
|
|
|
62
63
|
* arm's parameters un-promoted.
|
|
63
64
|
*/
|
|
64
65
|
readonly exactArmFor: (source: Representation, target: Representation) => ConversionNode | null;
|
|
66
|
+
/**
|
|
67
|
+
* An instance of a class extending a native collection, read AS that
|
|
68
|
+
* collection for one of the collection's own members
|
|
69
|
+
* (`SemanticOperand.nativeBaseView`): `super.get(k)`, or `lower.size` where
|
|
70
|
+
* no class in the family redeclares `size`. The same upcast the ordinary
|
|
71
|
+
* store renders, minted even for a family that redeclares OTHER members,
|
|
72
|
+
* which is exactly the case `nodeFor` must refuse. `null` for any other pair.
|
|
73
|
+
*/
|
|
74
|
+
readonly nativeBaseViewFor: (source: Representation, target: Representation) => ConversionNode | null;
|
|
75
|
+
/**
|
|
76
|
+
* A census-built sum read as the one native collection the program asserts
|
|
77
|
+
* it is (`lower-operands.ts`'s `assertedCensusUnionReceiver`): every arm is
|
|
78
|
+
* that collection, a box, or an open Document that may view one, and EACH
|
|
79
|
+
* is converted -- the collection as it is, the box through its checked
|
|
80
|
+
* unbox, the Document through the object it views. `nodeFor`'s answer for
|
|
81
|
+
* the same pair selects the collection's arm by its tag, which misreads a
|
|
82
|
+
* boxed or viewed Map. `null` for any other pair.
|
|
83
|
+
*/
|
|
84
|
+
readonly armViewFor: (source: Representation, target: Representation) => ConversionNode | null;
|
|
85
|
+
/**
|
|
86
|
+
* A tagged union the program's own `as T` asserts to ONE carrier that some
|
|
87
|
+
* arm cannot convert into. The assertion proves nothing about which arm is
|
|
88
|
+
* live (a flow narrowing would), so `nodeFor`'s selection -- an unchecked
|
|
89
|
+
* `get<k>()` of the arm that converts -- is wrong for the other arms: it
|
|
90
|
+
* aborted on a live `unknown[]` arm of `(cond ? items[0] : items) as S[]`.
|
|
91
|
+
* This node dispatches on the live arm instead: an arm that converts does,
|
|
92
|
+
* an `Array<any>` arm is rebuilt element-wise with each element checked, and
|
|
93
|
+
* an arm that cannot be the target is a `TypeError`. `null` for a source that
|
|
94
|
+
* is not a union or a target that is a union, a box or an optional (those
|
|
95
|
+
* have their own whole-union recipes).
|
|
96
|
+
*/
|
|
97
|
+
readonly assertedUnionFor: (source: Representation, target: Representation, copyAllowed: boolean) => ConversionNode | null;
|
|
98
|
+
/**
|
|
99
|
+
* A record entering a slot whose record arm is an interface FAMILY's
|
|
100
|
+
* layout, viewed knowing which members of the family the site named
|
|
101
|
+
* (`record-view.ts`'s `FamilyMemberKeys`). `nodeFor`'s answer for the same
|
|
102
|
+
* pair is keyed by carriers alone and cannot tell a site that named a
|
|
103
|
+
* member lacking a layout field from one whose member declares it, so it
|
|
104
|
+
* must refuse a source that cannot fill that field; this node is asked
|
|
105
|
+
* only after it did, by a site that published the member it names. `null`
|
|
106
|
+
* where even the member's own keys leave no view.
|
|
107
|
+
*/
|
|
108
|
+
readonly familyMemberViewFor: (source: Representation, target: Representation, members: FamilyMemberKeys) => ConversionNode | null;
|
|
109
|
+
/**
|
|
110
|
+
* A CAUGHT value -- a `catch (error)` binding typed `any` -- handed to a
|
|
111
|
+
* class-typed slot: the checked read of the class instance, which, when the
|
|
112
|
+
* thrown value is not one, rethrows that value rather than aborting.
|
|
113
|
+
* mongodb's `executeOperation` does `catch (error) { return
|
|
114
|
+
* operation.handleError(error) }` with `handleError(error: MongoError)`,
|
|
115
|
+
* whose every implementation rethrows what it does not recognize; in JS a
|
|
116
|
+
* non-MongoError reaches it and propagates as the operation's rejection.
|
|
117
|
+
* The slot cannot hold that value, so the handoff itself propagates it.
|
|
118
|
+
* `null` for any other pair.
|
|
119
|
+
*/
|
|
120
|
+
readonly caughtHandoffFor: (source: Representation, target: Representation) => ConversionNode | null;
|
|
121
|
+
/**
|
|
122
|
+
* An `any` argument entering an OPTIONAL parameter (`x?: T`, no default)
|
|
123
|
+
* whose payload has no `null` state: a `null` the value holds reads as the
|
|
124
|
+
* parameter's absence. mongodb's `executeCommands` keeps `let thrownError =
|
|
125
|
+
* null` (typed `any`) and, on success, passes it to `mergeBatchResults(...,
|
|
126
|
+
* err?: AnyError, ...)`. The callee was checked against `T | undefined`, so
|
|
127
|
+
* the only null it can see is one an `any` smuggled past that check; it has
|
|
128
|
+
* no default initializer that could tell the two apart. `null` for any
|
|
129
|
+
* other pair.
|
|
130
|
+
*/
|
|
131
|
+
readonly nullishOptionalFor: (source: Representation, target: Representation) => ConversionNode | null;
|
|
65
132
|
/** The node a `convert` instruction names, from whichever table minted it; `null` for an id no census minted. */
|
|
66
133
|
readonly nodeById: (id: ConversionNodeId) => ConversionNode | null;
|
|
67
134
|
/** Every node minted through `nodeFor` that the eager graph did not already hold. */
|
|
@@ -75,6 +142,32 @@ export declare const conversionNodeIdOf: (source: Representation, target: Repres
|
|
|
75
142
|
/** The carrier each abstract operation lands on. */
|
|
76
143
|
export declare const coercionTargetOf: (operation: CoercionOperation) => Representation;
|
|
77
144
|
export declare const createConversionNodes: (input: ConversionCensusInput) => ConversionCensus;
|
|
145
|
+
/** The materializer id every family-member view node carries; the printer dispatches its recipe on it. */
|
|
146
|
+
export declare const FAMILY_MEMBER_VIEW_MATERIALIZER = "view:family-member-record";
|
|
147
|
+
/** The materializer id every nullish-optional node carries; the printer dispatches its recipe on it. */
|
|
148
|
+
export declare const NULLISH_OPTIONAL_MATERIALIZER = "view:nullish-optional";
|
|
149
|
+
/** The materializer id every caught-handoff node carries; the printer dispatches its recipe on it. */
|
|
150
|
+
export declare const CAUGHT_HANDOFF_MATERIALIZER = "view:caught-handoff";
|
|
151
|
+
/** The materializer id every native-base view node carries; the printer dispatches its recipe on it. */
|
|
152
|
+
export declare const NATIVE_BASE_VIEW_MATERIALIZER = "gea::host::nativeBaseView";
|
|
153
|
+
/**
|
|
154
|
+
* Whether `target` is exactly the native collection `source`'s class extends
|
|
155
|
+
* (`class-ref.nativeBase`), by carrier key: the pair every native collection
|
|
156
|
+
* upcast -- a store or a view -- spans.
|
|
157
|
+
*/
|
|
158
|
+
export declare const isNativeCollectionUpcast: (source: Representation, target: Representation) => boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Whether `target` is exactly the intrinsic promise `source`'s class extends
|
|
161
|
+
* (`class-ref.nativeBase`): `timeout.then(...)` on `class Timeout extends
|
|
162
|
+
* Promise<never>` reads `then` off that promise, sharing its state.
|
|
163
|
+
*/
|
|
164
|
+
export declare const isNativePromiseUpcast: (source: Representation, target: Representation) => boolean;
|
|
165
|
+
/** The materializer id every arm-view node carries; the printer dispatches its recipe on it. */
|
|
166
|
+
export declare const ARM_VIEW_MATERIALIZER = "gea::host::armView";
|
|
167
|
+
/** The materializer id every asserted-union node carries; the printer dispatches its recipe on it. */
|
|
168
|
+
export declare const ASSERTED_UNION_MATERIALIZER = "gea::host::assertedUnion";
|
|
169
|
+
/** The asserted-union node that may rebuild an `Array<any>` arm as a copy. */
|
|
170
|
+
export declare const ASSERTED_UNION_COPY_MATERIALIZER = "gea::host::assertedUnionCopy";
|
|
78
171
|
/** The materializer id every exact-arm node carries; the printer dispatches its recipe on it. */
|
|
79
172
|
export declare const EXACT_ARM_MATERIALIZER = "gea::host::exactArm";
|
|
80
173
|
/**
|
package/dist/conversion/nodes.js
CHANGED
|
@@ -1,7 +1,46 @@
|
|
|
1
|
-
import { representationKey } from '../representation/model.js';
|
|
1
|
+
import { isOpenDocument, representationKey, standInRefuses } from '../representation/model.js';
|
|
2
2
|
import { validateCapability } from './algebra.js';
|
|
3
3
|
import { createConversionDerivationContext, deriveConversionCapability } from './derive.js';
|
|
4
4
|
import { narrowingCapabilityFor } from './build.js';
|
|
5
|
+
/**
|
|
6
|
+
* Why a callable whose convention takes a receiver of class `X` cannot become
|
|
7
|
+
* one taking a receiver of class `Y` that does not extend `X`, or `null` for
|
|
8
|
+
* any other pair.
|
|
9
|
+
*
|
|
10
|
+
* `X.prototype.m.call(y, ...)` is the program shape: `mongodb-connection-
|
|
11
|
+
* string-url` borrows `CaseInsensitiveMap.prototype._normalizeKey` onto its
|
|
12
|
+
* `URLSearchParams` subclass. The body was compiled against `X`'s layout and
|
|
13
|
+
* dispatch -- its `this.keys()` is `Map`'s -- and no conversion of the function
|
|
14
|
+
* VALUE can retarget that; running it on a `Y` needs the body compiled again
|
|
15
|
+
* for `Y`, which this compiler does not do. The pair was already refused; this
|
|
16
|
+
* says why, rather than naming only the two carriers.
|
|
17
|
+
*/
|
|
18
|
+
const foreignReceiverOf = (source, target) => {
|
|
19
|
+
// The receiver itself, handed to a method of the unrelated class: the
|
|
20
|
+
// lowered form of the same borrow when the callee is resolved directly.
|
|
21
|
+
if (source.kind === 'class-ref' && target.kind === 'class-ref') {
|
|
22
|
+
if (source.declaration === target.declaration || source.ancestors.includes(target.declaration))
|
|
23
|
+
return null;
|
|
24
|
+
if (target.ancestors.includes(source.declaration))
|
|
25
|
+
return null;
|
|
26
|
+
return (`an instance of class ${source.declaration} is used where class ${target.declaration} is declared, and neither extends the ` +
|
|
27
|
+
`other: a compiled instance has its own class's layout, so no conversion makes it one of the other (a borrowed method, ` +
|
|
28
|
+
`\`${target.declaration}.prototype.m.call(instance)\`, would need the body compiled again for the instance's class)`);
|
|
29
|
+
}
|
|
30
|
+
if (!('abi' in source) || !('abi' in target))
|
|
31
|
+
return null;
|
|
32
|
+
const from = source.abi.receiver;
|
|
33
|
+
const into = target.abi.receiver;
|
|
34
|
+
if (from?.kind !== 'class-ref' || into?.kind !== 'class-ref')
|
|
35
|
+
return null;
|
|
36
|
+
if (into.declaration === from.declaration || into.ancestors.includes(from.declaration))
|
|
37
|
+
return null;
|
|
38
|
+
if (from.ancestors.includes(into.declaration))
|
|
39
|
+
return null;
|
|
40
|
+
return (`a method compiled for receivers of class ${from.declaration} is called with a receiver of class ${into.declaration}, ` +
|
|
41
|
+
`which does not extend it (\`${from.declaration}.prototype.m.call(receiver)\`): the body is compiled against its own ` +
|
|
42
|
+
"class's layout and dispatch, and running it on another class would need a copy of the body compiled for that class");
|
|
43
|
+
};
|
|
5
44
|
export const conversionNodeIdOf = (source, target) => `${representationKey(source)}->${representationKey(target)}`;
|
|
6
45
|
/** The carrier each abstract operation lands on. */
|
|
7
46
|
export const coercionTargetOf = (operation) => operation === 'ToNumber' ? { kind: 'scalar', domain: 'number' } : { kind: 'string' };
|
|
@@ -17,6 +56,8 @@ export const createConversionNodes = (input) => {
|
|
|
17
56
|
}
|
|
18
57
|
if (source.kind === 'void')
|
|
19
58
|
return { kind: 'never', reason: `a void source has no value to convert into ${targetKey}` };
|
|
59
|
+
if (standInRefuses(source, target))
|
|
60
|
+
return { kind: 'never', reason: `${targetKey} is a stand-in record only its own shape moves into` };
|
|
20
61
|
if (containsUnresolved(source) || containsUnresolved(target)) {
|
|
21
62
|
return { kind: 'never', reason: `an unresolved carrier in ${sourceKey} -> ${targetKey} names no conversion` };
|
|
22
63
|
}
|
|
@@ -45,7 +86,9 @@ export const createConversionNodes = (input) => {
|
|
|
45
86
|
const recipe = input.registry.staticRecipe(source, target);
|
|
46
87
|
if (recipe)
|
|
47
88
|
return { kind: 'static', materializer: recipe };
|
|
48
|
-
|
|
89
|
+
const foreign = foreignReceiverOf(source, target);
|
|
90
|
+
const missing = `no runtime conversion is installed from ${sourceKey} to ${targetKey}`;
|
|
91
|
+
return { kind: 'never', reason: foreign === null ? missing : `${missing}: ${foreign}` };
|
|
49
92
|
};
|
|
50
93
|
const nodeFor = (source, target) => {
|
|
51
94
|
const sourceKey = representationKey(source);
|
|
@@ -58,7 +101,10 @@ export const createConversionNodes = (input) => {
|
|
|
58
101
|
if (remembered !== undefined)
|
|
59
102
|
return remembered;
|
|
60
103
|
const capability = capabilityOf(source, target, sourceKey, targetKey);
|
|
61
|
-
|
|
104
|
+
// A membership view, not a Set copied from both tables: the copy was made
|
|
105
|
+
// once per minted pair, quadratic in the census, and was the mongodb
|
|
106
|
+
// driver's single largest lowering cost (20 of 35 seconds).
|
|
107
|
+
validateCapability(capability, { has: (known) => known === id || input.nodes.has(known) || minted.has(known) });
|
|
62
108
|
const node = { id, source, target, capability };
|
|
63
109
|
minted.set(id, node);
|
|
64
110
|
return node;
|
|
@@ -115,9 +161,216 @@ export const createConversionNodes = (input) => {
|
|
|
115
161
|
exactArms.set(id, node);
|
|
116
162
|
return node;
|
|
117
163
|
};
|
|
118
|
-
const
|
|
119
|
-
|
|
164
|
+
const nativeBaseViews = new Map();
|
|
165
|
+
const nativeBaseViewFor = (source, target) => {
|
|
166
|
+
if (!isNativeCollectionUpcast(source, target) && !isNativePromiseUpcast(source, target))
|
|
167
|
+
return null;
|
|
168
|
+
const id = `${representationKey(source)}->${representationKey(target)}#native-base-view`;
|
|
169
|
+
const remembered = nativeBaseViews.get(id);
|
|
170
|
+
if (remembered !== undefined)
|
|
171
|
+
return remembered;
|
|
172
|
+
const node = {
|
|
173
|
+
id,
|
|
174
|
+
source,
|
|
175
|
+
target,
|
|
176
|
+
capability: {
|
|
177
|
+
kind: 'static',
|
|
178
|
+
materializer: {
|
|
179
|
+
id: NATIVE_BASE_VIEW_MATERIALIZER,
|
|
180
|
+
domain: 'static:native-base-view',
|
|
181
|
+
allocates: false,
|
|
182
|
+
nativeFieldProtocol: 'unused',
|
|
183
|
+
nativePayloadTransport: 'preserved',
|
|
184
|
+
nativeClassReferenceIdentity: 'preserved',
|
|
185
|
+
callableIdentityTransport: 'preserved'
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
nativeBaseViews.set(id, node);
|
|
190
|
+
return node;
|
|
191
|
+
};
|
|
192
|
+
const armViews = new Map();
|
|
193
|
+
const armViewFor = (source, target) => {
|
|
194
|
+
if (!isArmViewPair(source, target))
|
|
195
|
+
return null;
|
|
196
|
+
const id = `${representationKey(source)}->${representationKey(target)}#arm-view`;
|
|
197
|
+
const remembered = armViews.get(id);
|
|
198
|
+
if (remembered !== undefined)
|
|
199
|
+
return remembered;
|
|
200
|
+
const node = {
|
|
201
|
+
id,
|
|
202
|
+
source,
|
|
203
|
+
target,
|
|
204
|
+
capability: { kind: 'static', materializer: { id: ARM_VIEW_MATERIALIZER, domain: 'static:arm-view', allocates: true } }
|
|
205
|
+
};
|
|
206
|
+
armViews.set(id, node);
|
|
207
|
+
return node;
|
|
208
|
+
};
|
|
209
|
+
const assertedUnions = new Map();
|
|
210
|
+
const assertedUnionFor = (source, target, copyAllowed) => {
|
|
211
|
+
if (source.kind !== 'tagged-union')
|
|
212
|
+
return null;
|
|
213
|
+
if (target.kind === 'tagged-union' || target.kind === 'dynamic' || target.kind === 'optional')
|
|
214
|
+
return null;
|
|
215
|
+
const id = `${representationKey(source)}->${representationKey(target)}#asserted-union${copyAllowed ? ':copy' : ''}`;
|
|
216
|
+
const remembered = assertedUnions.get(id);
|
|
217
|
+
if (remembered !== undefined)
|
|
218
|
+
return remembered;
|
|
219
|
+
const node = {
|
|
220
|
+
id,
|
|
221
|
+
source,
|
|
222
|
+
target,
|
|
223
|
+
capability: {
|
|
224
|
+
kind: 'static',
|
|
225
|
+
materializer: {
|
|
226
|
+
id: copyAllowed ? ASSERTED_UNION_COPY_MATERIALIZER : ASSERTED_UNION_MATERIALIZER,
|
|
227
|
+
domain: copyAllowed ? 'static:asserted-union-copy' : 'static:asserted-union',
|
|
228
|
+
allocates: copyAllowed
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
assertedUnions.set(id, node);
|
|
233
|
+
return node;
|
|
234
|
+
};
|
|
235
|
+
const familyMemberViews = new Map();
|
|
236
|
+
const familyMemberViewFor = (source, target, members) => {
|
|
237
|
+
const named = [...members.entries()]
|
|
238
|
+
.sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
|
|
239
|
+
.map(([shape, keys]) => `${shape}:${[...keys].sort().join(',')}`)
|
|
240
|
+
.join(';');
|
|
241
|
+
const id = `${representationKey(source)}->${representationKey(target)}#family-members(${named})`;
|
|
242
|
+
const remembered = familyMemberViews.get(id);
|
|
243
|
+
if (remembered !== undefined)
|
|
244
|
+
return remembered;
|
|
245
|
+
const materializer = input.registry.familyMemberView?.(source, target, members) ?? null;
|
|
246
|
+
if (materializer === null)
|
|
247
|
+
return null;
|
|
248
|
+
const node = { id, source, target, capability: { kind: 'static', materializer }, familyMembers: members };
|
|
249
|
+
familyMemberViews.set(id, node);
|
|
250
|
+
return node;
|
|
251
|
+
};
|
|
252
|
+
const caughtHandoffs = new Map();
|
|
253
|
+
const caughtHandoffFor = (source, target) => {
|
|
254
|
+
if (source.kind !== 'dynamic' || target.kind !== 'class-ref')
|
|
255
|
+
return null;
|
|
256
|
+
const id = `${representationKey(source)}->${representationKey(target)}#caught-handoff`;
|
|
257
|
+
const remembered = caughtHandoffs.get(id);
|
|
258
|
+
if (remembered !== undefined)
|
|
259
|
+
return remembered;
|
|
260
|
+
const node = {
|
|
261
|
+
id,
|
|
262
|
+
source,
|
|
263
|
+
target,
|
|
264
|
+
capability: { kind: 'static', materializer: { id: CAUGHT_HANDOFF_MATERIALIZER, domain: 'static:caught-handoff', allocates: false } }
|
|
265
|
+
};
|
|
266
|
+
caughtHandoffs.set(id, node);
|
|
267
|
+
return node;
|
|
268
|
+
};
|
|
269
|
+
const nullishOptionals = new Map();
|
|
270
|
+
const nullishOptionalFor = (source, target) => {
|
|
271
|
+
if (source.kind !== 'dynamic' || target.kind !== 'optional' || target.absence !== 'undefined')
|
|
272
|
+
return null;
|
|
273
|
+
const id = `${representationKey(source)}->${representationKey(target)}#nullish-optional`;
|
|
274
|
+
const remembered = nullishOptionals.get(id);
|
|
275
|
+
if (remembered !== undefined)
|
|
276
|
+
return remembered;
|
|
277
|
+
const node = {
|
|
278
|
+
id,
|
|
279
|
+
source,
|
|
280
|
+
target,
|
|
281
|
+
capability: {
|
|
282
|
+
kind: 'static',
|
|
283
|
+
materializer: { id: NULLISH_OPTIONAL_MATERIALIZER, domain: 'static:nullish-optional', allocates: false }
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
nullishOptionals.set(id, node);
|
|
287
|
+
return node;
|
|
288
|
+
};
|
|
289
|
+
const nodeById = (id) => input.nodes.get(id) ??
|
|
290
|
+
minted.get(id) ??
|
|
291
|
+
coercions.get(id) ??
|
|
292
|
+
exactArms.get(id) ??
|
|
293
|
+
nativeBaseViews.get(id) ??
|
|
294
|
+
armViews.get(id) ??
|
|
295
|
+
assertedUnions.get(id) ??
|
|
296
|
+
familyMemberViews.get(id) ??
|
|
297
|
+
caughtHandoffs.get(id) ??
|
|
298
|
+
nullishOptionals.get(id) ??
|
|
299
|
+
null;
|
|
300
|
+
return {
|
|
301
|
+
nodeFor,
|
|
302
|
+
coercionFor,
|
|
303
|
+
exactArmFor,
|
|
304
|
+
nativeBaseViewFor,
|
|
305
|
+
armViewFor,
|
|
306
|
+
assertedUnionFor,
|
|
307
|
+
familyMemberViewFor,
|
|
308
|
+
caughtHandoffFor,
|
|
309
|
+
nullishOptionalFor,
|
|
310
|
+
nodeById,
|
|
311
|
+
minted
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
/** The materializer id every family-member view node carries; the printer dispatches its recipe on it. */
|
|
315
|
+
export const FAMILY_MEMBER_VIEW_MATERIALIZER = 'view:family-member-record';
|
|
316
|
+
/** The materializer id every nullish-optional node carries; the printer dispatches its recipe on it. */
|
|
317
|
+
export const NULLISH_OPTIONAL_MATERIALIZER = 'view:nullish-optional';
|
|
318
|
+
/** The materializer id every caught-handoff node carries; the printer dispatches its recipe on it. */
|
|
319
|
+
export const CAUGHT_HANDOFF_MATERIALIZER = 'view:caught-handoff';
|
|
320
|
+
/** The materializer id every native-base view node carries; the printer dispatches its recipe on it. */
|
|
321
|
+
export const NATIVE_BASE_VIEW_MATERIALIZER = 'gea::host::nativeBaseView';
|
|
322
|
+
/**
|
|
323
|
+
* Whether `target` is exactly the native collection `source`'s class extends
|
|
324
|
+
* (`class-ref.nativeBase`), by carrier key: the pair every native collection
|
|
325
|
+
* upcast -- a store or a view -- spans.
|
|
326
|
+
*/
|
|
327
|
+
export const isNativeCollectionUpcast = (source, target) => source.kind === 'class-ref' &&
|
|
328
|
+
source.nativeBase !== undefined &&
|
|
329
|
+
target.kind === 'keyed-collection' &&
|
|
330
|
+
representationKey(source.nativeBase) === representationKey(target);
|
|
331
|
+
/**
|
|
332
|
+
* Whether `target` is exactly the intrinsic promise `source`'s class extends
|
|
333
|
+
* (`class-ref.nativeBase`): `timeout.then(...)` on `class Timeout extends
|
|
334
|
+
* Promise<never>` reads `then` off that promise, sharing its state.
|
|
335
|
+
*/
|
|
336
|
+
export const isNativePromiseUpcast = (source, target) => source.kind === 'class-ref' &&
|
|
337
|
+
source.nativeBase?.kind === 'promise' &&
|
|
338
|
+
target.kind === 'promise' &&
|
|
339
|
+
representationKey(source.nativeBase) === representationKey(target);
|
|
340
|
+
/** The materializer id every arm-view node carries; the printer dispatches its recipe on it. */
|
|
341
|
+
export const ARM_VIEW_MATERIALIZER = 'gea::host::armView';
|
|
342
|
+
/**
|
|
343
|
+
* Whether `armViewFor` answers the pair: a sum some arm of which is a box or
|
|
344
|
+
* an open Document, every other arm the target itself (or a Map the target's
|
|
345
|
+
* all-dynamic view reads), read as a Map or an Array -- the collections a
|
|
346
|
+
* Document can view (`gea::dictionary::aliasOf`). `emit-narrowing.ts`'s
|
|
347
|
+
* `armViewText` renders exactly these arms.
|
|
348
|
+
*/
|
|
349
|
+
const isArmViewPair = (source, target) => {
|
|
350
|
+
if (source.kind !== 'tagged-union')
|
|
351
|
+
return false;
|
|
352
|
+
const viewable = (target.kind === 'keyed-collection' && target.family === 'map') || target.kind === 'array-object';
|
|
353
|
+
if (!viewable || target.ownership !== 'shared-refcount')
|
|
354
|
+
return false;
|
|
355
|
+
const key = representationKey(target);
|
|
356
|
+
const indirect = (arm) => arm.value.kind === 'dynamic' || isOpenDocument(arm.value);
|
|
357
|
+
// Another Map carrier is the same object read through the all-dynamic Map
|
|
358
|
+
// view (`gea::detail::unboxDynamicMap`), when that is the target.
|
|
359
|
+
const mapView = (arm) => target.kind === 'keyed-collection' &&
|
|
360
|
+
target.key.kind === 'dynamic' &&
|
|
361
|
+
target.value?.kind === 'dynamic' &&
|
|
362
|
+
target.recursive === undefined &&
|
|
363
|
+
target.readOnlyView !== true &&
|
|
364
|
+
arm.value.kind === 'keyed-collection' &&
|
|
365
|
+
arm.value.family === 'map' &&
|
|
366
|
+
arm.value.recursive === undefined &&
|
|
367
|
+
arm.value.ownership === 'shared-refcount';
|
|
368
|
+
return source.arms.some(indirect) && source.arms.every((arm) => indirect(arm) || representationKey(arm.value) === key || mapView(arm));
|
|
120
369
|
};
|
|
370
|
+
/** The materializer id every asserted-union node carries; the printer dispatches its recipe on it. */
|
|
371
|
+
export const ASSERTED_UNION_MATERIALIZER = 'gea::host::assertedUnion';
|
|
372
|
+
/** The asserted-union node that may rebuild an `Array<any>` arm as a copy. */
|
|
373
|
+
export const ASSERTED_UNION_COPY_MATERIALIZER = 'gea::host::assertedUnionCopy';
|
|
121
374
|
/** The materializer id every exact-arm node carries; the printer dispatches its recipe on it. */
|
|
122
375
|
export const EXACT_ARM_MATERIALIZER = 'gea::host::exactArm';
|
|
123
376
|
/**
|
|
@@ -127,6 +380,10 @@ export const EXACT_ARM_MATERIALIZER = 'gea::host::exactArm';
|
|
|
127
380
|
* exactly-one test still guards the answer rather than trusting that.
|
|
128
381
|
*/
|
|
129
382
|
export const exactArmIndexOf = (source, target) => {
|
|
383
|
+
// A possibly-absent union projects the same way; absence fails the check
|
|
384
|
+
// like any other arm (`gea::host::exactArm`'s `Optional` overload).
|
|
385
|
+
if (source.kind === 'optional' && source.payload.kind === 'tagged-union')
|
|
386
|
+
return exactArmIndexOf(source.payload, target);
|
|
130
387
|
if (source.kind !== 'tagged-union')
|
|
131
388
|
return null;
|
|
132
389
|
const targetKey = representationKey(target);
|
|
@@ -11,10 +11,51 @@ import { narrowingReachesTarget } from './build.js';
|
|
|
11
11
|
* emits the same pair as an IR conversion.
|
|
12
12
|
*/
|
|
13
13
|
export const narrowedOperandView = (source, operand, deriver) => {
|
|
14
|
+
// A box asserted to a type (`(value as string[]).join(',')` over an `any`)
|
|
15
|
+
// is read as that type: the checked unbox, then the native member. Read off
|
|
16
|
+
// the box, the member was looked up as a detached function value and
|
|
17
|
+
// called with no receiver.
|
|
18
|
+
if (source.kind === 'dynamic' && operand.asserted === true) {
|
|
19
|
+
const asserted = deriver.derive(operand.type);
|
|
20
|
+
return asserted.kind === 'unresolved' ? source : asserted;
|
|
21
|
+
}
|
|
14
22
|
if (source.kind !== 'optional' && source.kind !== 'tagged-union')
|
|
15
23
|
return source;
|
|
16
24
|
const target = deriver.derive(operand.type);
|
|
17
25
|
if (representationKey(source) === representationKey(target))
|
|
18
26
|
return source;
|
|
27
|
+
if (source.kind === 'tagged-union' && source.arms.some(isProxyArm))
|
|
28
|
+
return narrowedKeepingProxies(source, target);
|
|
29
|
+
// The same sum behind an absence -- a module `let` with no initializer, read
|
|
30
|
+
// where it may still be unwritten (`representation/unassigned-binding-cells.ts`):
|
|
31
|
+
// mongodb's `'kModuleError' in zstd` over the proxy-carrying `ZStandard`. A
|
|
32
|
+
// use that states the arm ran on a present value (`in` throws on
|
|
33
|
+
// `undefined`, and so does a member read), so the view is the payload's own
|
|
34
|
+
// proxy-keeping selection -- the payload itself when the checker's arm is
|
|
35
|
+
// every ordinary arm it holds -- reached by the checked presence load.
|
|
36
|
+
if (source.kind === 'optional' && source.payload.kind === 'tagged-union' && source.payload.arms.some(isProxyArm)) {
|
|
37
|
+
const payload = source.payload;
|
|
38
|
+
const wanted = (target.kind === 'tagged-union' ? target.arms.map((arm) => arm.value) : [target]).map(representationKey);
|
|
39
|
+
const ordinary = new Set(payload.arms.filter((arm) => !isProxyArm(arm)).map((arm) => representationKey(arm.value)));
|
|
40
|
+
if (wanted.length > 0 && wanted.every((key) => ordinary.has(key)))
|
|
41
|
+
return narrowedKeepingProxies(payload, target);
|
|
42
|
+
}
|
|
19
43
|
return narrowingReachesTarget(source, target) ? target : source;
|
|
20
44
|
};
|
|
45
|
+
const isProxyArm = (arm) => arm.value.kind === 'proxy-object';
|
|
46
|
+
/**
|
|
47
|
+
* A proxy answers `in`, `typeof`-free structural checks and every other
|
|
48
|
+
* narrowing test through its own traps, so no narrowing the checker performed
|
|
49
|
+
* can rule it out: a narrowed view of a sum holding a proxy arm keeps that arm
|
|
50
|
+
* (under its own tag) beside the ordinary arms the narrowing selected. Loading
|
|
51
|
+
* the narrowed arm unchecked would read the wrong payload while the proxy is
|
|
52
|
+
* the one held.
|
|
53
|
+
*/
|
|
54
|
+
const narrowedKeepingProxies = (source, target) => {
|
|
55
|
+
const ordinary = source.arms.filter((arm) => !isProxyArm(arm));
|
|
56
|
+
const wanted = new Set((target.kind === 'tagged-union' ? target.arms.map((arm) => arm.value) : [target]).map((value) => representationKey(value)));
|
|
57
|
+
const kept = ordinary.filter((arm) => wanted.has(representationKey(arm.value)));
|
|
58
|
+
if (kept.length === 0 || kept.length !== wanted.size || kept.length === ordinary.length)
|
|
59
|
+
return source;
|
|
60
|
+
return { kind: 'tagged-union', arms: [...kept, ...source.arms.filter(isProxyArm)] };
|
|
61
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { CallableAbi, RecordField, Representation } from '../representation/model.js';
|
|
2
|
+
import type { RecordLayoutPolicy } from '../representation/policies.js';
|
|
3
|
+
import { type PairConvertible } from './record-view.js';
|
|
4
|
+
/**
|
|
5
|
+
* A program object that implements the iterator protocol by hand, read as the
|
|
6
|
+
* cursor carrier (`iterator`) its declared type names.
|
|
7
|
+
*
|
|
8
|
+
* mongodb's `onData` builds `{ next() {...}, return() {...}, throw(err)
|
|
9
|
+
* {...}, [Symbol.asyncIterator]() { return this } }` typed `AsyncGenerator<
|
|
10
|
+
* Buffer> & AsyncDisposable`: the intersection derives to a record, while
|
|
11
|
+
* `AsyncGenerator<Buffer>` alone -- `[Symbol.asyncIterator]`'s own result, and
|
|
12
|
+
* the field `Connection.dataEvents` it is stored into -- derives to the
|
|
13
|
+
* `async-generator` carrier. The two are one object, so the conversion is a
|
|
14
|
+
* VIEW: the carrier's steps call the same object's own members
|
|
15
|
+
* (`gea_runtime.h`'s `AsyncGenerator::ProtocolSteps`, or
|
|
16
|
+
* `Iterator::ProtocolSteps` for a synchronous iterator object), never a copy of
|
|
17
|
+
* what it held when converted.
|
|
18
|
+
*
|
|
19
|
+
* Only a shared-refcount object qualifies, because only a reference preserves
|
|
20
|
+
* that identity; a by-value record would be a snapshot. Each member the
|
|
21
|
+
* protocol calls must be a callable field whose parameters the call can omit,
|
|
22
|
+
* answering an `IteratorResult`. An async generator's step hands the member's
|
|
23
|
+
* promise straight back, mapped onto its step; a synchronous cursor's step
|
|
24
|
+
* cannot wait for one -- a blocking read inside a callback is the nested pump
|
|
25
|
+
* the runtime refuses -- so a synchronous target admits no promise-answering
|
|
26
|
+
* member. `next` must
|
|
27
|
+
* always be there; `return`/`throw` may be optional members, as
|
|
28
|
+
* `IterableIterator<T>` declares them.
|
|
29
|
+
*/
|
|
30
|
+
export interface ProtocolIteratorMember {
|
|
31
|
+
readonly key: 'next' | 'return' | 'throw';
|
|
32
|
+
/**
|
|
33
|
+
* How the object says the member is there: always (`required`), or only
|
|
34
|
+
* when its presence bit is set (`flag`, an optional field) and, for an
|
|
35
|
+
* `optional(...)` value, when that holds a payload too. An optional member
|
|
36
|
+
* is asked at every step, never once at conversion: `IterableIterator<T>`'s
|
|
37
|
+
* `return?`/`throw?` may be installed after the cursor is made, and one that
|
|
38
|
+
* is absent when the step runs behaves exactly as a missing member.
|
|
39
|
+
*/
|
|
40
|
+
readonly presence: {
|
|
41
|
+
readonly flag: boolean;
|
|
42
|
+
readonly payload: boolean;
|
|
43
|
+
};
|
|
44
|
+
readonly abi: CallableAbi;
|
|
45
|
+
/** The `IteratorResult` the member answers, after awaiting a promise result. */
|
|
46
|
+
readonly result: Representation;
|
|
47
|
+
readonly awaited: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface ProtocolIteratorPlan {
|
|
50
|
+
readonly source: Extract<Representation, {
|
|
51
|
+
kind: 'record' | 'native-record-ref';
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* The cursor the object is read as: the synchronous `iterator` (a
|
|
55
|
+
* `Generator`/`IterableIterator`-typed object), or an `async-generator`
|
|
56
|
+
* (mongodb's `onData`, typed `AsyncGenerator<Buffer>`), whose steps hand the
|
|
57
|
+
* member's promise back instead of reading it -- `gea::AsyncGenerator`'s
|
|
58
|
+
* `ProtocolSteps`.
|
|
59
|
+
*/
|
|
60
|
+
readonly target: Extract<Representation, {
|
|
61
|
+
kind: 'iterator' | 'async-generator';
|
|
62
|
+
}>;
|
|
63
|
+
readonly next: ProtocolIteratorMember;
|
|
64
|
+
readonly finish: ProtocolIteratorMember | null;
|
|
65
|
+
readonly raise: ProtocolIteratorMember | null;
|
|
66
|
+
}
|
|
67
|
+
export interface IteratorResultRecord {
|
|
68
|
+
readonly record: Representation;
|
|
69
|
+
readonly value: RecordField;
|
|
70
|
+
readonly done: RecordField;
|
|
71
|
+
/** Whether a step can find this arm not done (a yielded value) and done (a completion). */
|
|
72
|
+
readonly yields: boolean;
|
|
73
|
+
readonly returns: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The `{ value, done }` records an `IteratorResult` can be: every arm of a
|
|
77
|
+
* union, or the one record. The library's union is told apart the way
|
|
78
|
+
* `record-view.ts`'s `iteratorResultHomes` tells it apart: the return arm
|
|
79
|
+
* REQUIRES `done` (`done: true`), the yield arm leaves it optional (`done?:
|
|
80
|
+
* false`), since boolean literals do not survive structural normalization. A
|
|
81
|
+
* shape with no such split can be either.
|
|
82
|
+
*/
|
|
83
|
+
export declare const iteratorResultRecordsOf: (layouts: RecordLayoutPolicy, result: Representation) => readonly IteratorResultRecord[] | null;
|
|
84
|
+
export declare const protocolIteratorPlan: (layouts: RecordLayoutPolicy, source: Representation, target: Representation, convertible: PairConvertible) => ProtocolIteratorPlan | null;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { thrownValueCarrier } from '../representation/model.js';
|
|
2
|
+
import { holdsAbsence } from './record-view.js';
|
|
3
|
+
/**
|
|
4
|
+
* The `{ value, done }` records an `IteratorResult` can be: every arm of a
|
|
5
|
+
* union, or the one record. The library's union is told apart the way
|
|
6
|
+
* `record-view.ts`'s `iteratorResultHomes` tells it apart: the return arm
|
|
7
|
+
* REQUIRES `done` (`done: true`), the yield arm leaves it optional (`done?:
|
|
8
|
+
* false`), since boolean literals do not survive structural normalization. A
|
|
9
|
+
* shape with no such split can be either.
|
|
10
|
+
*/
|
|
11
|
+
export const iteratorResultRecordsOf = (layouts, result) => {
|
|
12
|
+
const arms = result.kind === 'tagged-union' ? result.arms.map((arm) => arm.value) : [result];
|
|
13
|
+
const found = [];
|
|
14
|
+
for (const arm of arms) {
|
|
15
|
+
const fields = arm.kind === 'record' ? arm.fields : arm.kind === 'native-record-ref' ? layouts.forShape(arm.shapeId) : null;
|
|
16
|
+
if (fields === null)
|
|
17
|
+
return null;
|
|
18
|
+
const value = fields.find((field) => field.key === 'value');
|
|
19
|
+
const done = fields.find((field) => field.key === 'done');
|
|
20
|
+
if (value === undefined || done === undefined)
|
|
21
|
+
return null;
|
|
22
|
+
found.push({ record: arm, value, done });
|
|
23
|
+
}
|
|
24
|
+
const split = found.some((arm) => arm.done.required) && found.some((arm) => !arm.done.required);
|
|
25
|
+
return found.map((arm) => ({ ...arm, yields: !split || !arm.done.required, returns: !split || arm.done.required }));
|
|
26
|
+
};
|
|
27
|
+
const omittable = (abi, from) => abi.parameters.every((parameter, position) => position < from ||
|
|
28
|
+
(abi.restFrom !== null && position >= abi.restFrom ? parameter.value.kind === 'array-object' : holdsAbsence(parameter.value)));
|
|
29
|
+
const memberOf = (layouts, fields, source, key, convertible) => {
|
|
30
|
+
const field = fields.find((candidate) => candidate.key === key);
|
|
31
|
+
if (field === undefined)
|
|
32
|
+
return 'absent';
|
|
33
|
+
const payload = field.value.kind === 'optional';
|
|
34
|
+
const value = field.value.kind === 'optional' ? field.value.payload : field.value;
|
|
35
|
+
// `next` is what makes the object an iterator at all.
|
|
36
|
+
if (key === 'next' && (payload || !field.required))
|
|
37
|
+
return null;
|
|
38
|
+
if (value.kind !== 'function-value-dispatch')
|
|
39
|
+
return null;
|
|
40
|
+
const abi = value.abi;
|
|
41
|
+
if (abi.receiver !== null && !convertible(source, abi.receiver))
|
|
42
|
+
return null;
|
|
43
|
+
// `throw(e)` hands the thrown value on as its first argument.
|
|
44
|
+
if (key === 'throw') {
|
|
45
|
+
const first = abi.parameters[0];
|
|
46
|
+
if (first === undefined || (abi.restFrom !== null && abi.restFrom === 0) || !convertible(thrownValueCarrier, first.value))
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (!omittable(abi, key === 'throw' ? 1 : 0))
|
|
50
|
+
return null;
|
|
51
|
+
const awaited = abi.result.kind === 'promise';
|
|
52
|
+
const result = abi.result.kind === 'promise' ? abi.result.value : abi.result;
|
|
53
|
+
if (iteratorResultRecordsOf(layouts, result) === null)
|
|
54
|
+
return null;
|
|
55
|
+
return { key, presence: { flag: !field.required, payload }, abi, result, awaited };
|
|
56
|
+
};
|
|
57
|
+
export const protocolIteratorPlan = (layouts, source, target, convertible) => {
|
|
58
|
+
if (target.kind !== 'iterator' && target.kind !== 'async-generator')
|
|
59
|
+
return null;
|
|
60
|
+
if ((source.kind !== 'record' && source.kind !== 'native-record-ref') || source.ownership !== 'shared-refcount')
|
|
61
|
+
return null;
|
|
62
|
+
const fields = source.kind === 'record' ? source.fields : layouts.forShape(source.shapeId);
|
|
63
|
+
if (fields === null)
|
|
64
|
+
return null;
|
|
65
|
+
const next = memberOf(layouts, fields, source, 'next', convertible);
|
|
66
|
+
if (next === null || next === 'absent')
|
|
67
|
+
return null;
|
|
68
|
+
const finish = memberOf(layouts, fields, source, 'return', convertible);
|
|
69
|
+
const raise = memberOf(layouts, fields, source, 'throw', convertible);
|
|
70
|
+
if (finish === null || raise === null)
|
|
71
|
+
return null;
|
|
72
|
+
if (target.kind === 'iterator' && [next, finish, raise].some((member) => member !== 'absent' && member.awaited))
|
|
73
|
+
return null;
|
|
74
|
+
// Every value a step can hand the cursor must reach its carrier: a yielded
|
|
75
|
+
// `value` the element, a done `value` the completion.
|
|
76
|
+
const completionValueless = target.completion.kind === 'void' || target.completion.kind === 'undefined';
|
|
77
|
+
for (const member of [next, raise === 'absent' ? null : raise]) {
|
|
78
|
+
if (member === null)
|
|
79
|
+
continue;
|
|
80
|
+
for (const arm of iteratorResultRecordsOf(layouts, member.result) ?? []) {
|
|
81
|
+
if (arm.yields && !convertible(arm.value.value, target.element))
|
|
82
|
+
return null;
|
|
83
|
+
if (arm.returns && !completionValueless && !convertible(arm.value.value, target.completion))
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { source, target, next, finish: finish === 'absent' ? null : finish, raise: raise === 'absent' ? null : raise };
|
|
88
|
+
};
|