@geastack/compiler 1.0.19 → 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/prelude.js +5 -1
- 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 +594 -54
- 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 +48 -4
- 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 +18007 -4757
- package/src/targets/cpp/runtime/gea_runtime_builtins.cpp +7 -45
- package/src/targets/cpp/runtime/gea_runtime_rtc.h +247 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { dictionaryKeyDomainOf, representationKey } from '../../../representation/model.js';
|
|
2
2
|
import { hasReferenceIdentity } from '../../../representation/collections.js';
|
|
3
3
|
import { thrownValueCarrier } from '../../../ir/lower-exceptions.js';
|
|
4
|
-
import { alignedValueText, callableObjectAbi } from '../emit-narrowing.js';
|
|
4
|
+
import { alignedValueText, callableObjectAbi, readOnlyMapViewText } from '../emit-narrowing.js';
|
|
5
|
+
import { declaredFieldRepresentationOf } from '../../../projection/fields.js';
|
|
5
6
|
import { cppConstantLiteral, cppStringLiteral, cppTypeOf, cppUndefinedValue } from '../types.js';
|
|
6
7
|
import { createCppEmitBlockedError, operandText, prototypeMethodReceiverText } from '../emit-context.js';
|
|
7
8
|
import { arrayMethods } from './emit-prototype-array.js';
|
|
@@ -211,12 +212,38 @@ const fulfilledHandlerText = (ctx, receiverCarrier, abi, handlerText) => {
|
|
|
211
212
|
* than a deduction -- so the two share `promiseReactionText` below, which is
|
|
212
213
|
* where both the reason conversion and the result-carrier agreement live.
|
|
213
214
|
*/
|
|
215
|
+
/**
|
|
216
|
+
* Whether a reaction handler's parameters past the first can all be bound to
|
|
217
|
+
* `undefined`. A Node-style `Callback = (error?, result?) => void` handed to
|
|
218
|
+
* `.then(undefined, cb)` is the shape: the reaction supplies only the reason,
|
|
219
|
+
* and ECMA-262 binds every parameter it did not supply to `undefined`. A
|
|
220
|
+
* trailing parameter whose carrier has no rendering of `undefined` cannot be
|
|
221
|
+
* called this way at all, so it stays a refusal.
|
|
222
|
+
*/
|
|
223
|
+
const trailingParametersTakeUndefined = (abi) => abi.parameters
|
|
224
|
+
.slice(1)
|
|
225
|
+
.every((parameter) => parameter.value.kind === 'undefined' ||
|
|
226
|
+
(parameter.value.kind === 'optional' && parameter.value.absence === 'undefined') ||
|
|
227
|
+
parameter.value.kind === 'dynamic');
|
|
214
228
|
const promiseThenText = (ctx, receiverText, args, result, receiverCarrier) => {
|
|
215
229
|
const onFulfilled = args[0];
|
|
216
230
|
if (args.length > 2 || !onFulfilled) {
|
|
217
231
|
throw createCppEmitBlockedError('host-invocation:Promise.prototype.then', `"Promise.prototype.then" takes a fulfillment handler and an optional rejection handler (ECMA-262 27.2.5.4); this call passes ${args.length}`);
|
|
218
232
|
}
|
|
219
|
-
|
|
233
|
+
// 27.2.5.4 step 3-4 hand `PerformPromiseThen` whatever was passed, and
|
|
234
|
+
// 27.2.5.4.2 (`NewPromiseReactionJob`) treats a handler that is not callable
|
|
235
|
+
// as ABSENT: an `undefined` fulfillment handler passes the value through, an
|
|
236
|
+
// `undefined` rejection handler forwards the reason. So `p.then(undefined, g)`
|
|
237
|
+
// is `p.catch(g)` exactly -- the driver's `close().then(undefined, squash)` --
|
|
238
|
+
// and `p.then(f, undefined)` is `p.then(f)`. Only the statically-absent
|
|
239
|
+
// carriers qualify; a handler that MAY be absent is still a runtime test.
|
|
240
|
+
const statedAbsent = (operand) => operand !== undefined && (operand.representation.kind === 'undefined' || operand.representation.kind === 'null');
|
|
241
|
+
const onRejected = statedAbsent(args[1]) ? undefined : args[1];
|
|
242
|
+
if (statedAbsent(onFulfilled)) {
|
|
243
|
+
if (onRejected !== undefined)
|
|
244
|
+
return promiseReactionText(ctx, 'then', receiverText, undefined, onRejected, result, receiverCarrier);
|
|
245
|
+
throw createCppEmitBlockedError('host-invocation:Promise.prototype.then', '"Promise.prototype.then" with no callable handler at all is a pass-through this backend does not render (27.2.5.4)');
|
|
246
|
+
}
|
|
220
247
|
if (onRejected !== undefined) {
|
|
221
248
|
return promiseReactionText(ctx, 'then', receiverText, onFulfilled, onRejected, result, receiverCarrier);
|
|
222
249
|
}
|
|
@@ -308,7 +335,7 @@ const promiseReactionText = (ctx, family, receiverText, onFulfilled, onRejected,
|
|
|
308
335
|
const resultType = cppTypeOf(carrier);
|
|
309
336
|
const handlerAbi = (handler, role) => {
|
|
310
337
|
const abi = callableObjectAbi(handler.representation);
|
|
311
|
-
if (!abi || abi.receiver !== null || abi.restFrom !== null || abi
|
|
338
|
+
if (!abi || abi.receiver !== null || abi.restFrom !== null || !trailingParametersTakeUndefined(abi)) {
|
|
312
339
|
throw createCppEmitBlockedError(`host-invocation:${label}`, `a "${label}" handler carried as "${representationKey(handler.representation)}" is not a plain 0- or 1-parameter ` +
|
|
313
340
|
`callable; ${clause} calls it with the ${role === 'rejection' ? 'rejection reason' : 'fulfillment value'} and nothing else -- ` +
|
|
314
341
|
'no receiver, no rest pack');
|
|
@@ -330,7 +357,18 @@ const promiseReactionText = (ctx, family, receiverText, onFulfilled, onRejected,
|
|
|
330
357
|
throw createCppEmitBlockedError(`conversion:${representationKey(source)}->${representationKey(slot.value)}`, `a "${label}" handler declares its ${note} as "${representationKey(slot.value)}" and no conversion is installed from ` +
|
|
331
358
|
`"${representationKey(source)}"`);
|
|
332
359
|
}
|
|
333
|
-
|
|
360
|
+
// The reaction job passes exactly one argument; every parameter past it is
|
|
361
|
+
// bound to `undefined` (10.2.1.3 OrdinaryCallBindThis / FunctionDeclarationInstantiation
|
|
362
|
+
// step 25), which `trailingParametersTakeUndefined` already proved each one holds.
|
|
363
|
+
const rest = abi.parameters.slice(1).map((parameter) => {
|
|
364
|
+
const absent = alignedValueText(ctx, `${site}:absent`, { kind: 'undefined' }, parameter.value, cppUndefinedValue);
|
|
365
|
+
if (absent === null) {
|
|
366
|
+
throw createCppEmitBlockedError(`conversion:undefined->${representationKey(parameter.value)}`, `a "${label}" handler declares a parameter past the ${note} as "${representationKey(parameter.value)}", which has no rendering ` +
|
|
367
|
+
'of the `undefined` the reaction binds it to');
|
|
368
|
+
}
|
|
369
|
+
return absent;
|
|
370
|
+
});
|
|
371
|
+
return [converted, ...rest].join(', ');
|
|
334
372
|
};
|
|
335
373
|
/**
|
|
336
374
|
* Settle this call's result from one handler's own result.
|
|
@@ -601,20 +639,14 @@ export const promisePrototypeMethods = new Set(promiseMethods.keys());
|
|
|
601
639
|
* Deliberately absent from every family, each still refused BY NAME at its
|
|
602
640
|
* access (`keyedCollectionMemberText`):
|
|
603
641
|
*
|
|
604
|
-
* - `forEach` --
|
|
605
|
-
* callback whose `this`-arg and three-parameter frame this backend has no
|
|
606
|
-
* convention for; `Array.prototype.map` is the one callback-taking method it
|
|
607
|
-
* does render, and its own renderer below is what that took.
|
|
608
|
-
* - `keys` / `values` -- each returns an iterator whose element carrier is not
|
|
609
|
-
* currently projected here. Map `entries` is implemented below because its
|
|
610
|
-
* result already carries the concrete pair type needed by `gea::Iterator`.
|
|
642
|
+
* - `Map.forEach` -- Set.forEach uses the native callback frame below.
|
|
611
643
|
* - `getOrInsert` / `getOrInsertComputed` (ES2026), the ES2025
|
|
612
644
|
* `union`/`intersection`/`difference`/`isSubsetOf` family, and `Map.groupBy`
|
|
613
645
|
* / `Set.prototype.symmetricDifference` -- unbuilt, not refused on
|
|
614
646
|
* principle.
|
|
615
647
|
*/
|
|
616
648
|
const strongMapMethods = new Set(['get', 'set', 'has', 'delete', 'clear', 'entries', 'keys', 'values']);
|
|
617
|
-
const strongSetMethods = new Set(['add', 'has', 'delete', 'clear']);
|
|
649
|
+
const strongSetMethods = new Set(['add', 'has', 'delete', 'clear', 'forEach']);
|
|
618
650
|
const weakMapMethods = new Set(['get', 'set', 'has', 'delete']);
|
|
619
651
|
const weakSetMethods = new Set(['add', 'has', 'delete']);
|
|
620
652
|
export const keyedCollectionPrototypeMethods = (family) => family === 'map' ? strongMapMethods : family === 'set' ? strongSetMethods : family === 'weak-map' ? weakMapMethods : weakSetMethods;
|
|
@@ -636,8 +668,67 @@ export const keyedCollectionPrototypeMethods = (family) => family === 'map' ? st
|
|
|
636
668
|
* ownership at construction, so a collection reaching a call site is a
|
|
637
669
|
* `shared_ptr`.
|
|
638
670
|
*/
|
|
671
|
+
/**
|
|
672
|
+
* `set`/`add` return their receiver. Called on a subclass's native-base view
|
|
673
|
+
* (`super.set(k, v)` in `class C extends Map`), the checker types that result
|
|
674
|
+
* as the subclass -- `this` -- while the helper hands back the base view it was
|
|
675
|
+
* given. The view was taken from that very object, so the static downcast
|
|
676
|
+
* names exactly the receiver the language returns.
|
|
677
|
+
*/
|
|
678
|
+
const returnedReceiverText = (carrier, result, text) => {
|
|
679
|
+
const published = result?.representation;
|
|
680
|
+
// A class split at `any` types `this` as the union of its copies
|
|
681
|
+
// (mongodb's `CaseInsensitiveMap<Value = any>`): the receiver is the one
|
|
682
|
+
// copy whose native base IS this view's carrier, so the downcast re-enters
|
|
683
|
+
// the union at that arm. More than one such arm leaves the receiver's copy
|
|
684
|
+
// unnamed by the view, and the text stays as it was.
|
|
685
|
+
if (published?.kind === 'tagged-union') {
|
|
686
|
+
const homes = published.arms.flatMap((arm, index) => arm.value.kind === 'class-ref' &&
|
|
687
|
+
arm.value.nativeBase !== undefined &&
|
|
688
|
+
representationKey(arm.value.nativeBase) === representationKey(carrier)
|
|
689
|
+
? [{ index, arm: arm.value }]
|
|
690
|
+
: []);
|
|
691
|
+
const home = homes.length === 1 ? homes[0] : undefined;
|
|
692
|
+
if (home === undefined)
|
|
693
|
+
return text;
|
|
694
|
+
return `${cppTypeOf(published)}::ofArm<${home.index}>(gea::refStaticCast<${cppTypeOf(home.arm)}::element_type>(${text}))`;
|
|
695
|
+
}
|
|
696
|
+
if (published?.kind !== 'class-ref' || published.nativeBase === undefined)
|
|
697
|
+
return text;
|
|
698
|
+
if (representationKey(published.nativeBase) !== representationKey(carrier))
|
|
699
|
+
return text;
|
|
700
|
+
return `gea::refStaticCast<${cppTypeOf(published)}::element_type>(${text})`;
|
|
701
|
+
};
|
|
639
702
|
const keyedCollectionCallText = (ctx, carrier, member, receiverText, args, result) => {
|
|
640
703
|
const family = carrier.family;
|
|
704
|
+
if (family === 'set' && member === 'forEach') {
|
|
705
|
+
const callback = args[0];
|
|
706
|
+
const abi = callback && callableObjectAbi(callback.representation);
|
|
707
|
+
if (!callback || !abi || args.length > 2 || abi.restFrom !== null) {
|
|
708
|
+
throw createCppEmitBlockedError('host-invocation:set.prototype.forEach', 'Set.forEach requires a callback with a fixed native call frame');
|
|
709
|
+
}
|
|
710
|
+
const convert = (source, target, text) => {
|
|
711
|
+
const converted = alignedValueText(ctx, 'prototype/emit-prototype-invoke.ts:set-forEach', source, target, text);
|
|
712
|
+
if (converted === null) {
|
|
713
|
+
throw createCppEmitBlockedError('host-invocation:set.prototype.forEach', 'Set.forEach callback argument has no native conversion');
|
|
714
|
+
}
|
|
715
|
+
return converted;
|
|
716
|
+
};
|
|
717
|
+
const argumentsText = abi.parameters.map((parameter, index) => index < 2
|
|
718
|
+
? convert(carrier.key, parameter.value, 'gea_set_value')
|
|
719
|
+
: index === 2
|
|
720
|
+
? convert(carrier, parameter.value, 'gea_set_receiver')
|
|
721
|
+
: convert({ kind: 'undefined' }, parameter.value, 'gea::Undefined{}'));
|
|
722
|
+
if (abi.receiver !== null) {
|
|
723
|
+
const receiver = args[1];
|
|
724
|
+
argumentsText.unshift(convert(receiver?.representation ?? { kind: 'undefined' }, abi.receiver, receiver ? operandText(ctx, receiver) : 'gea::Undefined{}'));
|
|
725
|
+
}
|
|
726
|
+
// Insertion serials observe deletion, re-insertion and additions during a callback.
|
|
727
|
+
// Copy the current value before calling user code, which may invalidate Set storage.
|
|
728
|
+
return (`([&]() { auto gea_set_receiver = ${receiverText}; auto gea_set_callback = ${operandText(ctx, callback)}; ` +
|
|
729
|
+
`std::uint64_t gea_set_cursor = 0; while (const auto* gea_set_item = gea_set_receiver->itemAfter(gea_set_cursor)) { ` +
|
|
730
|
+
`auto gea_set_value = *gea_set_item; gea_set_callback.call(${argumentsText.join(', ')}); } }())`);
|
|
731
|
+
}
|
|
641
732
|
const expected = member === 'set' ? 2 : member === 'clear' || member === 'entries' || member === 'keys' || member === 'values' ? 0 : 1;
|
|
642
733
|
if (args.length !== expected) {
|
|
643
734
|
throw createCppEmitBlockedError(`host-invocation:${family}.prototype.${member}`, `"${family}.prototype.${member}" takes ${expected} argument(s); this call passes ${args.length}`);
|
|
@@ -656,6 +747,21 @@ const keyedCollectionCallText = (ctx, carrier, member, receiverText, args, resul
|
|
|
656
747
|
// of it. For a fully typed collection the source and target carriers are
|
|
657
748
|
// identical and it returns the text unchanged, so nothing native is
|
|
658
749
|
// disturbed.
|
|
750
|
+
// BSONPERF-identity-membership: `Set<Document>.has(value)` where the value is
|
|
751
|
+
// an object the program holds as a dynamic box (a native record, class
|
|
752
|
+
// instance, Array or Map -- bson's serializer `path.has(value)`) is an
|
|
753
|
+
// identity question. Converting the box into the Document the set stores
|
|
754
|
+
// would mint a view (a Dictionary, a shared alias and a registry entry) only
|
|
755
|
+
// to throw it away: a member's view is registered while the set holds it, so
|
|
756
|
+
// the registry answers membership without allocating anything.
|
|
757
|
+
if (family === 'set' &&
|
|
758
|
+
member === 'has' &&
|
|
759
|
+
!carrier.recursive &&
|
|
760
|
+
carrier.key.kind === 'dictionary' &&
|
|
761
|
+
carrier.key.key === 'string' &&
|
|
762
|
+
carrier.key.value.kind === 'dynamic' &&
|
|
763
|
+
args[0]?.representation.kind === 'dynamic')
|
|
764
|
+
return `gea::dictionary::setHasObject(${receiverText}, ${operandText(ctx, args[0])})`;
|
|
659
765
|
const slotOf = (index) => (index === 1 && carrier.value ? carrier.value : carrier.key);
|
|
660
766
|
const argumentTexts = args.map((argument, index) => {
|
|
661
767
|
const slot = slotOf(index);
|
|
@@ -681,23 +787,28 @@ const keyedCollectionCallText = (ctx, carrier, member, receiverText, args, resul
|
|
|
681
787
|
// JavaScript result is the original receiver, so mutate that one wrapper
|
|
682
788
|
// and return the same `Ref<wrapper>` directly.
|
|
683
789
|
if (carrier.recursive) {
|
|
684
|
-
|
|
790
|
+
// A statement call publishes no result: nothing reads the receiver back.
|
|
791
|
+
if (!result)
|
|
792
|
+
return `${receiverText}->set(${argumentTexts.join(', ')})`;
|
|
793
|
+
if (representationKey(result.representation) !== representationKey(carrier)) {
|
|
685
794
|
throw createCppEmitBlockedError(`host-invocation:${family}.prototype.set`, `recursive ${family}.prototype.set publishes "${result ? representationKey(result.representation) : 'nothing'}", not its receiver carrier`);
|
|
686
795
|
}
|
|
687
796
|
return `([&]() -> ${cppTypeOf(result.representation)} { ${receiverText}->set(${argumentTexts.join(', ')}); return ${receiverText}; }())`;
|
|
688
797
|
}
|
|
689
798
|
const helper = family === 'weak-map' ? 'gea::weakMapSet' : 'gea::mapSet';
|
|
690
|
-
return `${helper}(${receiverText}, ${argumentTexts.join(', ')})
|
|
799
|
+
return returnedReceiverText(carrier, result, `${helper}(${receiverText}, ${argumentTexts.join(', ')})`);
|
|
691
800
|
}
|
|
692
801
|
if (member === 'add') {
|
|
693
802
|
if (carrier.recursive) {
|
|
694
|
-
if (!result
|
|
803
|
+
if (!result)
|
|
804
|
+
return `${receiverText}->add(${argumentTexts[0]})`;
|
|
805
|
+
if (representationKey(result.representation) !== representationKey(carrier)) {
|
|
695
806
|
throw createCppEmitBlockedError(`host-invocation:${family}.prototype.add`, `recursive ${family}.prototype.add publishes "${result ? representationKey(result.representation) : 'nothing'}", not its receiver carrier`);
|
|
696
807
|
}
|
|
697
808
|
return `([&]() -> ${cppTypeOf(result.representation)} { ${receiverText}->add(${argumentTexts[0]}); return ${receiverText}; }())`;
|
|
698
809
|
}
|
|
699
810
|
const helper = family === 'weak-set' ? 'gea::weakSetAdd' : 'gea::setAdd';
|
|
700
|
-
return `${helper}(${receiverText}, ${argumentTexts[0]})
|
|
811
|
+
return returnedReceiverText(carrier, result, `${helper}(${receiverText}, ${argumentTexts[0]})`);
|
|
701
812
|
}
|
|
702
813
|
if (member === 'entries') {
|
|
703
814
|
if (family !== 'map' || result?.representation.kind !== 'iterator') {
|
|
@@ -723,11 +834,9 @@ const keyedCollectionCallText = (ctx, carrier, member, receiverText, args, resul
|
|
|
723
834
|
// is the collection's key either way.
|
|
724
835
|
if (family === 'set')
|
|
725
836
|
return `gea::Iterator<${element}>(${receiverText})`;
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
`if (gea_position >= gea_entries.size()) return false; ` +
|
|
730
|
-
`gea_out = gea_entries[gea_position].${half}; return true; })`);
|
|
837
|
+
// Walked by insertion serial, not position (`Map::entryAfter`): a
|
|
838
|
+
// position walk skipped the entry that slid into each deleted slot.
|
|
839
|
+
return `gea::mapHalfIterator<${element}, ${member === 'keys' ? 'true' : 'false'}>(${receiverText})`;
|
|
731
840
|
}
|
|
732
841
|
// `delete` is a C++ keyword; `remove` is the member the runtime spells for
|
|
733
842
|
// ECMA-262's `delete`, and this is the single place the rename happens.
|
|
@@ -745,6 +854,73 @@ const keyedCollectionCallText = (ctx, carrier, member, receiverText, args, resul
|
|
|
745
854
|
}
|
|
746
855
|
return invocation;
|
|
747
856
|
};
|
|
857
|
+
/**
|
|
858
|
+
* The half of a Map cursor's element at `index` (0 the key, 1 the value): a
|
|
859
|
+
* `[K, V]` tuple's own field, or the element of the Array a tuple whose two
|
|
860
|
+
* positions share one carrier derives as (`makeMapEntry`'s two shapes).
|
|
861
|
+
*/
|
|
862
|
+
const mapEntryHalfOf = (ctx, element, index) => element.kind === 'array-object' ? element.element : declaredFieldRepresentationOf(ctx.deriver, element, String(index), ctx.classes);
|
|
863
|
+
/**
|
|
864
|
+
* The collection a Map cursor member is actually walked through, where the
|
|
865
|
+
* call publishes a cursor whose element is not the one `carrier` steps.
|
|
866
|
+
*
|
|
867
|
+
* A class extending `Map<K, T>` split into layout copies holds its own `V`
|
|
868
|
+
* per copy, while the call publishes the cursor its declared type names: a
|
|
869
|
+
* union dispatch (`emit-callable.ts`'s `emitUnionMethodCall`) over the copies,
|
|
870
|
+
* or one copy read where the class is spelled at `any`. The
|
|
871
|
+
* answer is the SAME map read through `gea::mapReadOnlyView` -- the checked
|
|
872
|
+
* per-value widening `convertedValueText` renders for `V -> V'`, over the
|
|
873
|
+
* live storage, never a copy. `entries`, `keys` and `values` are reads, so the
|
|
874
|
+
* read-only view is all they need. A key that differs, or a value no widening
|
|
875
|
+
* reaches, refuses by name.
|
|
876
|
+
*/
|
|
877
|
+
const walkedMapCarrier = (ctx, carrier, member, receiverText, result) => {
|
|
878
|
+
const unchanged = { carrier, text: receiverText };
|
|
879
|
+
if (carrier.family !== 'map' || carrier.value === null)
|
|
880
|
+
return unchanged;
|
|
881
|
+
if (member !== 'entries' && member !== 'keys' && member !== 'values')
|
|
882
|
+
return unchanged;
|
|
883
|
+
if (result?.representation.kind !== 'iterator')
|
|
884
|
+
return unchanged;
|
|
885
|
+
const element = result.representation.element;
|
|
886
|
+
const key = member === 'values' ? carrier.key : member === 'keys' ? element : mapEntryHalfOf(ctx, element, 0);
|
|
887
|
+
const value = member === 'keys' ? carrier.value : member === 'values' ? element : mapEntryHalfOf(ctx, element, 1);
|
|
888
|
+
const refuse = (why) => {
|
|
889
|
+
throw createCppEmitBlockedError(`host-invocation:map.prototype.${member}`, `"map.prototype.${member}" walks a "${representationKey(carrier)}" into a cursor of "${representationKey(element)}": ${why}`);
|
|
890
|
+
};
|
|
891
|
+
if (key === null || value === null)
|
|
892
|
+
return refuse('the cursor element names no key/value halves');
|
|
893
|
+
// A `[unknown, unknown]` pair is the shared-carrier Array of `Value`s, and `makeMapEntry` boxes each half as it
|
|
894
|
+
// leaves the map (`DynamicCarrier<K>::out`), exactly as `DynamicMapSource` does: both the key and the value reach the
|
|
895
|
+
// cursor boxed over the live storage, so neither half needs a view here.
|
|
896
|
+
if (member === 'entries' && element.kind === 'array-object' && element.element.kind === 'dynamic')
|
|
897
|
+
return unchanged;
|
|
898
|
+
if (cppTypeOf(key) !== cppTypeOf(carrier.key))
|
|
899
|
+
return refuse('the key carriers differ, and a Map view widens values only');
|
|
900
|
+
if (cppTypeOf(value) === cppTypeOf(carrier.value))
|
|
901
|
+
return unchanged;
|
|
902
|
+
const viewed = { ...carrier, value, readOnlyView: true };
|
|
903
|
+
const text = readOnlyMapViewText(carrier, viewed, receiverText);
|
|
904
|
+
if (text === null)
|
|
905
|
+
return refuse(`no read-only widening of "${representationKey(carrier.value)}" into "${representationKey(value)}" is licensed`);
|
|
906
|
+
return { carrier: viewed, text };
|
|
907
|
+
};
|
|
908
|
+
/**
|
|
909
|
+
* One native base's own prototype member, called on a receiver already viewed
|
|
910
|
+
* as that base (`class-ref.nativeBase`): the keyed-collection and promise
|
|
911
|
+
* renderers above, reached from a union arm that has no class body of its own
|
|
912
|
+
* for the key. `null` where this file renders no such member.
|
|
913
|
+
*/
|
|
914
|
+
export const nativeBaseMethodCallText = (ctx, carrier, member, receiverText, args, result) => {
|
|
915
|
+
if (carrier.kind === 'promise') {
|
|
916
|
+
const render = promiseMethods.get(member);
|
|
917
|
+
return render ? render(ctx, receiverText, args, result, carrier) : null;
|
|
918
|
+
}
|
|
919
|
+
if (carrier.kind !== 'keyed-collection' || !keyedCollectionPrototypeMethods(carrier.family).has(member))
|
|
920
|
+
return null;
|
|
921
|
+
const walked = walkedMapCarrier(ctx, carrier, member, receiverText, result);
|
|
922
|
+
return keyedCollectionCallText(ctx, walked.carrier, member, walked.text, args, result);
|
|
923
|
+
};
|
|
748
924
|
/** The keys `scalarMemberText` may defer off a number receiver -- one authority for "is this method implemented", as above. */
|
|
749
925
|
export const numberPrototypeMethods = new Set(numberMethods.keys());
|
|
750
926
|
/**
|
|
@@ -783,7 +959,10 @@ const dictionaryCallText = (ctx, member, receiverText, table, args) => {
|
|
|
783
959
|
if (key === undefined) {
|
|
784
960
|
throw createCppEmitBlockedError('call-abi:hasOwnProperty', '"Object.prototype.hasOwnProperty" was called with no key');
|
|
785
961
|
}
|
|
786
|
-
|
|
962
|
+
// A string table may be a Document viewing an instance (`hasOwn` excludes
|
|
963
|
+
// the inherited getters `has` answers for the `in` operator).
|
|
964
|
+
const method = table.key === 'string' ? 'hasOwn' : 'has';
|
|
965
|
+
return `${receiverText}${table.accessor}${method}(${keyedTableKeyText(ctx, key, dictionaryKeyDomainOf(table.key, key.representation))})`;
|
|
787
966
|
};
|
|
788
967
|
/**
|
|
789
968
|
* The call text for a deferred String/Array prototype-method read, or `null`
|
|
@@ -906,7 +1085,7 @@ const renderPrototypeMethodCall = (ctx, read, receiverText, operation) => {
|
|
|
906
1085
|
const invocation = typedArrayCallText(ctx, read.member, receiver, typedArrayElementSpelling(arm.value), operation.arguments);
|
|
907
1086
|
if (operation.result === null || operation.result.representation.kind === 'void')
|
|
908
1087
|
return invocation;
|
|
909
|
-
const source = read.member === 'set' ? { kind: 'undefined' } : arm.value;
|
|
1088
|
+
const source = read.member === 'set' ? { kind: 'undefined' } : read.member === 'toBase64' ? { kind: 'string' } : arm.value;
|
|
910
1089
|
const converted = alignedValueText(ctx, 'prototype/emit-prototype-invoke.ts:682', source, operation.result.representation, invocation);
|
|
911
1090
|
if (converted === null) {
|
|
912
1091
|
throw createCppEmitBlockedError(`conversion:${representationKey(source)}->${representationKey(operation.result.representation)}`, `a typed-array union arm's "${read.member}" result carries "${representationKey(source)}" while the call publishes ` +
|
|
@@ -953,7 +1132,22 @@ const renderPrototypeMethodCall = (ctx, read, receiverText, operation) => {
|
|
|
953
1132
|
if (typeof text !== 'string') {
|
|
954
1133
|
throw createCppEmitBlockedError(`host-invocation:union.${read.member}`, `a mixed-union arm's "${read.member}" renders as a native scalar call, which has no per-arm spelling here`);
|
|
955
1134
|
}
|
|
956
|
-
|
|
1135
|
+
if (discardedWithAbsentArm)
|
|
1136
|
+
return `(void)(${text})`;
|
|
1137
|
+
// A primitive's `valueOf` answers the primitive itself, so each arm's
|
|
1138
|
+
// answer is that arm's own carrier and lands in its arm of the result --
|
|
1139
|
+
// the arms of `number | string` have no common C++ type to meet in.
|
|
1140
|
+
if (read.member === 'valueOf' &&
|
|
1141
|
+
armCarrier !== undefined &&
|
|
1142
|
+
operation.result !== null &&
|
|
1143
|
+
(armCarrier.kind === 'string' || armCarrier.kind === 'scalar')) {
|
|
1144
|
+
const aligned = alignedValueText(ctx, 'prototype/emit-prototype-invoke.ts:mixed-union-value-of', armCarrier, operation.result.representation, text);
|
|
1145
|
+
if (aligned === null) {
|
|
1146
|
+
throw createCppEmitBlockedError(`host-invocation:union.${read.member}`, `a "${representationKey(armCarrier)}" arm's valueOf cannot land in this call's "${representationKey(operation.result.representation)}" result`);
|
|
1147
|
+
}
|
|
1148
|
+
return aligned;
|
|
1149
|
+
}
|
|
1150
|
+
return text;
|
|
957
1151
|
});
|
|
958
1152
|
return branches.reduceRight((rest, branch, index) => (index === branches.length - 1 ? branch : `${receiverText}.is<${index}>() ? ${branch} : (${rest})`), '');
|
|
959
1153
|
}
|
|
@@ -970,7 +1164,18 @@ const renderPrototypeMethodCall = (ctx, read, receiverText, operation) => {
|
|
|
970
1164
|
const end = operation.arguments[1] === undefined
|
|
971
1165
|
? `static_cast<double>(${receiverText}->size())`
|
|
972
1166
|
: operandText(ctx, operation.arguments[1]);
|
|
973
|
-
|
|
1167
|
+
const sliced = `gea::detail::arrayBufferSlice(${receiverText}, ${start}, ${end})`;
|
|
1168
|
+
// `view.buffer.slice(...)` is declared on `ArrayBufferLike`, so the call's
|
|
1169
|
+
// result may be held as `ArrayBuffer | SharedArrayBuffer` while this
|
|
1170
|
+
// receiver is the ArrayBuffer arm: the fresh block lands in its own arm.
|
|
1171
|
+
const held = operation.result?.representation;
|
|
1172
|
+
if (held === undefined || held.kind === 'array-buffer')
|
|
1173
|
+
return sliced;
|
|
1174
|
+
const aligned = alignedValueText(ctx, 'prototype/emit-prototype-invoke.ts:array-buffer-slice', { kind: 'array-buffer', ownership: 'shared-refcount' }, held, sliced);
|
|
1175
|
+
if (aligned === null) {
|
|
1176
|
+
throw createCppEmitBlockedError('host-invocation:ArrayBuffer.prototype.slice', `ArrayBuffer.prototype.slice answers a fresh ArrayBuffer, which this call's result "${representationKey(held)}" cannot hold`);
|
|
1177
|
+
}
|
|
1178
|
+
return aligned;
|
|
974
1179
|
}
|
|
975
1180
|
if (read.receiverKind === 'keyed-collection') {
|
|
976
1181
|
if (!read.collectionFamily) {
|
|
@@ -982,7 +1187,8 @@ const renderPrototypeMethodCall = (ctx, read, receiverText, operation) => {
|
|
|
982
1187
|
if (!read.collectionCarrier) {
|
|
983
1188
|
throw createCppEmitBlockedError(`host-invocation:${read.collectionFamily}.prototype.${read.member}`, `"${read.member}" was recorded as a deferred keyed-collection read with no carrier, and its arguments cannot be converted into slots this call cannot see`);
|
|
984
1189
|
}
|
|
985
|
-
|
|
1190
|
+
const walked = walkedMapCarrier(ctx, read.collectionCarrier, read.member, receiverText, operation.result);
|
|
1191
|
+
return keyedCollectionCallText(ctx, walked.carrier, read.member, walked.text, operation.arguments, operation.result);
|
|
986
1192
|
}
|
|
987
1193
|
const render = arrayMethods.get(read.member);
|
|
988
1194
|
if (!render) {
|
|
@@ -43,5 +43,5 @@ import { type EmitContext } from '../emit-context.js';
|
|
|
43
43
|
*/
|
|
44
44
|
export declare const iteratorPrototypeMethods: ReadonlySet<string>;
|
|
45
45
|
export declare const iteratorCallText: (ctx: EmitContext, member: string, receiverText: string, carrier: Extract<Representation, {
|
|
46
|
-
kind: "iterator";
|
|
46
|
+
kind: "iterator" | "async-generator";
|
|
47
47
|
}> | undefined, operation: CallOperation) => string;
|
|
@@ -4,7 +4,7 @@ import { createCppEmitBlockedError, operandText } from '../emit-context.js';
|
|
|
4
4
|
import { alignedValueText } from '../emit-narrowing.js';
|
|
5
5
|
import { memberAccessOperator } from '../emit-carrier-members.js';
|
|
6
6
|
import { recordFieldsOfShape } from '../records.js';
|
|
7
|
-
import { cppRecordFieldName, cppRecordFieldPresenceName, cppRecordStructName, cppTypeOf } from '../types.js';
|
|
7
|
+
import { cppRecordFieldName, cppRecordFieldPresenceName, cppRecordStructName, cppTypeOf, cppUndefinedValue } from '../types.js';
|
|
8
8
|
/**
|
|
9
9
|
* `%GeneratorPrototype%.next`/`.return`/`.throw` (ECMA-262 27.5.1.2-27.5.1.4)
|
|
10
10
|
* off a generator value, which this backend carries as the cursor
|
|
@@ -84,11 +84,40 @@ const sendsNothing = (ctx, argument) => argument.representation.kind === 'undefi
|
|
|
84
84
|
* record that comes back is read off it.
|
|
85
85
|
*/
|
|
86
86
|
const iteratorResultText = (ctx, receiverText, carrier, result, stepText) => {
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
// An async generator's `next`/`return`/`throw` answers a PROMISE of the
|
|
88
|
+
// record (ECMA-262 27.6.1): the same record, settled, and a step that throws
|
|
89
|
+
// -- `throw(e)` the body does not catch, or a hand-written iterator's own
|
|
90
|
+
// rejected `next()` -- is that promise's rejection rather than a synchronous
|
|
91
|
+
// throw. `Connection.dataEvents?.throw(error).then(undefined, squashError)`.
|
|
92
|
+
if (result.representation.kind === 'promise' && result.representation.value.kind === 'tagged-union') {
|
|
93
|
+
const promiseType = cppTypeOf(result.representation);
|
|
94
|
+
const settled = iteratorResultText(ctx, receiverText, carrier, { ...result, representation: result.representation.value }, stepText);
|
|
95
|
+
return (`([&]() -> ${promiseType} { try { return ${promiseType}(${settled}); } ` +
|
|
96
|
+
`catch (...) { return ${promiseType}::rejected_with(std::current_exception()); } }())`);
|
|
97
|
+
}
|
|
98
|
+
const union = iteratorResultUnionOf(carrier, result.representation);
|
|
99
|
+
const arms = iteratorResultArmsText(ctx, carrier, union, {
|
|
100
|
+
done: `${receiverText}.done()`,
|
|
101
|
+
value: 'gea_next',
|
|
102
|
+
completion: `${receiverText}.takeCompletionValue()`
|
|
103
|
+
});
|
|
104
|
+
return `([&]() -> ${cppTypeOf(union)} { auto gea_next = ${stepText}; (void)gea_next; ${arms} })()`;
|
|
105
|
+
};
|
|
106
|
+
const iteratorResultUnionOf = (carrier, result) => {
|
|
107
|
+
if (result.kind !== 'tagged-union') {
|
|
108
|
+
throw createCppEmitBlockedError(`runtime-helper:protocol:result:${representationKey(carrier)}`, `publishes "${representationKey(result)}", but ` +
|
|
89
109
|
'IteratorResult<T, TReturn> is a union of two records and this file renders exactly that');
|
|
90
110
|
}
|
|
91
|
-
|
|
111
|
+
return result;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* The statements that build `IteratorYieldResult<T> | IteratorReturnResult<TReturn>`
|
|
115
|
+
* from one step's three reads and return it -- shared by the synchronous
|
|
116
|
+
* cursor, whose reads are `done()`/the stepped value/`takeCompletionValue()`,
|
|
117
|
+
* and an async generator, whose settled `AsyncIteratorResult` carries all
|
|
118
|
+
* three as fields.
|
|
119
|
+
*/
|
|
120
|
+
const iteratorResultArmsText = (ctx, carrier, union, reads) => {
|
|
92
121
|
const arms = union.arms.map((arm, index) => {
|
|
93
122
|
const value = arm.value;
|
|
94
123
|
if (!isRecordArm(value))
|
|
@@ -106,20 +135,28 @@ const iteratorResultText = (ctx, receiverText, carrier, result, stepText) => {
|
|
|
106
135
|
'(two records, told apart by a required `done: true` against an optional `done?: false`)');
|
|
107
136
|
}
|
|
108
137
|
// The return arm's `value` field is the generator's COMPLETION value,
|
|
109
|
-
// read off the cursor's own
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
138
|
+
// read off the cursor's own completion slot -- never off whatever was
|
|
139
|
+
// passed to `next`/`return`, because a `finally` block that runs during an
|
|
140
|
+
// abrupt completion can override it with its own `return` (ECMA-262
|
|
141
|
+
// 27.5.3.3's own note), and `promise_type::completion_value` is exactly the
|
|
142
|
+
// slot both roads write through (`gea_runtime.h`).
|
|
114
143
|
const completionText = returnArm.valueField === null || isValueless(returnArm.valueField.value)
|
|
115
144
|
? null
|
|
116
145
|
: (() => {
|
|
146
|
+
// A valueless completion channel completes with `undefined`, which
|
|
147
|
+
// a field that can hold it -- `IteratorResult<T, any>`'s `value:
|
|
148
|
+
// any` -- is written as. Only a field that cannot is a refusal.
|
|
149
|
+
const absent = isValueless(carrier.completion)
|
|
150
|
+
? alignedValueText(ctx, 'prototype/emit-prototype-iterator.ts:absent-completion', { kind: 'undefined' }, returnArm.valueField.value, cppUndefinedValue)
|
|
151
|
+
: null;
|
|
152
|
+
if (absent !== null)
|
|
153
|
+
return absent;
|
|
117
154
|
if (isValueless(carrier.completion)) {
|
|
118
155
|
throw createCppEmitBlockedError(`conversion:${representationKey(carrier.completion)}->${representationKey(returnArm.valueField.value)}`, `a generator's completion value is carried as "${representationKey(returnArm.valueField.value)}", and this generator's own ` +
|
|
119
156
|
'completion channel is "undefined" -- either TReturn never resolved to a native carrier, or this generator is not ' +
|
|
120
157
|
'annotated as one -- so the cursor has no storage to read one back from');
|
|
121
158
|
}
|
|
122
|
-
const text = alignedValueText(ctx, 'prototype/emit-prototype-iterator.ts:155', carrier.completion, returnArm.valueField.value,
|
|
159
|
+
const text = alignedValueText(ctx, 'prototype/emit-prototype-iterator.ts:155', carrier.completion, returnArm.valueField.value, reads.completion);
|
|
123
160
|
if (text === null) {
|
|
124
161
|
throw createCppEmitBlockedError(`conversion:${representationKey(carrier.completion)}->${representationKey(returnArm.valueField.value)}`, `the cursor completes with "${representationKey(carrier.completion)}" while the IteratorResult "value" field carries ` +
|
|
125
162
|
`"${representationKey(returnArm.valueField.value)}", and no installed conversion reconciles them`);
|
|
@@ -134,7 +171,7 @@ const iteratorResultText = (ctx, receiverText, carrier, result, stepText) => {
|
|
|
134
171
|
}
|
|
135
172
|
const yieldValueText = yieldArm.valueField === null || isValueless(yieldArm.valueField.value)
|
|
136
173
|
? null
|
|
137
|
-
: alignedValueText(ctx, 'prototype/emit-prototype-iterator.ts:177', carrier.element, yieldArm.valueField.value,
|
|
174
|
+
: alignedValueText(ctx, 'prototype/emit-prototype-iterator.ts:177', carrier.element, yieldArm.valueField.value, reads.value);
|
|
138
175
|
if (yieldArm.valueField !== null && !isValueless(yieldArm.valueField.value) && yieldValueText === null) {
|
|
139
176
|
throw createCppEmitBlockedError(`conversion:${representationKey(carrier.element)}->${representationKey(yieldArm.valueField.value)}`, `the cursor yields "${representationKey(carrier.element)}" while the IteratorResult "value" field carries ` +
|
|
140
177
|
`"${representationKey(yieldArm.valueField.value)}", and no installed conversion reconciles them`);
|
|
@@ -148,8 +185,7 @@ const iteratorResultText = (ctx, receiverText, carrier, result, stepText) => {
|
|
|
148
185
|
const yieldBranch = `auto gea_result = ${constructionText(yieldArm.value)}; ${fieldStoreText(yieldAccessor, yieldArm.done, falseText)}` +
|
|
149
186
|
(yieldValueText === null || yieldArm.valueField === null ? '' : fieldStoreText(yieldAccessor, yieldArm.valueField, yieldValueText)) +
|
|
150
187
|
`return ${unionType}::ofArm<${yieldArm.index}>(gea_result);`;
|
|
151
|
-
return
|
|
152
|
-
`if (${receiverText}.done()) { ${returnBranch} } ${yieldBranch} })()`);
|
|
188
|
+
return `if (${reads.done}) { ${returnBranch} } ${yieldBranch}`;
|
|
153
189
|
};
|
|
154
190
|
/**
|
|
155
191
|
* `iter.next(v)` (member already checked to be `"next"`). Builds the step
|
|
@@ -236,6 +272,66 @@ const abruptCallText = (ctx, member, receiverText, carrier, operation) => {
|
|
|
236
272
|
}
|
|
237
273
|
return `${receiverText}.resumeReturn(${text})`;
|
|
238
274
|
};
|
|
275
|
+
/**
|
|
276
|
+
* `%AsyncGeneratorPrototype%.next`/`.return`/`.throw` (ECMA-262 27.6.1.2-4)
|
|
277
|
+
* off an `async function*`'s own `gea::AsyncGenerator`: each call enqueues a
|
|
278
|
+
* request and answers the promise of its step, which is mapped onto the
|
|
279
|
+
* `IteratorResult` union the checker typed the call's payload with -- the
|
|
280
|
+
* same two records `iteratorResultArmsText` builds for the synchronous
|
|
281
|
+
* cursor, read off the settled `AsyncIteratorResult`'s fields. A rejected
|
|
282
|
+
* step stays a rejection: `then` forwards it untouched, so
|
|
283
|
+
* `Connection.dataEvents?.throw(error).then(undefined, squashError)` sees it.
|
|
284
|
+
*/
|
|
285
|
+
const asyncGeneratorCallText = (ctx, member, receiverText, carrier, operation) => {
|
|
286
|
+
const argument = operation.arguments[0];
|
|
287
|
+
const sent = argument !== undefined && !sendsNothing(ctx, argument) ? argument : null;
|
|
288
|
+
const channelText = (channel, what) => {
|
|
289
|
+
if (sent === null)
|
|
290
|
+
return '';
|
|
291
|
+
if (isValueless(channel)) {
|
|
292
|
+
throw createCppEmitBlockedError(`runtime-helper:protocol:${member}:${representationKey(carrier)}`, `${what} sends a value into an async generator whose channel for it is "undefined" -- the type argument never resolved ` +
|
|
293
|
+
'to a native carrier -- so there is no storage to send it through');
|
|
294
|
+
}
|
|
295
|
+
const text = alignedValueText(ctx, `prototype/emit-prototype-iterator.ts:async-${member}`, sent.representation, channel, operandText(ctx, sent));
|
|
296
|
+
if (text === null) {
|
|
297
|
+
throw createCppEmitBlockedError(`conversion:${representationKey(sent.representation)}->${representationKey(channel)}`, `${what} sends "${representationKey(sent.representation)}" into a channel carried as "${representationKey(channel)}", ` +
|
|
298
|
+
'and no installed conversion reconciles them');
|
|
299
|
+
}
|
|
300
|
+
return text;
|
|
301
|
+
};
|
|
302
|
+
const stepText = (() => {
|
|
303
|
+
switch (member) {
|
|
304
|
+
case 'next':
|
|
305
|
+
return `${receiverText}.next(${channelText(carrier.resume, 'next(v)')})`;
|
|
306
|
+
case 'return':
|
|
307
|
+
return `${receiverText}.return_(${channelText(carrier.completion, 'return(v)')})`;
|
|
308
|
+
case 'throw': {
|
|
309
|
+
if (!argument)
|
|
310
|
+
throw createCppEmitBlockedError('call-abi:throw', 'throw(e) carries no argument to inject as the abrupt completion');
|
|
311
|
+
// Thrown as the carrier every `catch` inside the body binds, for the
|
|
312
|
+
// reason the synchronous generator's `throw(e)` below gives.
|
|
313
|
+
const text = alignedValueText(ctx, 'prototype/emit-prototype-iterator.ts:async-throw', argument.representation, thrownValueCarrier, operandText(ctx, argument));
|
|
314
|
+
if (text === null) {
|
|
315
|
+
throw createCppEmitBlockedError(`conversion:${representationKey(argument.representation)}->${representationKey(thrownValueCarrier)}`, `throw(e) sends "${representationKey(argument.representation)}" into the thrown-value carrier, and no installed conversion reconciles them`);
|
|
316
|
+
}
|
|
317
|
+
return `${receiverText}.throw_(std::make_exception_ptr(${text}))`;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
})();
|
|
321
|
+
if (operation.result === null)
|
|
322
|
+
return stepText;
|
|
323
|
+
const promised = operation.result.representation;
|
|
324
|
+
if (promised.kind !== 'promise') {
|
|
325
|
+
throw createCppEmitBlockedError(`runtime-helper:protocol:result:${representationKey(carrier)}`, `publishes "${representationKey(promised)}", but an async generator's ${member}() answers a promise of its IteratorResult`);
|
|
326
|
+
}
|
|
327
|
+
const union = iteratorResultUnionOf(carrier, promised.value);
|
|
328
|
+
const arms = iteratorResultArmsText(ctx, carrier, union, {
|
|
329
|
+
done: 'gea_step.done',
|
|
330
|
+
value: 'gea_step.value',
|
|
331
|
+
completion: 'gea_step.completion'
|
|
332
|
+
});
|
|
333
|
+
return `(${stepText}).then([](const ${cppTypeOf(carrier)}::Result& gea_step) -> ${cppTypeOf(union)} { ${arms} })`;
|
|
334
|
+
};
|
|
239
335
|
export const iteratorCallText = (ctx, member, receiverText, carrier, operation) => {
|
|
240
336
|
if (!iteratorPrototypeMethods.has(member)) {
|
|
241
337
|
throw createCppEmitBlockedError('property-access:iterator:get:false', `"${member}" was recorded as a deferred %GeneratorPrototype% read but this file renders no call for it`);
|
|
@@ -243,6 +339,8 @@ export const iteratorCallText = (ctx, member, receiverText, carrier, operation)
|
|
|
243
339
|
if (carrier === undefined) {
|
|
244
340
|
throw createCppEmitBlockedError(`host-invocation:GeneratorPrototype.${member}`, `"${member}" was recorded as a deferred iterator read with no cursor carrier to render it off`);
|
|
245
341
|
}
|
|
342
|
+
if (carrier.kind === 'async-generator')
|
|
343
|
+
return asyncGeneratorCallText(ctx, member, receiverText, carrier, operation);
|
|
246
344
|
if (member === 'next')
|
|
247
345
|
return nextCallText(ctx, receiverText, carrier, operation);
|
|
248
346
|
const stepText = abruptCallText(ctx, member, receiverText, carrier, operation);
|
|
@@ -7,10 +7,11 @@ import { type ConversionSite } from '../emit-narrowing.js';
|
|
|
7
7
|
* thenable is adopted, and anything else resolves to ITSELF. `Awaited<T>` is
|
|
8
8
|
* TypeScript's name for the same fact, which is why `await 1` is `1`.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* This is the BLOCKING rendering -- adoption as a read of the settled value,
|
|
11
|
+
* `.awaited()` -- and its one remaining caller is a module body's top-level
|
|
12
|
+
* `await`, which runs at the bottom of the program's own stack. Every `await`
|
|
13
|
+
* inside a function suspends instead: `coroutineAwaitStatements` below renders
|
|
14
|
+
* the same four shapes as `co_await`.
|
|
14
15
|
*
|
|
15
16
|
* The case this exists for is the THIRD one, which neither half of that
|
|
16
17
|
* sentence covers on its own: a union of both. `string | Promise<string>` is
|
|
@@ -44,3 +45,31 @@ export declare const awaitedText: (ctx: ConversionSite, site: string, carrier: R
|
|
|
44
45
|
* a union this cannot mint without the census's own arm ordering.
|
|
45
46
|
*/
|
|
46
47
|
export declare const awaitedRepresentation: (carrier: Representation) => Representation | null;
|
|
48
|
+
/**
|
|
49
|
+
* `await` inside an async COROUTINE: the same four resolution shapes
|
|
50
|
+
* `awaitedText` states, rendered as statements that suspend.
|
|
51
|
+
*
|
|
52
|
+
* `co_await promise` suspends the frame and resumes it from one promise job
|
|
53
|
+
* with the fulfillment value, or rethrows the rejection at the resume point
|
|
54
|
+
* where the enclosing `try` catches it. A non-thenable is awaited too --
|
|
55
|
+
* 27.7.5.3 wraps it in a resolved promise, so `await 1` still yields to the
|
|
56
|
+
* job queue once -- through `gea::awaitValue`, which is that one tick.
|
|
57
|
+
*
|
|
58
|
+
* Statements rather than one expression, because a `co_await` is legal in far
|
|
59
|
+
* fewer places than a read is: never inside a lambda, and every conversion
|
|
60
|
+
* renderer is free to spell its answer as one. So each arm suspends into a
|
|
61
|
+
* named local first, and only that local is ever handed to `alignedValueText`.
|
|
62
|
+
*
|
|
63
|
+
* `into` is the result cell, already declared; `null` discards the value, and
|
|
64
|
+
* so does a `void` target.
|
|
65
|
+
*/
|
|
66
|
+
export declare const coroutineAwaitStatements: (ctx: ConversionSite, site: string, carrier: Representation, text: string, target: Representation | null, into: string | null) => readonly string[];
|
|
67
|
+
/**
|
|
68
|
+
* The one-tick Await an async generator writes itself around a value it
|
|
69
|
+
* yields or returns, and the async-from-sync step's second tick (the runtime
|
|
70
|
+
* adds none of these). A box goes through `promiseResolveDynamic`, because it
|
|
71
|
+
* may hold a thenable to adopt and `gea::awaitValue` refuses a `gea::Value` at
|
|
72
|
+
* compile time for exactly that reason; every native carrier takes
|
|
73
|
+
* `awaitValue`, which already adopts a promise or a union arm holding one.
|
|
74
|
+
*/
|
|
75
|
+
export declare const awaitTickText: (carrier: Representation, text: string) => string;
|