@geastack/compiler 1.0.20 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-emit.js +11 -1
- package/dist/cli-package-source.d.ts +0 -4
- package/dist/cli-package-source.js +8 -112
- package/dist/cli-refusal-location.d.ts +6 -0
- package/dist/cli-refusal-location.js +5 -0
- package/dist/cli.js +2 -1
- package/dist/compiler.d.ts +4 -0
- package/dist/compiler.js +120 -29
- package/dist/conversion/algebra.d.ts +16 -1
- package/dist/conversion/algebra.js +2 -0
- package/dist/conversion/build.d.ts +12 -0
- package/dist/conversion/build.js +31 -6
- package/dist/conversion/constructor-identity-family.d.ts +49 -0
- package/dist/conversion/constructor-identity-family.js +67 -0
- package/dist/conversion/derive.js +39 -6
- package/dist/conversion/iterable-object-view.d.ts +44 -0
- package/dist/conversion/iterable-object-view.js +55 -0
- package/dist/conversion/iterator-object-view.d.ts +77 -0
- package/dist/conversion/iterator-object-view.js +112 -0
- package/dist/conversion/nodes.d.ts +93 -0
- package/dist/conversion/nodes.js +262 -5
- package/dist/conversion/operand-view.js +41 -0
- package/dist/conversion/protocol-iterator.d.ts +84 -0
- package/dist/conversion/protocol-iterator.js +88 -0
- package/dist/conversion/record-view.d.ts +152 -8
- package/dist/conversion/record-view.js +518 -37
- package/dist/conversion/registry.d.ts +32 -0
- package/dist/ir/borrowed-call-arguments.d.ts +22 -1
- package/dist/ir/borrowed-call-arguments.js +102 -1
- package/dist/ir/borrowed-callable-uses.d.ts +62 -0
- package/dist/ir/borrowed-callable-uses.js +135 -0
- package/dist/ir/boxed-bind-assumptions.d.ts +24 -0
- package/dist/ir/boxed-bind-assumptions.js +93 -0
- package/dist/ir/build.d.ts +18 -7
- package/dist/ir/build.js +71 -13
- package/dist/ir/call-dispatch.js +474 -10
- package/dist/ir/call-entry.d.ts +24 -1
- package/dist/ir/call-entry.js +106 -1
- package/dist/ir/callable-class-flow.d.ts +3 -1
- package/dist/ir/callable-class-flow.js +42 -6
- package/dist/ir/callable-identity-demand.d.ts +20 -1
- package/dist/ir/callable-identity-demand.js +157 -18
- package/dist/ir/callable-member-candidates.d.ts +11 -1
- package/dist/ir/callable-member-candidates.js +82 -3
- package/dist/ir/callable-records.js +2 -2
- package/dist/ir/callable-site-escape.d.ts +4 -0
- package/dist/ir/callable-site-escape.js +228 -0
- package/dist/ir/captures.d.ts +10 -1
- package/dist/ir/captures.js +219 -4
- package/dist/ir/certificate.js +87 -16
- package/dist/ir/certify/carrier-keys.d.ts +58 -1
- package/dist/ir/certify/carrier-keys.js +160 -6
- package/dist/ir/certify/property-access-keys.d.ts +17 -0
- package/dist/ir/certify/property-access-keys.js +36 -0
- package/dist/ir/certify/property-access.js +49 -4
- package/dist/ir/certify/runtime-helper.d.ts +4 -0
- package/dist/ir/certify/runtime-helper.js +17 -5
- package/dist/ir/certify.js +132 -79
- package/dist/ir/class-static-fields.d.ts +11 -0
- package/dist/ir/class-static-fields.js +28 -0
- package/dist/ir/construct-entry.d.ts +2 -1
- package/dist/ir/construct-entry.js +3 -2
- package/dist/ir/construction-only-fields.d.ts +73 -0
- package/dist/ir/construction-only-fields.js +211 -0
- package/dist/ir/dominance.d.ts +14 -0
- package/dist/ir/dominance.js +18 -4
- package/dist/ir/emission-representations.js +4 -1
- package/dist/ir/exception-edges.d.ts +17 -0
- package/dist/ir/exception-edges.js +75 -0
- package/dist/ir/facts.d.ts +54 -3
- package/dist/ir/facts.js +182 -5
- package/dist/ir/generator-split.js +2 -2
- package/dist/ir/instance-reparenting.d.ts +83 -0
- package/dist/ir/instance-reparenting.js +167 -0
- package/dist/ir/integer-storage.d.ts +29 -0
- package/dist/ir/integer-storage.js +188 -79
- package/dist/ir/integers.d.ts +16 -0
- package/dist/ir/integers.js +327 -8
- package/dist/ir/integrity-restrictions.d.ts +42 -9
- package/dist/ir/integrity-restrictions.js +335 -42
- package/dist/ir/key-order-observation.d.ts +38 -0
- package/dist/ir/key-order-observation.js +173 -0
- package/dist/ir/literal-set-membership.d.ts +30 -0
- package/dist/ir/literal-set-membership.js +277 -0
- package/dist/ir/lower-allocation.js +68 -8
- package/dist/ir/lower-completion.d.ts +0 -9
- package/dist/ir/lower-completion.js +14 -5
- package/dist/ir/lower-destructuring.js +24 -2
- package/dist/ir/lower-exceptions.js +4 -4
- package/dist/ir/lower-flow.d.ts +21 -0
- package/dist/ir/lower-flow.js +37 -3
- package/dist/ir/lower-graph.d.ts +19 -1
- package/dist/ir/lower-graph.js +91 -67
- package/dist/ir/lower-invocation.d.ts +16 -0
- package/dist/ir/lower-invocation.js +189 -29
- package/dist/ir/lower-narrow.d.ts +0 -46
- package/dist/ir/lower-narrow.js +63 -1
- package/dist/ir/lower-operands.d.ts +52 -2
- package/dist/ir/lower-operands.js +491 -8
- package/dist/ir/lower-property.d.ts +2 -1
- package/dist/ir/lower-property.js +140 -31
- package/dist/ir/lower-protocol.js +16 -4
- package/dist/ir/lower-proxy.d.ts +65 -0
- package/dist/ir/lower-proxy.js +181 -0
- package/dist/ir/lower.js +112 -17
- package/dist/ir/model.d.ts +228 -18
- package/dist/ir/native-class-accessor.d.ts +9 -2
- package/dist/ir/native-class-accessor.js +12 -3
- package/dist/ir/native-class-construction.d.ts +1 -1
- package/dist/ir/native-class-construction.js +2 -1
- package/dist/ir/native-class-initialization.js +2 -2
- package/dist/ir/object-value-conversions.js +20 -5
- package/dist/ir/operation-index.d.ts +16 -0
- package/dist/ir/operation-index.js +17 -0
- package/dist/ir/pcm-loops.d.ts +11 -0
- package/dist/ir/pcm-loops.js +284 -0
- package/dist/ir/presence-proof.js +5 -0
- package/dist/ir/program-facts.d.ts +10 -20
- package/dist/ir/program-facts.js +80 -6
- package/dist/ir/proven-branches.d.ts +2 -2
- package/dist/ir/proven-branches.js +198 -3
- package/dist/ir/queries.js +35 -1
- package/dist/ir/reflection-demand.d.ts +9 -4
- package/dist/ir/reflection-demand.js +410 -28
- package/dist/ir/refusal.d.ts +1 -0
- package/dist/ir/refusal.js +2 -1
- package/dist/ir/shake.d.ts +94 -1
- package/dist/ir/shake.js +209 -12
- package/dist/ir/shared-empty-records.d.ts +12 -0
- package/dist/ir/shared-empty-records.js +301 -0
- package/dist/ir/spread-copy-elision.d.ts +59 -0
- package/dist/ir/spread-copy-elision.js +431 -0
- package/dist/ir/stable-cell-reads.d.ts +40 -0
- package/dist/ir/stable-cell-reads.js +123 -0
- package/dist/ir/static-callables.js +50 -0
- package/dist/ir/string-layout-reuse.d.ts +16 -1
- package/dist/ir/string-layout-reuse.js +66 -0
- package/dist/ir/transfer.d.ts +72 -3
- package/dist/ir/transfer.js +511 -19
- package/dist/ir/typed-property-access.d.ts +18 -2
- package/dist/ir/typed-property-access.js +109 -12
- package/dist/ir/verify.js +2 -1
- package/dist/plugins/apple/plugin.js +3 -2
- package/dist/plugins/gea/host.d.ts +7 -0
- package/dist/plugins/gea/host.js +30 -1
- package/dist/plugins/gea/lower.js +6 -1
- package/dist/plugins/gea/plugin.js +7 -4
- package/dist/plugins/gea/render-bridge.d.ts +4 -2
- package/dist/plugins/gea/render-bridge.js +23 -7
- package/dist/plugins/model.d.ts +2 -0
- package/dist/project-preparation.d.ts +5 -1
- package/dist/project-preparation.js +184 -7
- package/dist/projection/bindings.d.ts +5 -2
- package/dist/projection/bindings.js +40 -1
- package/dist/projection/callee.d.ts +16 -0
- package/dist/projection/callee.js +35 -6
- package/dist/projection/class-prototype.js +5 -1
- package/dist/projection/classes.d.ts +65 -2
- package/dist/projection/classes.js +159 -2
- package/dist/projection/dispatch.d.ts +69 -18
- package/dist/projection/dispatch.js +391 -19
- package/dist/projection/fields.d.ts +4 -3
- package/dist/projection/fields.js +89 -21
- package/dist/projection/instance-test.d.ts +12 -0
- package/dist/projection/instance-test.js +40 -10
- package/dist/projection/method-value-escapes.d.ts +43 -0
- package/dist/projection/method-value-escapes.js +113 -0
- package/dist/projection/slots.d.ts +34 -1
- package/dist/projection/slots.js +82 -5
- package/dist/representation/any-null-record-members.d.ts +41 -0
- package/dist/representation/any-null-record-members.js +115 -0
- package/dist/representation/collections.d.ts +3 -1
- package/dist/representation/collections.js +5 -2
- package/dist/representation/derive.d.ts +9 -1
- package/dist/representation/derive.js +366 -25
- package/dist/representation/difference.js +14 -0
- package/dist/representation/embedded-carriers.js +1 -0
- package/dist/representation/host-abi.d.ts +15 -0
- package/dist/representation/host-abi.js +28 -0
- package/dist/representation/host-templates.d.ts +1 -1
- package/dist/representation/host-templates.js +7 -3
- package/dist/representation/intersection.js +22 -0
- package/dist/representation/json-nullable.d.ts +18 -0
- package/dist/representation/json-nullable.js +22 -0
- package/dist/representation/model.d.ts +141 -0
- package/dist/representation/model.js +47 -3
- package/dist/representation/object-shape.d.ts +5 -1
- package/dist/representation/object-shape.js +5 -2
- package/dist/representation/policies.d.ts +66 -1
- package/dist/representation/proxy-carriers.d.ts +71 -0
- package/dist/representation/proxy-carriers.js +330 -0
- package/dist/representation/publish.d.ts +9 -1
- package/dist/representation/publish.js +186 -18
- package/dist/representation/record-fields.d.ts +5 -0
- package/dist/representation/record-fields.js +7 -1
- package/dist/representation/static-field-cells.d.ts +61 -0
- package/dist/representation/static-field-cells.js +80 -0
- package/dist/representation/unassigned-binding-cells.d.ts +32 -0
- package/dist/representation/unassigned-binding-cells.js +44 -0
- package/dist/representation/union.js +17 -1
- package/dist/representation/unwritten-record-members.d.ts +54 -0
- package/dist/representation/unwritten-record-members.js +167 -0
- package/dist/representation/value-records.js +153 -11
- package/dist/semantics/ambient.d.ts +102 -0
- package/dist/semantics/ambient.js +183 -0
- package/dist/semantics/any-null-member-declarations.d.ts +32 -0
- package/dist/semantics/any-null-member-declarations.js +90 -0
- package/dist/semantics/borrowed-builtin-call-bind-source-transform.js +14 -0
- package/dist/semantics/borrowed-method-receiver-copy-source-transform.d.ts +51 -0
- package/dist/semantics/borrowed-method-receiver-copy-source-transform.js +367 -0
- package/dist/semantics/call-invalidated-narrowing.d.ts +3 -0
- package/dist/semantics/call-invalidated-narrowing.js +715 -0
- package/dist/semantics/callable-origins.d.ts +39 -0
- package/dist/semantics/callable-origins.js +73 -2
- package/dist/semantics/class-alias.d.ts +36 -0
- package/dist/semantics/class-alias.js +64 -14
- package/dist/semantics/class-heritage.d.ts +64 -0
- package/dist/semantics/class-heritage.js +278 -2
- package/dist/semantics/commonjs-wrapper.d.ts +1 -1
- package/dist/semantics/commonjs-wrapper.js +24 -7
- package/dist/semantics/constructor-function-class-source-transform.d.ts +4 -0
- package/dist/semantics/constructor-function-class-source-transform.js +327 -0
- package/dist/semantics/constructor-slot-subclasses.js +163 -4
- package/dist/semantics/declaration-overlay-transform.js +197 -3
- package/dist/semantics/frontend.d.ts +31 -0
- package/dist/semantics/frontend.js +212 -26
- package/dist/semantics/host-methods.d.ts +27 -2
- package/dist/semantics/host-methods.js +57 -4
- package/dist/semantics/host-protocols.d.ts +19 -8
- package/dist/semantics/host-protocols.js +145 -31
- package/dist/semantics/interface-families.d.ts +51 -2
- package/dist/semantics/interface-families.js +609 -23
- package/dist/semantics/interface-implementors.d.ts +20 -0
- package/dist/semantics/interface-implementors.js +130 -6
- package/dist/semantics/known-caller-predicate-parameters.d.ts +2 -0
- package/dist/semantics/known-caller-predicate-parameters.js +161 -0
- package/dist/semantics/model/intrinsic-accessor-getters.d.ts +10 -0
- package/dist/semantics/model/intrinsic-accessor-getters.js +4 -0
- package/dist/semantics/model/operands.d.ts +10 -0
- package/dist/semantics/model/operations.d.ts +107 -0
- package/dist/semantics/model/selected-signature.d.ts +33 -0
- package/dist/semantics/model/structural-type-table.d.ts +15 -0
- package/dist/semantics/model/structural-type-table.js +19 -1
- package/dist/semantics/model/structural-types.d.ts +99 -0
- package/dist/semantics/model/structural-types.js +31 -2
- package/dist/semantics/normalize/absent-globals.d.ts +1 -1
- package/dist/semantics/normalize/absent-globals.js +3 -3
- package/dist/semantics/normalize/bivariant-slot-parameter.d.ts +46 -0
- package/dist/semantics/normalize/bivariant-slot-parameter.js +372 -0
- package/dist/semantics/normalize/callback-parameter-contracts.d.ts +2 -0
- package/dist/semantics/normalize/callback-parameter-contracts.js +21 -0
- package/dist/semantics/normalize/census.d.ts +2 -1
- package/dist/semantics/normalize/census.js +25 -2
- package/dist/semantics/normalize/class-instance-record-statement.d.ts +37 -0
- package/dist/semantics/normalize/class-instance-record-statement.js +74 -0
- package/dist/semantics/normalize/collection-bindings.js +242 -5
- package/dist/semantics/normalize/commonjs-require.d.ts +35 -5
- package/dist/semantics/normalize/commonjs-require.js +464 -147
- package/dist/semantics/normalize/dead-event-emissions.d.ts +6 -0
- package/dist/semantics/normalize/dead-event-emissions.js +866 -0
- package/dist/semantics/normalize/dead-method-copies.d.ts +56 -0
- package/dist/semantics/normalize/dead-method-copies.js +239 -0
- package/dist/semantics/normalize/derived-expression-type.d.ts +149 -2
- package/dist/semantics/normalize/derived-expression-type.js +418 -14
- package/dist/semantics/normalize/field-bindings.js +139 -4
- package/dist/semantics/normalize/flow/callable-reach.js +162 -9
- package/dist/semantics/normalize/flow/member-call-forwarding.js +6 -0
- package/dist/semantics/normalize/flow/owned-class-receivers.js +40 -2
- package/dist/semantics/normalize/flow/source-class-data.d.ts +7 -1
- package/dist/semantics/normalize/flow/source-class-data.js +28 -9
- package/dist/semantics/normalize/flow/source-value-session.js +32 -13
- package/dist/semantics/normalize/flow/targets.d.ts +32 -0
- package/dist/semantics/normalize/flow/targets.js +65 -6
- package/dist/semantics/normalize/flow/value-flow.d.ts +7 -0
- package/dist/semantics/normalize/flow/value-flow.js +30 -2
- package/dist/semantics/normalize/fresh-array-result.d.ts +32 -0
- package/dist/semantics/normalize/fresh-array-result.js +125 -0
- package/dist/semantics/normalize/gating.js +2 -0
- package/dist/semantics/normalize/global-host-mutations.d.ts +11 -1
- package/dist/semantics/normalize/global-host-mutations.js +691 -27
- package/dist/semantics/normalize/host-effect-contracts.d.ts +43 -1
- package/dist/semantics/normalize/host-effect-contracts.js +60 -3
- package/dist/semantics/normalize/host-mutation-key-reader.js +35 -10
- package/dist/semantics/normalize/identities.js +64 -3
- package/dist/semantics/normalize/intrinsic-accessor-getter.d.ts +59 -0
- package/dist/semantics/normalize/intrinsic-accessor-getter.js +129 -0
- package/dist/semantics/normalize/local-bindings.js +117 -21
- package/dist/semantics/normalize/merged-declaration.d.ts +41 -0
- package/dist/semantics/normalize/merged-declaration.js +81 -0
- package/dist/semantics/normalize/never-override-result.d.ts +21 -0
- package/dist/semantics/normalize/never-override-result.js +64 -0
- package/dist/semantics/normalize/null-blind-parameter.d.ts +21 -0
- package/dist/semantics/normalize/null-blind-parameter.js +77 -0
- package/dist/semantics/normalize/object-bag-bindings.js +26 -2
- package/dist/semantics/normalize/omitted-stated-parameter.d.ts +1 -1
- package/dist/semantics/normalize/omitted-stated-parameter.js +34 -4
- package/dist/semantics/normalize/override-field-arms.d.ts +33 -0
- package/dist/semantics/normalize/override-field-arms.js +362 -0
- package/dist/semantics/normalize/parameter-bindings.d.ts +64 -1
- package/dist/semantics/normalize/parameter-bindings.js +827 -81
- package/dist/semantics/normalize/parameter-slot.d.ts +1 -0
- package/dist/semantics/normalize/parameter-slot.js +69 -0
- package/dist/semantics/normalize/physical-overload-result.d.ts +45 -0
- package/dist/semantics/normalize/physical-overload-result.js +132 -0
- package/dist/semantics/normalize/producer-context.d.ts +23 -0
- package/dist/semantics/normalize/producers/allocations.d.ts +13 -0
- package/dist/semantics/normalize/producers/allocations.js +8 -15
- package/dist/semantics/normalize/producers/binding-kind.d.ts +11 -0
- package/dist/semantics/normalize/producers/binding-kind.js +31 -0
- package/dist/semantics/normalize/producers/bindings.js +16 -1
- package/dist/semantics/normalize/producers/boundary.js +21 -1
- package/dist/semantics/normalize/producers/class-lifecycle.js +23 -14
- package/dist/semantics/normalize/producers/computations.js +8 -67
- package/dist/semantics/normalize/producers/control-loops.d.ts +1 -1
- package/dist/semantics/normalize/producers/control-loops.js +25 -1
- package/dist/semantics/normalize/producers/control.js +87 -60
- package/dist/semantics/normalize/producers/declaration-lifecycle.js +5 -0
- package/dist/semantics/normalize/producers/enums.d.ts +10 -0
- package/dist/semantics/normalize/producers/enums.js +169 -0
- package/dist/semantics/normalize/producers/erasure.d.ts +10 -0
- package/dist/semantics/normalize/producers/erasure.js +23 -0
- package/dist/semantics/normalize/producers/intrinsic-accessor-getter.d.ts +15 -0
- package/dist/semantics/normalize/producers/intrinsic-accessor-getter.js +33 -0
- package/dist/semantics/normalize/producers/invocations.js +255 -18
- package/dist/semantics/normalize/producers/iteration-yield.js +6 -1
- package/dist/semantics/normalize/producers/logical-merge-type.d.ts +36 -0
- package/dist/semantics/normalize/producers/logical-merge-type.js +163 -0
- package/dist/semantics/normalize/producers/properties.js +207 -18
- package/dist/semantics/normalize/producers/protocol.d.ts +4 -0
- package/dist/semantics/normalize/producers/protocol.js +147 -12
- package/dist/semantics/normalize/producers/references.js +50 -9
- package/dist/semantics/normalize/producers/shared.d.ts +120 -0
- package/dist/semantics/normalize/producers/shared.js +359 -10
- package/dist/semantics/normalize/producers/spread-arguments.js +85 -4
- package/dist/semantics/normalize/producers/tuple-spread.d.ts +1 -0
- package/dist/semantics/normalize/producers/tuple-spread.js +1 -1
- package/dist/semantics/normalize/property-key-domain.js +6 -0
- package/dist/semantics/normalize/reachability.d.ts +7 -0
- package/dist/semantics/normalize/reachability.js +166 -9
- package/dist/semantics/normalize/record-home-arms.d.ts +25 -0
- package/dist/semantics/normalize/record-home-arms.js +87 -0
- package/dist/semantics/normalize/record-link-families.d.ts +74 -0
- package/dist/semantics/normalize/record-link-families.js +327 -0
- package/dist/semantics/normalize/record-stand-in-arms.d.ts +56 -0
- package/dist/semantics/normalize/record-stand-in-arms.js +484 -0
- package/dist/semantics/normalize/return-bindings.d.ts +6 -2
- package/dist/semantics/normalize/return-bindings.js +60 -7
- package/dist/semantics/normalize/script-global-redefinition.js +5 -0
- package/dist/semantics/normalize/shared-array-storage.d.ts +42 -0
- package/dist/semantics/normalize/shared-array-storage.js +373 -0
- package/dist/semantics/normalize/sloppy-absence.d.ts +41 -0
- package/dist/semantics/normalize/sloppy-absence.js +199 -0
- package/dist/semantics/normalize/specialization.d.ts +40 -0
- package/dist/semantics/normalize/specialization.js +770 -36
- package/dist/semantics/normalize/structural-array-element.js +196 -6
- package/dist/semantics/normalize/structural-array-read.js +12 -0
- package/dist/semantics/normalize/structural-creation-order.d.ts +15 -0
- package/dist/semantics/normalize/structural-creation-order.js +51 -48
- package/dist/semantics/normalize/structural-declarations.d.ts +16 -0
- package/dist/semantics/normalize/structural-declarations.js +43 -0
- package/dist/semantics/normalize/structural-generics.d.ts +13 -0
- package/dist/semantics/normalize/structural-generics.js +22 -0
- package/dist/semantics/normalize/structural-indexed-access.js +16 -0
- package/dist/semantics/normalize/structural-instantiated-member.js +68 -2
- package/dist/semantics/normalize/structural-joins.js +2 -0
- package/dist/semantics/normalize/structural-layout-relevance.d.ts +30 -0
- package/dist/semantics/normalize/structural-layout-relevance.js +164 -0
- package/dist/semantics/normalize/structural-layout-type.js +270 -14
- package/dist/semantics/normalize/structural-leaves.d.ts +1 -1
- package/dist/semantics/normalize/structural-leaves.js +17 -3
- package/dist/semantics/normalize/structural-mutable-method.js +5 -1
- package/dist/semantics/normalize/structural-parts.d.ts +18 -5
- package/dist/semantics/normalize/structural-parts.js +68 -19
- package/dist/semantics/normalize/structural-receiver.d.ts +1 -1
- package/dist/semantics/normalize/structural-receiver.js +23 -1
- package/dist/semantics/normalize/structural-self-reference.d.ts +1 -1
- package/dist/semantics/normalize/structural-self-reference.js +23 -2
- package/dist/semantics/normalize/structural.d.ts +12 -1
- package/dist/semantics/normalize/structural.js +1437 -53
- package/dist/semantics/normalize/suppressed-write-arms.d.ts +47 -0
- package/dist/semantics/normalize/suppressed-write-arms.js +393 -0
- package/dist/semantics/normalize/unresolvable-names.d.ts +15 -2
- package/dist/semantics/normalize/unresolvable-names.js +30 -6
- package/dist/semantics/normalize/unshared-array-result.d.ts +32 -0
- package/dist/semantics/normalize/unshared-array-result.js +125 -0
- package/dist/semantics/package-sources.d.ts +1 -1
- package/dist/semantics/package-sources.js +120 -8
- package/dist/semantics/program.d.ts +20 -0
- package/dist/semantics/program.js +179 -26
- package/dist/semantics/shared-declaration-files.d.ts +44 -0
- package/dist/semantics/shared-declaration-files.js +42 -0
- package/dist/semantics/stable-checker.d.ts +1 -1
- package/dist/semantics/stable-checker.js +7 -2
- package/dist/semantics/subclass-member-overlay-transform.js +95 -53
- package/dist/semantics/unchecked-guard-argument-copies.d.ts +67 -0
- package/dist/semantics/unchecked-guard-argument-copies.js +163 -0
- package/dist/semantics/unchecked-write-member-declarations.d.ts +46 -0
- package/dist/semantics/unchecked-write-member-declarations.js +331 -0
- package/dist/targets/cpp/balanced-units.d.ts +31 -0
- package/dist/targets/cpp/balanced-units.js +57 -0
- package/dist/targets/cpp/borrowed-arm-projections.d.ts +31 -0
- package/dist/targets/cpp/borrowed-arm-projections.js +106 -0
- package/dist/targets/cpp/borrowed-call-entry.d.ts +1 -1
- package/dist/targets/cpp/borrowed-call-entry.js +24 -20
- package/dist/targets/cpp/captures.js +314 -8
- package/dist/targets/cpp/char-code-buffers.d.ts +36 -0
- package/dist/targets/cpp/char-code-buffers.js +214 -0
- package/dist/targets/cpp/class-layout.d.ts +7 -1
- package/dist/targets/cpp/class-layout.js +42 -17
- package/dist/targets/cpp/class-properties/computed-method-value.d.ts +17 -2
- package/dist/targets/cpp/class-properties/computed-method-value.js +50 -4
- package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +31 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.js +174 -17
- package/dist/targets/cpp/class-ref-transport.d.ts +32 -0
- package/dist/targets/cpp/class-ref-transport.js +56 -1
- package/dist/targets/cpp/conversions.js +1827 -1502
- package/dist/targets/cpp/coroutine-bodies.d.ts +97 -0
- package/dist/targets/cpp/coroutine-bodies.js +187 -0
- package/dist/targets/cpp/document.js +11 -1
- package/dist/targets/cpp/emit-allocation.js +568 -21
- package/dist/targets/cpp/emit-arrays.d.ts +10 -0
- package/dist/targets/cpp/emit-arrays.js +147 -16
- package/dist/targets/cpp/emit-binding-reference.d.ts +26 -2
- package/dist/targets/cpp/emit-binding-reference.js +97 -5
- package/dist/targets/cpp/emit-bindings.d.ts +9 -1
- package/dist/targets/cpp/emit-bindings.js +108 -8
- package/dist/targets/cpp/emit-buffers.d.ts +2 -16
- package/dist/targets/cpp/emit-buffers.js +124 -25
- package/dist/targets/cpp/emit-callable.d.ts +35 -72
- package/dist/targets/cpp/emit-callable.js +647 -82
- package/dist/targets/cpp/emit-carrier-members.d.ts +13 -2
- package/dist/targets/cpp/emit-carrier-members.js +50 -9
- package/dist/targets/cpp/emit-constructor-identity-family.d.ts +20 -0
- package/dist/targets/cpp/emit-constructor-identity-family.js +45 -0
- package/dist/targets/cpp/emit-context.d.ts +329 -15
- package/dist/targets/cpp/emit-context.js +104 -13
- package/dist/targets/cpp/emit-dynamic-properties.d.ts +44 -0
- package/dist/targets/cpp/emit-dynamic-properties.js +256 -37
- package/dist/targets/cpp/emit-equality.js +117 -2
- package/dist/targets/cpp/emit-error-constructor.d.ts +19 -0
- package/dist/targets/cpp/emit-error-constructor.js +73 -0
- package/dist/targets/cpp/emit-exceptions.d.ts +25 -3
- package/dist/targets/cpp/emit-exceptions.js +215 -26
- package/dist/targets/cpp/emit-in.js +52 -5
- package/dist/targets/cpp/emit-instanceof.js +59 -11
- package/dist/targets/cpp/emit-integers.d.ts +6 -0
- package/dist/targets/cpp/emit-integers.js +10 -0
- package/dist/targets/cpp/emit-iterable-object-view.d.ts +15 -0
- package/dist/targets/cpp/emit-iterable-object-view.js +51 -0
- package/dist/targets/cpp/emit-iterator-object-view.d.ts +15 -0
- package/dist/targets/cpp/emit-iterator-object-view.js +125 -0
- package/dist/targets/cpp/emit-iterator.d.ts +7 -10
- package/dist/targets/cpp/emit-iterator.js +361 -24
- package/dist/targets/cpp/emit-json.d.ts +7 -1
- package/dist/targets/cpp/emit-json.js +595 -55
- package/dist/targets/cpp/emit-jsx.d.ts +0 -37
- package/dist/targets/cpp/emit-jsx.js +70 -8
- package/dist/targets/cpp/emit-narrowing.d.ts +192 -28
- package/dist/targets/cpp/emit-narrowing.js +1595 -120
- package/dist/targets/cpp/emit-native-selection.js +8 -2
- package/dist/targets/cpp/emit-presence.js +13 -0
- package/dist/targets/cpp/emit-properties.d.ts +3 -1
- package/dist/targets/cpp/emit-properties.js +303 -54
- package/dist/targets/cpp/emit-protocol-iterator.d.ts +14 -0
- package/dist/targets/cpp/emit-protocol-iterator.js +203 -0
- package/dist/targets/cpp/emit-proxy.d.ts +17 -0
- package/dist/targets/cpp/emit-proxy.js +35 -0
- package/dist/targets/cpp/emit-record-view.d.ts +12 -1
- package/dist/targets/cpp/emit-record-view.js +429 -18
- package/dist/targets/cpp/emit-return.d.ts +38 -0
- package/dist/targets/cpp/emit-return.js +143 -21
- package/dist/targets/cpp/emit-scopes.d.ts +78 -0
- package/dist/targets/cpp/emit-scopes.js +196 -0
- package/dist/targets/cpp/emit-sum-widening.js +6 -3
- package/dist/targets/cpp/emit-tonumber.d.ts +40 -1
- package/dist/targets/cpp/emit-tonumber.js +75 -4
- package/dist/targets/cpp/emit-tostring.d.ts +28 -2
- package/dist/targets/cpp/emit-tostring.js +115 -12
- package/dist/targets/cpp/emit-typeof.js +2 -2
- package/dist/targets/cpp/emit-union-properties.d.ts +9 -0
- package/dist/targets/cpp/emit-union-properties.js +391 -49
- package/dist/targets/cpp/emit.d.ts +3 -1
- package/dist/targets/cpp/emit.js +725 -90
- package/dist/targets/cpp/evaluated-once.d.ts +51 -0
- package/dist/targets/cpp/evaluated-once.js +140 -0
- package/dist/targets/cpp/host/core-globals.d.ts +0 -21
- package/dist/targets/cpp/host/core-globals.js +10 -2
- package/dist/targets/cpp/host/emit-host-invoke.d.ts +0 -10
- package/dist/targets/cpp/host/emit-host-invoke.js +454 -36
- package/dist/targets/cpp/host/emit-host-object.js +733 -88
- package/dist/targets/cpp/host/emit-host-properties.js +26 -2
- package/dist/targets/cpp/host/emit-host-reflect.d.ts +1 -0
- package/dist/targets/cpp/host/emit-host-reflect.js +26 -7
- package/dist/targets/cpp/host/emit-host-value.d.ts +13 -0
- package/dist/targets/cpp/host/emit-host-value.js +47 -3
- package/dist/targets/cpp/host/host-members.d.ts +11 -0
- package/dist/targets/cpp/host/host-members.js +50 -4
- package/dist/targets/cpp/host/native-protocols.js +3 -0
- package/dist/targets/cpp/host/object-protocol.d.ts +8 -0
- package/dist/targets/cpp/host/object-protocol.js +55 -13
- package/dist/targets/cpp/key-order-tracking.d.ts +11 -0
- package/dist/targets/cpp/key-order-tracking.js +18 -0
- package/dist/targets/cpp/manifest/capabilities.js +117 -9
- package/dist/targets/cpp/manifest.js +14 -0
- package/dist/targets/cpp/native-collection-base.d.ts +27 -0
- package/dist/targets/cpp/native-collection-base.js +202 -0
- package/dist/targets/cpp/native-error-base.d.ts +14 -0
- package/dist/targets/cpp/native-error-base.js +19 -4
- package/dist/targets/cpp/native-promise-base.d.ts +23 -0
- package/dist/targets/cpp/native-promise-base.js +30 -0
- package/dist/targets/cpp/native-symbol-keys.js +1 -1
- package/dist/targets/cpp/prototype/emit-prototype-array.js +258 -20
- package/dist/targets/cpp/prototype/emit-prototype-date.js +5 -4
- package/dist/targets/cpp/prototype/emit-prototype-invoke.d.ts +9 -1
- package/dist/targets/cpp/prototype/emit-prototype-invoke.js +232 -26
- package/dist/targets/cpp/prototype/emit-prototype-iterator.d.ts +1 -1
- package/dist/targets/cpp/prototype/emit-prototype-iterator.js +111 -13
- package/dist/targets/cpp/prototype/emit-prototype-promise.d.ts +33 -4
- package/dist/targets/cpp/prototype/emit-prototype-promise.js +218 -10
- package/dist/targets/cpp/prototype/emit-prototype-regexp.js +8 -5
- package/dist/targets/cpp/prototype/emit-prototype-string.js +24 -7
- package/dist/targets/cpp/prototype/prototype-method-reads.js +18 -3
- package/dist/targets/cpp/reactive-dependencies.d.ts +2 -0
- package/dist/targets/cpp/reactive-dependencies.js +94 -3
- package/dist/targets/cpp/realm-storage.d.ts +5 -0
- package/dist/targets/cpp/realm-storage.js +12 -0
- package/dist/targets/cpp/records.d.ts +151 -1
- package/dist/targets/cpp/records.js +1328 -122
- package/dist/targets/cpp/recursive-containers.d.ts +4 -1
- package/dist/targets/cpp/recursive-containers.js +28 -9
- package/dist/targets/cpp/translation-unit.d.ts +10 -0
- package/dist/targets/cpp/translation-unit.js +686 -140
- package/dist/targets/cpp/types.d.ts +56 -6
- package/dist/targets/cpp/types.js +218 -12
- package/dist/targets/cpp/virtual-methods.d.ts +3 -3
- package/dist/targets/cpp/virtual-methods.js +174 -17
- package/package.json +14 -13
- package/src/targets/cpp/runtime/gea_dynamic_proxy.h +155 -25
- package/src/targets/cpp/runtime/gea_eval.h +3 -0
- package/src/targets/cpp/runtime/gea_pcm.h +116 -0
- package/src/targets/cpp/runtime/gea_runtime.h +18159 -4887
- package/src/targets/cpp/runtime/gea_runtime_builtins.cpp +7 -45
- package/src/targets/cpp/runtime/gea_runtime_rtc.h +247 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { usesRealmStorage } from './realm-storage.js';
|
|
1
2
|
import { boxedValueText } from './emit-dynamic-properties.js';
|
|
2
3
|
import { isCanonicalNumberPropertyKeyText, representationKey } from '../../representation/model.js';
|
|
3
4
|
import { completeTemplateObjectCarrier, isCompleteTemplateObjectCarrier, templateObjectCapabilityKeyOf } from '../../representation/template-object.js';
|
|
4
5
|
import { fieldPresenceOf, staticOwnFieldsOf } from '../../representation/record-fields.js';
|
|
5
|
-
import { regexpFlagSupportKeyOf, spreadSourceCarrierKeyOf } from '../../ir/certify/carrier-keys.js';
|
|
6
|
-
import { createCppEmitBlockedError, defineValue, internTemplateObject, operandText } from './emit-context.js';
|
|
6
|
+
import { regexpFlagSupportKeyOf, indexedRecordViewOf, isCopyableIndexedRecordIntoDictionary, isDynamicCopyableIntoFieldRecord, spreadFieldRecordReceiverOf, spreadIndexedRecordReceiverOf, spreadSourceCarrierKeyOf } from '../../ir/certify/carrier-keys.js';
|
|
7
|
+
import { createCppEmitBlockedError, defineValue, internTemplateObject, isCppEmitBlockedError, operandText } from './emit-context.js';
|
|
7
8
|
import { memberAccessOperator } from './emit-carrier-members.js';
|
|
8
|
-
import { cppArrayExtensionStructName, cppRecordFieldName, cppRecordAccessorEnvironmentName, cppRecordFieldPresenceName, cppRecordStructName, cppStringLiteral, cppTypeOf } from './types.js';
|
|
9
|
-
import { declaredRecordFieldOf, declaredFieldRepresentationOf, recordAccessorsOfShape } from './records.js';
|
|
9
|
+
import { cppArrayExtensionStructName, cppRecordFieldName, cppRecordAccessorEnvironmentName, cppRecordFieldPresenceName, cppRecordStructName, cppStringLiteral, cppTypeOf, unitFunctionName } from './types.js';
|
|
10
|
+
import { cppRecordIndexAttributesNameFor, cppRecordIndexSidecarNameFor, declaredRecordFieldOf, declaredFieldRepresentationOf, recordAccessorsOfShape, recordFieldsOfShape, tailAwareFieldWriteText, tailAwareFieldReadText, staticKeyOrderText } from './records.js';
|
|
11
|
+
import { keyOrderUnobservedIn, tracksKeyOrder } from './key-order-tracking.js';
|
|
10
12
|
import { alignedValueText } from './emit-narrowing.js';
|
|
11
13
|
import { cppRegExpNativeTypes } from './regexp-types.js';
|
|
12
14
|
import { armAt, armIs } from './emit-union-properties.js';
|
|
@@ -19,8 +21,32 @@ import { packedEnvironmentText } from './emit-callable.js';
|
|
|
19
21
|
* behind a `shared_ptr`, or a keyed container -- is decided by the carrier the
|
|
20
22
|
* deriver already chose, never re-decided here.
|
|
21
23
|
*/
|
|
24
|
+
/**
|
|
25
|
+
* The receiver's own `.fields` list, resolved for `tailAwareFieldWriteText`
|
|
26
|
+
* -- the same question `emit-properties.ts`'s `recordFieldsForTailLookup`
|
|
27
|
+
* asks of a later store, asked here of the FIRST one: a construction site's
|
|
28
|
+
* sequential field stores (`emitFieldInits`, below) are the identical
|
|
29
|
+
* mechanism a later store already goes through (`emit-allocation.ts` has no
|
|
30
|
+
* separate positional/aggregate-initialization path), so a field this
|
|
31
|
+
* layout moved behind the tail must be spelled through
|
|
32
|
+
* `RecordTail::ensure()` on its very first write too, not only on a later
|
|
33
|
+
* one. `class-ref` is included here (unlike the read-side helper, which a
|
|
34
|
+
* class field read never reaches through this file's own record/native-ref
|
|
35
|
+
* cases) because a class literal's own fields ARE initialized through this
|
|
36
|
+
* exact function.
|
|
37
|
+
*/
|
|
38
|
+
const recordFieldsForTailLookup = (ctx, representation) => {
|
|
39
|
+
if (representation.kind === 'record' || representation.kind === 'record-with-index')
|
|
40
|
+
return representation.fields;
|
|
41
|
+
if (representation.kind === 'native-record-ref' && representation.native === null)
|
|
42
|
+
return recordFieldsOfShape(ctx.deriver, representation.shapeId);
|
|
43
|
+
if (representation.kind === 'class-ref')
|
|
44
|
+
return recordFieldsOfShape(ctx.deriver, representation.shapeId);
|
|
45
|
+
return null;
|
|
46
|
+
};
|
|
22
47
|
const emitFieldInits = (ctx, lines, receiverName, representation, ownership, fields) => {
|
|
23
48
|
const accessor = memberAccessOperator(ownership);
|
|
49
|
+
const tailLookupFields = recordFieldsForTailLookup(ctx, representation);
|
|
24
50
|
for (const field of fields) {
|
|
25
51
|
const rawValueText = operandText(ctx, field.value);
|
|
26
52
|
// An object literal's OWN inferred carrier for a field can be narrower
|
|
@@ -44,13 +70,26 @@ const emitFieldInits = (ctx, lines, receiverName, representation, ownership, fie
|
|
|
44
70
|
const valueText = (held ? alignedValueText(ctx, 'emit-allocation.ts:71', field.value.representation, held, rawValueText) : null) ?? rawValueText;
|
|
45
71
|
// `field.key` is the layout's own key -- `"0"` for a tuple slot -- not a
|
|
46
72
|
// C++ member name. `renderStructDefinition` declared that member through
|
|
47
|
-
// `cppRecordFieldName
|
|
48
|
-
|
|
73
|
+
// `cppRecordFieldName` (tail-placed ones through `RecordTail::ensure()`
|
|
74
|
+
// instead), so the initializer has to reach it the identical way.
|
|
75
|
+
const member = tailLookupFields === null ? cppRecordFieldName(field.key) : tailAwareFieldWriteText(tailLookupFields, field.key);
|
|
76
|
+
lines.push(`${receiverName}${accessor}${member} = ${valueText};`);
|
|
49
77
|
const declared = declaredRecordFieldOf(ctx.deriver, representation, field.key, ctx.classes);
|
|
50
78
|
if (declared && !declared.required) {
|
|
51
79
|
lines.push(`${receiverName}${accessor}${cppRecordFieldPresenceName(field.key)} = true;`);
|
|
52
80
|
}
|
|
53
81
|
}
|
|
82
|
+
// The struct lists its fields in the declared type's order, which is the
|
|
83
|
+
// literal's creation order only when the literal writes them in that
|
|
84
|
+
// order: `const o: Wide = { s3, id }` creates `s3` first. Such a literal
|
|
85
|
+
// hands the runtime its own order up front; one in layout order costs
|
|
86
|
+
// nothing.
|
|
87
|
+
if (tailLookupFields !== null && tracksKeyOrder(ctx, representation)) {
|
|
88
|
+
const positions = fields.map((field) => tailLookupFields.findIndex((candidate) => candidate.key === field.key));
|
|
89
|
+
if (positions.some((position, index) => index > 0 && position < (positions[index - 1] ?? -1))) {
|
|
90
|
+
lines.push(staticKeyOrderText(receiverName, fields.map((field) => field.key)));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
54
93
|
};
|
|
55
94
|
/**
|
|
56
95
|
* An object literal whose layout is a DICTIONARY, not a struct.
|
|
@@ -125,6 +164,14 @@ export const emitAllocateRecord = (ctx, lines, operation) => {
|
|
|
125
164
|
emitAllocateDictionary(ctx, lines, operation, representation);
|
|
126
165
|
return;
|
|
127
166
|
}
|
|
167
|
+
// An object literal laid out as a data-only class (`lower-allocation.ts`):
|
|
168
|
+
// the class's struct in a block whose header names a plain object, so
|
|
169
|
+
// every instance test and boxed reflection still answers `Object`. Its
|
|
170
|
+
// members are the literal's later `define-own-property` stores.
|
|
171
|
+
if (representation.kind === 'class-ref' && representation.ownership === 'shared-refcount') {
|
|
172
|
+
lines.push(`${defineValue(ctx, operation.result)} = gea::makePlainObjectRef<${cppTypeOf(representation)}>();`);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
128
175
|
if (representation.kind !== 'record' && representation.kind !== 'record-with-index' && representation.kind !== 'native-record-ref') {
|
|
129
176
|
throw createCppEmitBlockedError(`runtime-helper:allocation:object-literal:${representation.kind}`, `carries a "${representation.kind}" result, but this emitter only allocates "record", "record-with-index", "native-record-ref" and "dictionary"`);
|
|
130
177
|
}
|
|
@@ -172,7 +219,7 @@ export const emitAllocateRecord = (ctx, lines, operation) => {
|
|
|
172
219
|
lines.push(`${name} = ${cppTypeOf(representation)}{};`);
|
|
173
220
|
break;
|
|
174
221
|
case 'shared-refcount':
|
|
175
|
-
lines.push(`${name} = gea
|
|
222
|
+
lines.push(`${name} = gea::${operation.sharedEmpty === true ? 'sharedEmptyRef' : 'makeRef'}<${structName}>();`);
|
|
176
223
|
break;
|
|
177
224
|
case 'borrowed':
|
|
178
225
|
// A borrow is a reference to an object something else owns, and an
|
|
@@ -302,7 +349,7 @@ export const emitAllocateTemplateObject = (ctx, lines, operation) => {
|
|
|
302
349
|
// Render from the same canonical object the predicate compared against, so
|
|
303
350
|
// this function cannot gradually grow a second, broader carrier contract.
|
|
304
351
|
const { holder, body } = templateArrayObjectBody(completeTemplateObjectCarrier, operation);
|
|
305
|
-
const accessor = internTemplateObject(ctx.templateObjects, operation, holder, body);
|
|
352
|
+
const accessor = internTemplateObject(ctx.templateObjects, operation, holder, body, usesRealmStorage(ctx.placements));
|
|
306
353
|
const name = defineValue(ctx, operation.result);
|
|
307
354
|
lines.push(`${name} = ${accessor}();`);
|
|
308
355
|
return;
|
|
@@ -434,7 +481,10 @@ export { emitToNumericCoercion } from './emit-tonumber.js';
|
|
|
434
481
|
export const emitSpreadCopy = (ctx, lines, operation) => {
|
|
435
482
|
const receiver = operation.receiver.representation;
|
|
436
483
|
const source = operation.source.representation;
|
|
437
|
-
if (source.kind === 'dynamic' &&
|
|
484
|
+
if (source.kind === 'dynamic' &&
|
|
485
|
+
receiver.kind !== 'dynamic' &&
|
|
486
|
+
!isDynamicCopyableIntoFieldRecord(ctx.deriver, receiver) &&
|
|
487
|
+
!(receiver.kind === 'dictionary' && receiver.key === 'string')) {
|
|
438
488
|
throw createCppEmitBlockedError(`runtime-helper:protocol:spread:next:${spreadSourceCarrierKeyOf(source.kind, source, receiver, ctx.deriver)}`, `requires a dynamic object-spread receiver for a dynamic source, but the receiver is a "${representationKey(receiver)}"; this runtime-key walk is installed only for a dynamic receiver`);
|
|
439
489
|
}
|
|
440
490
|
if (receiver.kind === 'dynamic') {
|
|
@@ -457,8 +507,23 @@ export const emitSpreadCopy = (ctx, lines, operation) => {
|
|
|
457
507
|
lines.push('}');
|
|
458
508
|
return;
|
|
459
509
|
}
|
|
510
|
+
// The keys the literal created before this spread come first; a key the
|
|
511
|
+
// copy creates is learned after them, in the copy's order
|
|
512
|
+
// (`gea::detail::NativeOwnKeyOrder`).
|
|
513
|
+
const prior = ctx.spreadPriorKeys.get(operation);
|
|
514
|
+
if (prior !== undefined && tracksKeyOrder(ctx, receiver)) {
|
|
515
|
+
lines.push(staticKeyOrderText(operandText(ctx, operation.receiver), prior));
|
|
516
|
+
}
|
|
517
|
+
if (indexedRecordViewOf(ctx.deriver, receiver) !== null) {
|
|
518
|
+
emitSpreadIntoIndexedRecord(ctx, lines, operation);
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (spreadFieldRecordReceiverOf(ctx.deriver, receiver) !== null) {
|
|
522
|
+
emitSpreadIntoFieldRecord(ctx, lines, operation);
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
460
525
|
if (receiver.kind !== 'dictionary') {
|
|
461
|
-
throw createCppEmitBlockedError(`runtime-helper:protocol:spread:next:${spreadSourceCarrierKeyOf(source.kind, source, receiver, ctx.deriver)}`, `writes a runtime object-spread copy into a "${receiver.kind}" receiver, but this emitter only renders one into a "dictionary"`);
|
|
526
|
+
throw createCppEmitBlockedError(`runtime-helper:protocol:spread:next:${spreadSourceCarrierKeyOf(source.kind, source, receiver, ctx.deriver)}`, `writes a runtime object-spread copy into a "${receiver.kind}" receiver, but this emitter only renders one into a "dictionary" or a "record-with-index"`);
|
|
462
527
|
}
|
|
463
528
|
if (receiver.ownership === 'borrowed') {
|
|
464
529
|
throw createCppEmitBlockedError('runtime-helper:protocol:spread:next:dictionary(borrowed)', 'writes into a dictionary receiver carried with ownership "borrowed", which names no object this copy may write through');
|
|
@@ -466,20 +531,57 @@ export const emitSpreadCopy = (ctx, lines, operation) => {
|
|
|
466
531
|
const receiverText = operandText(ctx, operation.receiver);
|
|
467
532
|
const receiverRef = memberAccessOperator(receiver.ownership) === '->' ? `(*${receiverText})` : receiverText;
|
|
468
533
|
const sourceText = operandText(ctx, operation.source);
|
|
469
|
-
|
|
534
|
+
if (source.kind === 'dynamic') {
|
|
535
|
+
emitDynamicSpreadIntoDictionary(ctx, lines, source, sourceText, receiver, receiverRef);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
emitSpreadSourceCopy(ctx, lines, source, sourceText, receiver, receiverRef, spreadKeysOf(operation));
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
541
|
+
* `{ ...value }` of a dynamic source into a string-keyed dictionary: mongodb's
|
|
542
|
+
* `mechanismProperties = { ...optionValue }`, where `optionValue` is declared
|
|
543
|
+
* `unknown` and only bounded by an `isRecord` guard
|
|
544
|
+
* (`producers/shared.ts`'s `dynamicSpreadSourceTypeOf`). The keys exist only at
|
|
545
|
+
* runtime, so each own enumerable string key is read as a `gea::Value` and
|
|
546
|
+
* stored through the dictionary's checked value conversion -- the same walk
|
|
547
|
+
* `Object.assign` of a dynamic source into a typed dictionary uses
|
|
548
|
+
* (`host/emit-host-object.ts`). `null`/`undefined` copy nothing.
|
|
549
|
+
*/
|
|
550
|
+
const emitDynamicSpreadIntoDictionary = (ctx, lines, source, sourceText, receiver, receiverRef) => {
|
|
551
|
+
const converted = alignedValueText(ctx, 'emit-allocation.ts:dynamic-spread-into-dictionary', source, receiver.value, '__gea_spread_value');
|
|
552
|
+
if (converted === null) {
|
|
553
|
+
throw createCppEmitBlockedError(`conversion:${representationKey(source)}->${representationKey(receiver.value)}`, `copies a dynamic object-spread source into a dictionary of "${representationKey(receiver.value)}" values; ` +
|
|
554
|
+
'no installed conversion unboxes a dynamic value into that type');
|
|
555
|
+
}
|
|
556
|
+
lines.push('{');
|
|
557
|
+
lines.push(`const auto& __gea_spread_source = ${sourceText};`);
|
|
558
|
+
lines.push('if (__gea_spread_source.tag() != gea::Value::Tag::Null && __gea_spread_source.tag() != gea::Value::Tag::Undefined) {');
|
|
559
|
+
lines.push('for (const std::string& __gea_spread_key : __gea_spread_source.ownEnumerableStringKeys()) {');
|
|
560
|
+
lines.push('const gea::Value __gea_spread_value = __gea_spread_source.getProperty(gea::PropertyKey::string(__gea_spread_key));');
|
|
561
|
+
lines.push(`${receiverRef}[__gea_spread_key] = ${converted};`);
|
|
562
|
+
lines.push('}');
|
|
563
|
+
lines.push('}');
|
|
564
|
+
lines.push('}');
|
|
470
565
|
};
|
|
471
|
-
|
|
566
|
+
/**
|
|
567
|
+
* The keys a statically fielded source may contribute: its TYPE's own keys
|
|
568
|
+
* when the operation states them (`SpreadCopyOperation.keys`), since the
|
|
569
|
+
* carrier can hold defaulted fields the object does not have. `null` when the
|
|
570
|
+
* carrier's own field list is the key set.
|
|
571
|
+
*/
|
|
572
|
+
const spreadKeysOf = (operation) => operation.keys === undefined ? null : new Set(operation.keys);
|
|
573
|
+
const emitSpreadSourceCopy = (ctx, lines, source, sourceText, receiver, receiverRef, keys) => {
|
|
472
574
|
// `null`/`undefined` copy nothing (`CopyDataProperties`'s own definition),
|
|
473
575
|
// so the absent branch is simply empty rather than a converted "empty
|
|
474
576
|
// dictionary" write -- there is no receiver mutation to make at all.
|
|
475
577
|
if (source.kind === 'optional') {
|
|
476
578
|
lines.push(`if (${sourceText}.has_value()) {`);
|
|
477
|
-
emitSpreadSourceCopy(ctx, lines, source.payload, `(*${sourceText})`, receiver, receiverRef);
|
|
579
|
+
emitSpreadSourceCopy(ctx, lines, source.payload, `(*${sourceText})`, receiver, receiverRef, keys);
|
|
478
580
|
lines.push('}');
|
|
479
581
|
return;
|
|
480
582
|
}
|
|
481
583
|
if (source.kind !== 'tagged-union') {
|
|
482
|
-
emitSpreadArmCopy(ctx, lines, source, sourceText, receiver, receiverRef);
|
|
584
|
+
emitSpreadArmCopy(ctx, lines, source, sourceText, receiver, receiverRef, keys);
|
|
483
585
|
return;
|
|
484
586
|
}
|
|
485
587
|
const arms = source.arms;
|
|
@@ -487,7 +589,7 @@ const emitSpreadSourceCopy = (ctx, lines, source, sourceText, receiver, receiver
|
|
|
487
589
|
throw createCppEmitBlockedError('runtime-helper:protocol:spread:next:tagged-union(no-arms)', 'reads a runtime object-spread source carried as a tagged union with no arms');
|
|
488
590
|
}
|
|
489
591
|
if (arms.length === 1) {
|
|
490
|
-
emitSpreadArmCopy(ctx, lines, arms[0].value, armAt(sourceText, 0), receiver, receiverRef);
|
|
592
|
+
emitSpreadArmCopy(ctx, lines, arms[0].value, armAt(sourceText, 0), receiver, receiverRef, keys);
|
|
491
593
|
return;
|
|
492
594
|
}
|
|
493
595
|
// Exactly one arm is live at runtime (`gea::TaggedUnion`'s own invariant),
|
|
@@ -497,11 +599,11 @@ const emitSpreadSourceCopy = (ctx, lines, source, sourceText, receiver, receiver
|
|
|
497
599
|
arms.forEach((arm, index) => {
|
|
498
600
|
const isLast = index === arms.length - 1;
|
|
499
601
|
lines.push(index === 0 ? `if (${armIs(sourceText, index)}) {` : isLast ? '} else {' : `} else if (${armIs(sourceText, index)}) {`);
|
|
500
|
-
emitSpreadArmCopy(ctx, lines, arm.value, armAt(sourceText, index), receiver, receiverRef);
|
|
602
|
+
emitSpreadArmCopy(ctx, lines, arm.value, armAt(sourceText, index), receiver, receiverRef, keys);
|
|
501
603
|
});
|
|
502
604
|
lines.push('}');
|
|
503
605
|
};
|
|
504
|
-
const emitSpreadArmCopy = (ctx, lines, arm, armText, receiver, receiverRef) => {
|
|
606
|
+
const emitSpreadArmCopy = (ctx, lines, arm, armText, receiver, receiverRef, keys) => {
|
|
505
607
|
if (arm.kind === 'dictionary') {
|
|
506
608
|
emitSpreadDictionaryArmCopy(ctx, lines, arm, armText, receiver, receiverRef);
|
|
507
609
|
return;
|
|
@@ -515,9 +617,63 @@ const emitSpreadArmCopy = (ctx, lines, arm, armText, receiver, receiverRef) => {
|
|
|
515
617
|
// admitting this source consulted -- reading a different list here than the
|
|
516
618
|
// one that licensed the render is the certify-then-crash that key exists to
|
|
517
619
|
// prevent.
|
|
620
|
+
// An indexed record (a named interface with an index signature): its
|
|
621
|
+
// declared fields unroll like a record's, then its string sidecar's
|
|
622
|
+
// enumerable entries copy like a dictionary's.
|
|
623
|
+
const indexed = isCopyableIndexedRecordIntoDictionary(ctx.deriver, arm, receiver) ? indexedRecordViewOf(ctx.deriver, arm) : null;
|
|
624
|
+
if (indexed !== null) {
|
|
625
|
+
const member = `${armText}${memberAccessOperator(indexed.ownership)}`;
|
|
626
|
+
const ordered = creationOrderedCopyOpening(indexed.ownership, armText, null, (key, value) => {
|
|
627
|
+
const converted = alignedValueText(ctx, 'emit-allocation.ts:indexed-record-spread', dynamicSpreadValue, receiver.value, value);
|
|
628
|
+
return converted === null ? null : `${receiverRef}[${key}] = ${converted};`;
|
|
629
|
+
});
|
|
630
|
+
if (ordered !== null)
|
|
631
|
+
lines.push(ordered);
|
|
632
|
+
emitSpreadFieldCopy(ctx, lines, indexed.fields, member, receiver, receiverRef);
|
|
633
|
+
const serial = lines.length;
|
|
634
|
+
for (const index of indexed.indexes) {
|
|
635
|
+
const table = `${member}${cppRecordIndexSidecarNameFor(index, indexed.indexes)}`;
|
|
636
|
+
const attributes = `${member}${cppRecordIndexAttributesNameFor(index, indexed.indexes)}`;
|
|
637
|
+
const entry = `__gea_spread_entry_${serial}`;
|
|
638
|
+
const value = representationKey(index.value) === representationKey(receiver.value)
|
|
639
|
+
? `${entry}.second`
|
|
640
|
+
: alignedValueText(ctx, 'emit-allocation.ts:indexed-record-spread', index.value, receiver.value, `${entry}.second`);
|
|
641
|
+
if (value === null) {
|
|
642
|
+
throw createCppEmitBlockedError(`conversion:${representationKey(index.value)}->${representationKey(receiver.value)}`, `copies an index-signature entry carried as "${representationKey(index.value)}" into a receiver whose value is carried as ` +
|
|
643
|
+
`"${representationKey(receiver.value)}"; no conversion between those is licensed`);
|
|
644
|
+
}
|
|
645
|
+
lines.push(`for (const auto& ${entry} : ${table}) {`);
|
|
646
|
+
lines.push(`if (!${attributes}.attributes(${entry}.first).enumerable) continue;`);
|
|
647
|
+
lines.push(`${receiverRef}[${entry}.first] = ${value};`);
|
|
648
|
+
lines.push('}');
|
|
649
|
+
}
|
|
650
|
+
if (ordered !== null)
|
|
651
|
+
lines.push('}');
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
518
654
|
const fields = staticOwnFieldsOf(ctx.deriver, arm);
|
|
519
|
-
if (fields !== null
|
|
520
|
-
|
|
655
|
+
if (fields !== null) {
|
|
656
|
+
const copied = keys === null ? fields : fields.filter((field) => keys.has(field.key));
|
|
657
|
+
// A key outside the layout (an expando) is an own property too; the
|
|
658
|
+
// runtime walk copies it, in creation order, where the layout is the
|
|
659
|
+
// whole key set the static copy would take.
|
|
660
|
+
const ordered = receiver.key === 'string' && copied.length === fields.length
|
|
661
|
+
? creationOrderedCopyOpening(ownershipOfSpreadArm(arm), armText, null, (key, value) => {
|
|
662
|
+
const converted = alignedValueText(ctx, 'emit-allocation.ts:record-spread-in-creation-order', dynamicSpreadValue, receiver.value, value);
|
|
663
|
+
return converted === null ? null : `${receiverRef}[${key}] = ${converted};`;
|
|
664
|
+
})
|
|
665
|
+
: null;
|
|
666
|
+
// A literal's own accessor has no struct member for the static copy to
|
|
667
|
+
// read; only the runtime walk reaches it, through [[Get]].
|
|
668
|
+
if (ordered === null && arm.kind === 'record' && arm.accessors.length > 0) {
|
|
669
|
+
throw createCppEmitBlockedError('runtime-helper:protocol:spread:next:record(accessors-without-walk)', 'a spread of an object literal with accessors copies them only through the runtime creation-order walk, ' +
|
|
670
|
+
'and this source/receiver pair has none; a static copy would drop the accessor keys');
|
|
671
|
+
}
|
|
672
|
+
if (ordered !== null)
|
|
673
|
+
lines.push(ordered);
|
|
674
|
+
emitSpreadFieldCopy(ctx, lines, copied, `${armText}${memberAccessOperator(ownershipOfSpreadArm(arm))}`, receiver, receiverRef);
|
|
675
|
+
if (ordered !== null)
|
|
676
|
+
lines.push('}');
|
|
521
677
|
return;
|
|
522
678
|
}
|
|
523
679
|
throw createCppEmitBlockedError(`runtime-helper:protocol:spread:next:${spreadSourceCarrierKeyOf(arm.kind, arm, receiver, ctx.deriver)}`, `reads a runtime object-spread source carried as "${arm.kind}", but this emitter only copies a source whose own key set a static ` +
|
|
@@ -560,8 +716,7 @@ const emitSpreadFieldCopy = (ctx, lines, fields, armMember, receiver, receiverRe
|
|
|
560
716
|
throw createCppEmitBlockedError('runtime-helper:protocol:spread:next:record(unprovable-presence)', `copies a record source field "${field.key}" whose presence is unprovable beside "${representationKey(field.value)}"; this ` +
|
|
561
717
|
'emitter copies a required field or an optional generated field with an independent presence bit');
|
|
562
718
|
}
|
|
563
|
-
const
|
|
564
|
-
const readText = fieldText;
|
|
719
|
+
const readText = tailAwareFieldReadText(fields, field.key, armMember);
|
|
565
720
|
const converted = alignedValueText(ctx, 'emit-allocation.ts:704', field.value, receiver.value, readText);
|
|
566
721
|
if (converted === null) {
|
|
567
722
|
throw createCppEmitBlockedError(`conversion:${representationKey(field.value)}->${representationKey(receiver.value)}`, `copies a record source field "${field.key}" carried as "${representationKey(field.value)}" into a receiver whose value is carried as ` +
|
|
@@ -571,3 +726,395 @@ const emitSpreadFieldCopy = (ctx, lines, fields, armMember, receiver, receiverRe
|
|
|
571
726
|
lines.push(field.required ? write : `if (${armMember}${cppRecordFieldPresenceName(field.key)}) { ${write} }`);
|
|
572
727
|
}
|
|
573
728
|
};
|
|
729
|
+
/**
|
|
730
|
+
* `CopyDataProperties` into an object literal whose own type carries a string
|
|
731
|
+
* index signature (mongodb's `{ ...result.writeConcernError, ...result }`).
|
|
732
|
+
* The literal is a `record-with-index`: each copied key lands in the declared
|
|
733
|
+
* field of that name when the receiver has one and in the string sidecar
|
|
734
|
+
* otherwise -- the same split `recordIndexSidecarTableOf` draws for a single
|
|
735
|
+
* store. A statically named source key is routed at compile time; a key read
|
|
736
|
+
* off a source's own sidecar or dictionary at run time is compared against the
|
|
737
|
+
* receiver's declared names first. The admission is
|
|
738
|
+
* `carrier-keys.ts`'s `record-with-index<-copyable`, asked of the same pair.
|
|
739
|
+
*/
|
|
740
|
+
const emitSpreadIntoIndexedRecord = (ctx, lines, operation) => {
|
|
741
|
+
const source = operation.source.representation;
|
|
742
|
+
const receiverRepresentation = operation.receiver.representation;
|
|
743
|
+
const target = spreadIndexedRecordReceiverOf(ctx.deriver, receiverRepresentation);
|
|
744
|
+
if (target === null ||
|
|
745
|
+
spreadSourceCarrierKeyOf(source.kind, source, receiverRepresentation, ctx.deriver) !== 'indexed-record<-copyable') {
|
|
746
|
+
throw createCppEmitBlockedError(`runtime-helper:protocol:spread:next:${spreadSourceCarrierKeyOf(source.kind, source, receiverRepresentation, ctx.deriver)}`, `copies a "${representationKey(source)}" source into an indexed-record receiver, which takes only string keys from a copyable source`);
|
|
747
|
+
}
|
|
748
|
+
const { view: receiver, index } = target;
|
|
749
|
+
emitSpreadIntoFields(ctx, lines, source, operandText(ctx, operation.source), operandText(ctx, operation.receiver), cppTypeOf(receiverRepresentation), receiver, { member: cppRecordIndexSidecarNameFor(index, receiver.indexes), value: index.value }, spreadKeysOf(operation), operation.later ?? [], new Set(operation.overwritten ?? []));
|
|
750
|
+
};
|
|
751
|
+
/**
|
|
752
|
+
* `CopyDataProperties` into an object literal whose own type names its keys
|
|
753
|
+
* and has no index signature (`spreadFieldRecordReceiverOf`): the MongoDB
|
|
754
|
+
* driver's `buildOptions` returns `{ ...this.options, ...this.bsonOptions,
|
|
755
|
+
* timeoutContext }`, whose sources carry optional members and an optional
|
|
756
|
+
* whole. Each key the source HAS lands in the receiver's field of that name,
|
|
757
|
+
* with its presence bit; a key the literal's type does not name lands on the
|
|
758
|
+
* receiver's expando, since it is still an own property of the copy.
|
|
759
|
+
*/
|
|
760
|
+
const emitSpreadIntoFieldRecord = (ctx, lines, operation) => {
|
|
761
|
+
const source = operation.source.representation;
|
|
762
|
+
const receiverRepresentation = operation.receiver.representation;
|
|
763
|
+
const receiver = spreadFieldRecordReceiverOf(ctx.deriver, receiverRepresentation);
|
|
764
|
+
const carrier = spreadSourceCarrierKeyOf(source.kind, source, receiverRepresentation, ctx.deriver);
|
|
765
|
+
if (receiver === null || (carrier !== 'field-record<-copyable' && carrier !== 'field-record<-dynamic')) {
|
|
766
|
+
throw createCppEmitBlockedError(`runtime-helper:protocol:spread:next:${carrier}`, `copies a "${representationKey(source)}" source into a field-record receiver, which takes only a source whose keys a static field list reproduces`);
|
|
767
|
+
}
|
|
768
|
+
emitSpreadIntoFields(ctx, lines, source, operandText(ctx, operation.source), operandText(ctx, operation.receiver), cppTypeOf(receiverRepresentation), receiver, null, spreadKeysOf(operation), operation.later ?? [], new Set(operation.overwritten ?? []), keyOrderUnobservedIn(ctx, receiverRepresentation));
|
|
769
|
+
};
|
|
770
|
+
/**
|
|
771
|
+
* The copy both field-bearing receivers share: a statically named key lands
|
|
772
|
+
* in the receiver's declared field of that name, and otherwise in the string
|
|
773
|
+
* sidecar when the receiver has one -- or its expando, when it has none.
|
|
774
|
+
*/
|
|
775
|
+
const emitSpreadIntoFields = (ctx, lines, source, sourceText, receiverText, receiverType, receiver, sidecar, keys, later, overwritten,
|
|
776
|
+
// The receiver's key creation order is read by nothing (`ir/key-order-observation.ts`): the copy keeps none.
|
|
777
|
+
orderless = false) => {
|
|
778
|
+
const accessor = memberAccessOperator(receiver.ownership);
|
|
779
|
+
const converted = (from, to, text, what) => {
|
|
780
|
+
if (representationKey(from) === representationKey(to))
|
|
781
|
+
return text;
|
|
782
|
+
const aligned = alignedValueText(ctx, 'emit-allocation.ts:spread-indexed-record', from, to, text);
|
|
783
|
+
if (aligned === null) {
|
|
784
|
+
throw createCppEmitBlockedError(`conversion:${representationKey(from)}->${representationKey(to)}`, `copies ${what} carried as "${representationKey(from)}" into a receiver slot carried as "${representationKey(to)}"; no conversion between those is licensed`);
|
|
785
|
+
}
|
|
786
|
+
return aligned;
|
|
787
|
+
};
|
|
788
|
+
// Every store names the receiver, so each writer takes it: the walk's
|
|
789
|
+
// run-time key routing is rendered over a unit function's formal as well as
|
|
790
|
+
// over the site's own receiver (`keyedWriteText`).
|
|
791
|
+
const fieldWrite = (target, field, value, text) => {
|
|
792
|
+
const store = `${target}${accessor}${tailAwareFieldWriteText(receiver.fields, field.key)} = ${converted(value, field.value, text, `the key "${field.key}"`)};`;
|
|
793
|
+
return field.required ? store : `${store} ${target}${accessor}${cppRecordFieldPresenceName(field.key)} = true;`;
|
|
794
|
+
};
|
|
795
|
+
// With no index sidecar, a key the layout does not declare is still an own
|
|
796
|
+
// property of the copy: it lands on the receiver's expando, the sidecar
|
|
797
|
+
// every shared record has, rather than nowhere.
|
|
798
|
+
const expando = receiver.ownership === 'shared-refcount';
|
|
799
|
+
const sidecarWrite = (target, key, value, text) => sidecar !== null
|
|
800
|
+
? `${target}${accessor}${sidecar.member}[${key}] = ${converted(value, sidecar.value, text, 'an index-signature entry')};`
|
|
801
|
+
: expando
|
|
802
|
+
? `gea::nativeSpreadExpandoSet(${target}, ${key}, ${converted(value, dynamicSpreadValue, text, 'a key the receiver does not declare')});`
|
|
803
|
+
: null;
|
|
804
|
+
// Keys the static copy decided NOT to store, because a later member of the
|
|
805
|
+
// literal overwrites them: the creation-order walk, which routes run-time
|
|
806
|
+
// keys by name, drops the same stores.
|
|
807
|
+
const overwrittenInWalk = new Set();
|
|
808
|
+
// A key the copy skips because a later member overwrites it is still
|
|
809
|
+
// created BY the copy, at the copy's place, when the source holds it: the
|
|
810
|
+
// presence bit is raised here so the later member's store is an overwrite,
|
|
811
|
+
// not a creation (`declaredFieldCreationText`).
|
|
812
|
+
const createdBySkip = (target, name) => {
|
|
813
|
+
const field = receiver.fields.find((candidate) => candidate.key === name);
|
|
814
|
+
return field === undefined || field.required ? '' : `${target}${accessor}${cppRecordFieldPresenceName(name)} = true;`;
|
|
815
|
+
};
|
|
816
|
+
const staticWrite = (target, key, value, text) => {
|
|
817
|
+
const field = receiver.fields.find((candidate) => candidate.key === key);
|
|
818
|
+
if (field)
|
|
819
|
+
return fieldWrite(target, field, value, text);
|
|
820
|
+
// The static fallback owes the same excess keys as the runtime walk.
|
|
821
|
+
// Shared records keep these in their expando even without an index signature.
|
|
822
|
+
return sidecarWrite(target, cppStringLiteral(key), value, text);
|
|
823
|
+
};
|
|
824
|
+
// A run-time key is one of the receiver's declared names or an index entry.
|
|
825
|
+
const dynamicWrite = (target, key, value, text, skipping = true) => {
|
|
826
|
+
const fields = receiver.fields.filter((field) => !field.key.startsWith('sym('));
|
|
827
|
+
const skipped = !skipping
|
|
828
|
+
? []
|
|
829
|
+
: [...overwrittenInWalk].map((name) => `if (${key} == ${cppStringLiteral(name)}) { ${createdBySkip(target, name)} }`);
|
|
830
|
+
const branches = [
|
|
831
|
+
...skipped,
|
|
832
|
+
...fields.map((field) => `if (${key} == ${cppStringLiteral(field.key)}) { ${fieldWrite(target, field, value, text)} }`)
|
|
833
|
+
];
|
|
834
|
+
const rest = sidecarWrite(target, key, value, text);
|
|
835
|
+
return [...branches, ...(rest === null ? [] : [`{ ${rest} }`])].join(' else ');
|
|
836
|
+
};
|
|
837
|
+
// The routing above is a branch per declared field -- 131 of them into
|
|
838
|
+
// mongodb's options family -- and depends on nothing at the site but the
|
|
839
|
+
// receiver, the key and the value. Into a shared receiver it is defined once
|
|
840
|
+
// per receiver carrier and value carrier, and each walk calls it
|
|
841
|
+
// (`unitFunctionName`); the struct it stores into is the site's. The keys a
|
|
842
|
+
// later member overwrites are the site's own, so they are skipped before
|
|
843
|
+
// the call rather than inside it, where they would mint a copy per literal.
|
|
844
|
+
const keyedWriteText = (key, value, text) => {
|
|
845
|
+
if (receiver.ownership !== 'shared-refcount')
|
|
846
|
+
return dynamicWrite(receiverText, key, value, text);
|
|
847
|
+
const body = dynamicWrite('gea_spread_target', 'gea_spread_key', value, 'gea_spread_value', false);
|
|
848
|
+
const named = unitFunctionName('gea_spread_key_into', (name) => `void ${name}(const ${receiverType}& gea_spread_target, const std::string& gea_spread_key, const ${cppTypeOf(value)}& gea_spread_value)`, body);
|
|
849
|
+
if (named === null)
|
|
850
|
+
return dynamicWrite(receiverText, key, value, text);
|
|
851
|
+
const call = `${named}(${receiverText}, ${key}, ${text});`;
|
|
852
|
+
if (overwrittenInWalk.size === 0)
|
|
853
|
+
return call;
|
|
854
|
+
const marks = [...overwrittenInWalk].map((name) => `if (${key} == ${cppStringLiteral(name)}) { ${createdBySkip(receiverText, name)} }`);
|
|
855
|
+
return `${marks.join(' else ')} else ${call}`;
|
|
856
|
+
};
|
|
857
|
+
const copy = (from, text) => {
|
|
858
|
+
if (from.kind === 'optional') {
|
|
859
|
+
lines.push(`if (${text}.has_value()) {`);
|
|
860
|
+
copy(from.payload, `(*${text})`);
|
|
861
|
+
lines.push('}');
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
if (from.kind === 'tagged-union') {
|
|
865
|
+
from.arms.forEach((arm, armIndex) => {
|
|
866
|
+
const isLast = armIndex === from.arms.length - 1;
|
|
867
|
+
if (from.arms.length > 1) {
|
|
868
|
+
lines.push(armIndex === 0 ? `if (${armIs(text, armIndex)}) {` : isLast ? '} else {' : `} else if (${armIs(text, armIndex)}) {`);
|
|
869
|
+
}
|
|
870
|
+
copy(arm.value, armAt(text, armIndex));
|
|
871
|
+
});
|
|
872
|
+
if (from.arms.length > 1)
|
|
873
|
+
lines.push('}');
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
const serial = lines.length;
|
|
877
|
+
// A key the receiver's layout does not declare lands in its sidecar and
|
|
878
|
+
// would enumerate after every declared field; the receiver learns the
|
|
879
|
+
// copy's order instead (`gea::detail::learnCopiedOwnKeys`).
|
|
880
|
+
const copied = receiver.ownership === 'shared-refcount' && !orderless ? `__gea_spread_copied_${serial}` : null;
|
|
881
|
+
const noteCopied = (key) => (copied === null ? '' : ` ${copied}.push_back(gea::PropertyKey::string(${key}));`);
|
|
882
|
+
const openCopied = () => {
|
|
883
|
+
if (copied !== null)
|
|
884
|
+
lines.push(`{ std::vector<gea::PropertyKey> ${copied};`);
|
|
885
|
+
};
|
|
886
|
+
const closeCopied = () => {
|
|
887
|
+
if (copied !== null)
|
|
888
|
+
lines.push(`gea::detail::learnCopiedOwnKeys(${receiverText}, ${copied}${laterArgument(later, ', false')}); }`);
|
|
889
|
+
};
|
|
890
|
+
// A dynamic source is `CopyDataProperties` itself, the `dynamic->dynamic`
|
|
891
|
+
// walk's sequence: `null`/`undefined` copy nothing, and each own
|
|
892
|
+
// enumerable string key is read once -- a getter runs, in key order,
|
|
893
|
+
// whether or not the literal names it -- and routed by name. Symbol keys
|
|
894
|
+
// are skipped only because the admission refused every receiver with a
|
|
895
|
+
// symbol-named field.
|
|
896
|
+
if (from.kind === 'dynamic') {
|
|
897
|
+
const source = `__gea_spread_source_${serial}`;
|
|
898
|
+
const key = `__gea_spread_key_${serial}`;
|
|
899
|
+
const descriptor = `__gea_spread_descriptor_${serial}`;
|
|
900
|
+
openCopied();
|
|
901
|
+
lines.push('{');
|
|
902
|
+
lines.push(`const auto& ${source} = ${text};`);
|
|
903
|
+
lines.push(`if (${source}.tag() != gea::Value::Tag::Null && ${source}.tag() != gea::Value::Tag::Undefined) {`);
|
|
904
|
+
lines.push(`for (const gea::PropertyKey& ${key} : ${source}.ownPropertyKeys()) {`);
|
|
905
|
+
lines.push(`if (${key}.isSymbol()) continue;`);
|
|
906
|
+
lines.push(`gea::PropertyDescriptor ${descriptor};`);
|
|
907
|
+
lines.push(`if (!${source}.ownDescriptor(${key}, ${descriptor}) || !${descriptor}.enumerable) continue;`);
|
|
908
|
+
lines.push(`const auto __gea_spread_value_${serial} = ${source}.getProperty(${key});`);
|
|
909
|
+
lines.push(keyedWriteText(`${key}.text()`, from, `__gea_spread_value_${serial}`) + noteCopied(`${key}.text()`));
|
|
910
|
+
lines.push('}');
|
|
911
|
+
lines.push('}');
|
|
912
|
+
lines.push('}');
|
|
913
|
+
closeCopied();
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
const member = `${text}${memberAccessOperator(ownershipOfSpreadSource(from))}`;
|
|
917
|
+
if (from.kind === 'dictionary') {
|
|
918
|
+
openCopied();
|
|
919
|
+
lines.push(`for (const std::string& __gea_spread_key_${serial} : ${member}enumerableKeys()) {`);
|
|
920
|
+
lines.push(keyedWriteText(`__gea_spread_key_${serial}`, from.value, `${member}read(__gea_spread_key_${serial})`) +
|
|
921
|
+
noteCopied(`__gea_spread_key_${serial}`));
|
|
922
|
+
lines.push('}');
|
|
923
|
+
closeCopied();
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
// A shared class reference also carries `null` -- `T | null` folds onto
|
|
927
|
+
// the bare `Ref` (`representation/optional.ts`) -- and CopyDataProperties
|
|
928
|
+
// copies nothing from it. mongodb's `{ ...options.readPreference, ...value }`
|
|
929
|
+
// reads a field `parseOptions` has not filled yet, and every member read
|
|
930
|
+
// below dereferenced the empty handle.
|
|
931
|
+
const nullable = from.kind === 'class-ref' && from.ownership === 'shared-refcount';
|
|
932
|
+
if (nullable)
|
|
933
|
+
lines.push(`if (${text}) {`);
|
|
934
|
+
const view = indexedRecordViewOf(ctx.deriver, from);
|
|
935
|
+
const fields = view !== null ? view.fields : staticOwnFieldsOf(ctx.deriver, from);
|
|
936
|
+
// The walk copies every own key the source has; it stands in for the
|
|
937
|
+
// static copy only where that copy's key set is the source's whole layout
|
|
938
|
+
// -- a layout wider than the type's keys holds fields the value lacks.
|
|
939
|
+
const walkable = fields !== null && (keys === null || fields.every((field) => keys.has(field.key)));
|
|
940
|
+
// The static copy is decided first: its routing is what the walk follows.
|
|
941
|
+
// It is also spelled over a unit function's formals (`outlinedLines`), for
|
|
942
|
+
// the out-of-line copy below.
|
|
943
|
+
const staticLines = [];
|
|
944
|
+
const outlinedLines = [];
|
|
945
|
+
const outlinedMember = `gea_spread_source${memberAccessOperator(ownershipOfSpreadSource(from))}`;
|
|
946
|
+
// The SOURCE's own field list -- `tailAwareFieldReadText` needs it to
|
|
947
|
+
// decide whether reading `field.key` off the source goes through that
|
|
948
|
+
// source's own tail block, independent of whether the RECEIVER
|
|
949
|
+
// (`fieldWrite`, above) placed the same-named field inline or in a tail
|
|
950
|
+
// of its own. This is always a READ of the source: presence-gated below
|
|
951
|
+
// for an optional field, but `peek()`-based regardless, so a source whose
|
|
952
|
+
// tail was never allocated stays that way even for the required-field
|
|
953
|
+
// (unconditional) branch.
|
|
954
|
+
const sourceFields = fields ?? [];
|
|
955
|
+
const skipMarks = [];
|
|
956
|
+
// The outlined line of each source field by layout position (null: no store).
|
|
957
|
+
const outlinedByPosition = [];
|
|
958
|
+
for (const field of sourceFields) {
|
|
959
|
+
outlinedByPosition.push(null);
|
|
960
|
+
if (keys !== null && !keys.has(field.key))
|
|
961
|
+
continue;
|
|
962
|
+
// A later member of the literal writes this key unconditionally, so the
|
|
963
|
+
// copied value is dead -- and a source carrying it in a shape the
|
|
964
|
+
// literal's slot does not take (mongodb's `{ ...pluckBSONSerializeOptions(
|
|
965
|
+
// options), validation: parseUtf8ValidationOption(options) }`) must not
|
|
966
|
+
// refuse a store nothing can observe. A struct read has no getter to
|
|
967
|
+
// run; the walk still [[Get]]s it, and only drops the store.
|
|
968
|
+
if (overwritten.has(field.key)) {
|
|
969
|
+
overwrittenInWalk.add(field.key);
|
|
970
|
+
const mark = createdBySkip(receiverText, field.key);
|
|
971
|
+
if (mark !== '')
|
|
972
|
+
skipMarks.push(field.required ? mark : `if (${member}${cppRecordFieldPresenceName(field.key)}) ${mark}`);
|
|
973
|
+
continue;
|
|
974
|
+
}
|
|
975
|
+
const write = staticWrite(receiverText, field.key, field.value, tailAwareFieldReadText(sourceFields, field.key, member));
|
|
976
|
+
if (write === null)
|
|
977
|
+
throw createCppEmitBlockedError('runtime-helper:protocol:spread:next:unrepresented-own-key', `a spread cannot preserve the source's own key "${field.key}" in a receiver with no field or sidecar for it`);
|
|
978
|
+
staticLines.push(field.required ? write : `if (${member}${cppRecordFieldPresenceName(field.key)}) { ${write} }`);
|
|
979
|
+
const outlined = staticWrite('gea_spread_target', field.key, field.value, tailAwareFieldReadText(sourceFields, field.key, outlinedMember));
|
|
980
|
+
if (outlined !== null) {
|
|
981
|
+
const line = field.required ? outlined : `if (${outlinedMember}${cppRecordFieldPresenceName(field.key)}) { ${outlined} }`;
|
|
982
|
+
outlinedLines.push(line);
|
|
983
|
+
outlinedByPosition[outlinedByPosition.length - 1] = line;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
// A wide layout's copy is a guarded store per field -- 134 into mongodb's
|
|
987
|
+
// options family, at 55 spread sites -- and depends on nothing at the site
|
|
988
|
+
// but the two records. Between shared records it is defined once per
|
|
989
|
+
// source and receiver carrier and each site calls it (`unitFunctionName`),
|
|
990
|
+
// as the walk's key routing already is: the same stores, one copy of the
|
|
991
|
+
// code instead of one per site in the instruction cache.
|
|
992
|
+
const outlinedCall = receiver.ownership === 'shared-refcount' &&
|
|
993
|
+
ownershipOfSpreadSource(from) === 'shared-refcount' &&
|
|
994
|
+
staticLines.length >= outlinedCopyMinimumFields &&
|
|
995
|
+
outlinedLines.length === staticLines.length
|
|
996
|
+
? unitFunctionName('gea_spread_fields_into', (name) => `void ${name}(const ${receiverType}& gea_spread_target, const ${cppTypeOf(from)}& gea_spread_source)`, presenceSkippingBody(outlinedByPosition, sourceFields, (from.kind === 'record' || (from.kind === 'native-record-ref' && from.native === null)) &&
|
|
997
|
+
layoutOrderAgrees(ctx.layouts.forShape(from.shapeId), sourceFields), outlinedMember))
|
|
998
|
+
: null;
|
|
999
|
+
if (outlinedCall !== null)
|
|
1000
|
+
staticLines.splice(0, staticLines.length, `${outlinedCall}(${receiverText}, ${text});`);
|
|
1001
|
+
// A copy into a shared record hands its static copy to the runtime, which
|
|
1002
|
+
// runs it for a source whose keys merely left layout order and walks only
|
|
1003
|
+
// what the static copy cannot see (`copyOwnPropertiesInCreationOrderWith`).
|
|
1004
|
+
const staticCopy = receiver.ownership === 'shared-refcount' ? `__gea_static_copy_${serial}` : null;
|
|
1005
|
+
const ordered = !walkable
|
|
1006
|
+
? null
|
|
1007
|
+
: creationOrderedCopyOpening(view !== null ? view.ownership : ownershipOfSpreadSource(from), text, receiver.ownership === 'shared-refcount' ? receiverText : null, (key, value) => keyedWriteText(key, dynamicSpreadValue, value), later, staticCopy, orderless);
|
|
1008
|
+
// A literal's own accessor has no struct member for the static copy below
|
|
1009
|
+
// to read; only the runtime walk reaches it, through [[Get]].
|
|
1010
|
+
if (ordered === null && from.kind === 'record' && from.accessors.length > 0) {
|
|
1011
|
+
throw createCppEmitBlockedError('runtime-helper:protocol:spread:next:record(accessors-without-walk)', 'a spread of an object literal with accessors copies them only through the runtime creation-order walk, ' +
|
|
1012
|
+
'and this source/receiver pair has none; a static copy would drop the accessor keys');
|
|
1013
|
+
}
|
|
1014
|
+
const copyLines = [...staticLines, ...skipMarks];
|
|
1015
|
+
const indexes = view?.indexes ?? [];
|
|
1016
|
+
for (const sourceIndex of indexes) {
|
|
1017
|
+
const table = `${member}${cppRecordIndexSidecarNameFor(sourceIndex, indexes)}`;
|
|
1018
|
+
const attributes = `${member}${cppRecordIndexAttributesNameFor(sourceIndex, indexes)}`;
|
|
1019
|
+
copyLines.push(`for (const auto& __gea_spread_entry_${serial} : ${table}) {`);
|
|
1020
|
+
copyLines.push(`if (!${attributes}.attributes(__gea_spread_entry_${serial}.first).enumerable) continue;`);
|
|
1021
|
+
copyLines.push(keyedWriteText(`__gea_spread_entry_${serial}.first`, sourceIndex.value, `__gea_spread_entry_${serial}.second`));
|
|
1022
|
+
copyLines.push('}');
|
|
1023
|
+
}
|
|
1024
|
+
if (ordered !== null && staticCopy !== null) {
|
|
1025
|
+
lines.push(`{ const auto ${staticCopy} = [&]() {`, ...copyLines, '};', ordered, '}');
|
|
1026
|
+
}
|
|
1027
|
+
else {
|
|
1028
|
+
if (ordered !== null)
|
|
1029
|
+
lines.push(ordered);
|
|
1030
|
+
lines.push(...copyLines);
|
|
1031
|
+
if (ordered !== null)
|
|
1032
|
+
lines.push('}');
|
|
1033
|
+
}
|
|
1034
|
+
if (nullable)
|
|
1035
|
+
lines.push('}');
|
|
1036
|
+
};
|
|
1037
|
+
copy(source, sourceText);
|
|
1038
|
+
};
|
|
1039
|
+
/** The presence bits are declared in the struct's layout order: a run is only a run when the list agrees with it. */
|
|
1040
|
+
const layoutOrderAgrees = (layout, fields) => layout !== null && layout.length === fields.length && layout.every((field, index) => field.key === fields[index].key);
|
|
1041
|
+
/**
|
|
1042
|
+
* A wide record's presence-guarded stores, with each run of eight optional
|
|
1043
|
+
* fields that sit side by side in the layout skipped by ONE word test of their
|
|
1044
|
+
* presence bits. `records.ts` declares a bit per field in layout order and
|
|
1045
|
+
* gives an optional field a real, never-static one, so eight consecutive
|
|
1046
|
+
* optional fields own eight consecutive bytes; mongodb's options record holds
|
|
1047
|
+
* a handful of its 134 fields, and a flag-by-flag walk tested every one on
|
|
1048
|
+
* every copy (`NativeLayoutInfo::presenceContiguous` is the runtime's twin of
|
|
1049
|
+
* the same fact). A layout position without a store (a key the literal skips)
|
|
1050
|
+
* stays inside its run: its bit may be set, which only enters the run.
|
|
1051
|
+
*/
|
|
1052
|
+
const presenceSkippingBody = (lineByPosition, fields, contiguousBits, member) => {
|
|
1053
|
+
const out = [];
|
|
1054
|
+
let position = 0;
|
|
1055
|
+
while (position < fields.length) {
|
|
1056
|
+
const run = position + 8 <= fields.length && contiguousBits && fields.slice(position, position + 8).every((field) => !field.required);
|
|
1057
|
+
if (!run) {
|
|
1058
|
+
const line = lineByPosition[position];
|
|
1059
|
+
if (line !== null && line !== undefined)
|
|
1060
|
+
out.push(line);
|
|
1061
|
+
position += 1;
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1064
|
+
const lines = lineByPosition.slice(position, position + 8).filter((line) => line !== null && line !== undefined);
|
|
1065
|
+
const first = fields[position];
|
|
1066
|
+
if (lines.length > 0)
|
|
1067
|
+
out.push(`{ std::uint64_t gea_run; std::memcpy(&gea_run, &${member}${cppRecordFieldPresenceName(first.key)}, 8); if (gea_run != 0) { ${lines.join(' ')} } }`);
|
|
1068
|
+
position += 8;
|
|
1069
|
+
}
|
|
1070
|
+
return out.join(' ');
|
|
1071
|
+
};
|
|
1072
|
+
const dynamicSpreadValue = { kind: 'dynamic', reason: 'declared-any-never-narrowed' };
|
|
1073
|
+
/**
|
|
1074
|
+
* Below this many stores a spread's static copy stays at its site: a few
|
|
1075
|
+
* guarded stores cost less than the call, and a narrow copy is no weight in
|
|
1076
|
+
* the instruction cache.
|
|
1077
|
+
*/
|
|
1078
|
+
const outlinedCopyMinimumFields = 16;
|
|
1079
|
+
/**
|
|
1080
|
+
* The opening of a spread out of an indexed record that follows the source's
|
|
1081
|
+
* creation order when it has one, closed by the caller's `}` after its static
|
|
1082
|
+
* copy -- which walks the layout, declared fields before index entries, and
|
|
1083
|
+
* is the source's order only until the source has a key outside its layout
|
|
1084
|
+
* (`gea::copyOwnPropertiesInCreationOrder`). `write` stores one key and its
|
|
1085
|
+
* property value; null when it cannot, and then only the static copy runs.
|
|
1086
|
+
* With `receiver`, the record being built learns the copied keys' order too.
|
|
1087
|
+
*/
|
|
1088
|
+
const creationOrderedCopyOpening = (sourceOwnership, sourceText, receiver, write, later = [], staticCopy = null, orderless = false) => {
|
|
1089
|
+
if (sourceOwnership !== 'shared-refcount')
|
|
1090
|
+
return null;
|
|
1091
|
+
let body;
|
|
1092
|
+
try {
|
|
1093
|
+
body = write('__gea_ordered_key', '__gea_ordered_value');
|
|
1094
|
+
}
|
|
1095
|
+
catch (error) {
|
|
1096
|
+
if (isCppEmitBlockedError(error))
|
|
1097
|
+
return null;
|
|
1098
|
+
throw error;
|
|
1099
|
+
}
|
|
1100
|
+
if (body === null)
|
|
1101
|
+
return null;
|
|
1102
|
+
const receiverArgument = receiver === null || orderless ? '' : `${receiver}, `;
|
|
1103
|
+
// With the static copy named, the call is the whole statement: it runs that
|
|
1104
|
+
// copy itself when it can, and the caller's fallback is the same copy.
|
|
1105
|
+
if (staticCopy !== null && receiver !== null)
|
|
1106
|
+
return (`if (!gea::${orderless ? 'copyOwnPropertiesUnorderedWith' : 'copyOwnPropertiesInCreationOrderWith'}(${sourceText}, ${receiver}, ` +
|
|
1107
|
+
`[&](const std::string& __gea_ordered_key, const gea::Value& __gea_ordered_value) { ${body} }, ${staticCopy}` +
|
|
1108
|
+
`${orderless ? '' : laterArgument(later, '')})) ${staticCopy}();`);
|
|
1109
|
+
return (`if (!gea::copyOwnPropertiesInCreationOrder(${sourceText}, ${receiverArgument}` +
|
|
1110
|
+
`[&](const std::string& __gea_ordered_key, const gea::Value& __gea_ordered_value) { ${body} }` +
|
|
1111
|
+
`${receiver === null || orderless ? '' : laterArgument(later, '')})) {`);
|
|
1112
|
+
};
|
|
1113
|
+
/**
|
|
1114
|
+
* `later` as the trailing `std::initializer_list` argument of the runtime's
|
|
1115
|
+
* copy helpers, after `lead` (the arguments it has to spell before it), or
|
|
1116
|
+
* nothing when the literal writes no key after the spread.
|
|
1117
|
+
*/
|
|
1118
|
+
const laterArgument = (later, lead) => later.length === 0 ? '' : `${lead}, {${later.map(cppStringLiteral).join(', ')}}`;
|
|
1119
|
+
/** A source's ownership, which decides whether its members are reached through `.` or `->`. */
|
|
1120
|
+
const ownershipOfSpreadSource = (source) => source.kind === 'record-with-index' || source.kind === 'dictionary' ? source.ownership : ownershipOfSpreadArm(source);
|