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