@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
package/dist/targets/cpp/emit.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import { objectTagExpression, objectTagCapability } from './emit-object-tag.js';
|
|
2
|
+
import { restrictsEveryCarrier } from '../../ir/integrity-restrictions.js';
|
|
3
|
+
import { emitAllocateProxy, emitProxyArmTest, emitProxyPart, emitProxyTrapCheck } from './emit-proxy.js';
|
|
4
|
+
import { intrinsicAccessorGetterValueText } from './host/emit-host-value.js';
|
|
5
|
+
import { intrinsicAccessorGetterCapability } from '../../ir/certify/runtime-helper.js';
|
|
6
|
+
import { intrinsicAccessorGetterOfOperator } from '../../semantics/model/intrinsic-accessor-getters.js';
|
|
2
7
|
import { stableBorrowActualsOf } from '../../ir/borrowed-call-arguments.js';
|
|
8
|
+
import { borrowedArmProjectionsOf } from './borrowed-arm-projections.js';
|
|
3
9
|
import { owningConversionInputText } from './owning-conversion-input.js';
|
|
4
10
|
import { boxedValueText } from './emit-dynamic-properties.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
11
|
+
import { stableCellReadsOf } from '../../ir/stable-cell-reads.js';
|
|
12
|
+
import { noConstructionOnlyFields, stableFieldReadsOf } from '../../ir/construction-only-fields.js';
|
|
13
|
+
import { DyingArgumentSet, dyingTransferUsesOf, receiverRenamesOf, ownedDyingMergeInputsOf, ownedDyingValuesOf, ownedFormalInputsOf, transfersFormalConversion } from '../../ir/transfer.js';
|
|
14
|
+
import { classLayoutsConstructedBy, constructedBaseOf } from '../../projection/classes.js';
|
|
15
|
+
import { recordFieldsOfShape } from '../../projection/fields.js';
|
|
7
16
|
import { allOperationsOf } from '../../ir/model.js';
|
|
8
|
-
import { resultOfIrOperation } from '../../ir/queries.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
17
|
+
import { operandsOfIrOperation, resultOfIrOperation } from '../../ir/queries.js';
|
|
18
|
+
import { namesMoreThanOnce } from './evaluated-once.js';
|
|
19
|
+
import { isOpenDocument, representationKey } from '../../representation/model.js';
|
|
20
|
+
import { cppFormalName, cppReceiverName, createCppEmitBlockedError, createEmitContext, defineValue, defineValueAlias, directCalleesOf, emptyCaptureIndex, isIntegerStorageValue, isCppEmitBlockedError, operandText, storageTypeOf, cppThunkEntryText, sealFactFieldsForRender, suspendsInPlace } from './emit-context.js';
|
|
11
21
|
import { hostMemberReadsOf } from './host/emit-host-properties.js';
|
|
12
22
|
import { hostNamespaceReadsOf } from './host-namespace-reads.js';
|
|
13
23
|
import { functionSourceReadsOf } from './function-source-reads.js';
|
|
@@ -16,11 +26,13 @@ import { directCallReceiversOf, virtualCalleesOf } from './direct-call-receivers
|
|
|
16
26
|
import { unionMemberTypeofReadsOf, unionMethodReadsOf } from './emit-union-properties.js';
|
|
17
27
|
import { reactiveOriginsOf } from './reactive-origins.js';
|
|
18
28
|
import { renderTryRegion } from './emit-exceptions.js';
|
|
29
|
+
import { declarationScopesOf, gotoTargetsOf, identifiersOf, scopePlanOf } from './emit-scopes.js';
|
|
19
30
|
import { emitReturn } from './emit-return.js';
|
|
20
|
-
import { collectDirectBindingSinks, classObjectReadsOf, hostClassReadsOf, collectFormalCells, earlyCapturedCellPrologue, emitBindingRead, emitBindingWrite } from './emit-bindings.js';
|
|
21
|
-
import { EXACT_ARM_MATERIALIZER } from '../../conversion/nodes.js';
|
|
22
|
-
import { alignedValueText, emitMergeLiveArmRebuild, namedConversionText, widenedStoreText } from './emit-narrowing.js';
|
|
23
|
-
import {
|
|
31
|
+
import { collectDirectBindingSinks, classObjectReadsOf, hostClassReadsOf, collectFormalCells, earlyCapturedCellPrologue, emitBindingRead, emitBindingRenew, emitBindingWrite } from './emit-bindings.js';
|
|
32
|
+
import { ARM_VIEW_MATERIALIZER, ASSERTED_UNION_MATERIALIZER, ASSERTED_UNION_COPY_MATERIALIZER, EXACT_ARM_MATERIALIZER, FAMILY_MEMBER_VIEW_MATERIALIZER, CAUGHT_HANDOFF_MATERIALIZER, NULLISH_OPTIONAL_MATERIALIZER, NATIVE_BASE_VIEW_MATERIALIZER } from '../../conversion/nodes.js';
|
|
33
|
+
import { alignedValueText, unsharedArrayRebuildText, documentViewable, dynamicCarrierBoxText, emitMergeLiveArmRebuild, namedConversionText, movedValueText, widenedStoreText } from './emit-narrowing.js';
|
|
34
|
+
import { collectCharCodeBuffers } from './char-code-buffers.js';
|
|
35
|
+
import { admitDenseWindows, collectCapacityHints, emitAllocateArrayObject, emitDenseSetup, emitFillLoop, isConstantExpression } from './emit-arrays.js';
|
|
24
36
|
import { noInstantiationFacts } from '../../ir/instantiation.js';
|
|
25
37
|
import { observesEveryCallableIdentity } from '../../ir/callable-identity-demand.js';
|
|
26
38
|
import { stringConstantsOf } from '../../ir/dead-values.js';
|
|
@@ -29,7 +41,7 @@ import { emitGetIterator, emitIteratorClose, emitIteratorDone, emitIteratorNext,
|
|
|
29
41
|
import { absenceComparisonText, booleanTestText, definedTestText, presenceTestText } from './emit-presence.js';
|
|
30
42
|
import { callableIdentityEqualityText, constantStringComparisonText, strictEqualityText } from './emit-equality.js';
|
|
31
43
|
import { nativeEqualityText } from './emit-native-equality.js';
|
|
32
|
-
import { denseRemainderCompanion, integerBitwiseOperators, integerBoundedComparison, remainderText } from './emit-integers.js';
|
|
44
|
+
import { denseRemainderCompanion, integerBitwiseOperators, integerBoundedComparison, remainderText, roundingIntegerHelpers } from './emit-integers.js';
|
|
33
45
|
import { instanceofText } from './emit-instanceof.js';
|
|
34
46
|
import { typeofTagLiteral, typeofTagText, typeofText, typeofTextFor, unionMemberTypeofTagText, unionMemberTypeofText } from './emit-typeof.js';
|
|
35
47
|
import { emitHasProperty } from './emit-in.js';
|
|
@@ -41,8 +53,10 @@ import { directClassMethodBody } from './class-properties/emit-class-properties.
|
|
|
41
53
|
import { classMemberOf, lazyCalleeReadsOf, structNameOfReceiver } from './class-layout.js';
|
|
42
54
|
import { emitAllocateRecord, emitAllocateRegExp, emitAllocateTemplateObject, emitToNumericCoercion, emitSpreadCopy } from './emit-allocation.js';
|
|
43
55
|
import { alignedText, receiverBoundCallableText, emitAllocateCallable, emitAllocateConstructor, emitBindCallable, emitCall, emitConstruct, emitSuperInitialize } from './emit-callable.js';
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
56
|
+
import { nativeSumWidenable } from './emit-sum-widening.js';
|
|
57
|
+
import { cppBodyName, cppClassName, cppCommonJsModuleName, cppCommonJsRecordName, cppConstantLiteral, cppStringLiteral, cppTypeOf, cppUndefinedValue } from './types.js';
|
|
58
|
+
import { awaitTickText, awaitedText, coroutineAwaitStatements } from './prototype/emit-prototype-promise.js';
|
|
59
|
+
import { fusedAwaitCallsOf, isAsyncCoroutineBody } from './coroutine-bodies.js';
|
|
46
60
|
import { classTableRootsOf, emitElement, emitElementChild, emitElementProp } from './emit-jsx.js';
|
|
47
61
|
import { emitDeleteOperation, emitUnaryDelete } from './emit-dynamic-properties.js';
|
|
48
62
|
/**
|
|
@@ -245,6 +259,39 @@ const referenceIdentityOperators = new Map([
|
|
|
245
259
|
['==', { kind: 'infix', text: '==' }],
|
|
246
260
|
['!=', { kind: 'infix', text: '!=' }]
|
|
247
261
|
]);
|
|
262
|
+
/**
|
|
263
|
+
* `-`, `*`, `/`, `%` and `**` over two genuinely dynamic operands (a JS
|
|
264
|
+
* library's `this.pages.length * this.pageSize`, both read off an untyped
|
|
265
|
+
* `opts`), where the checker typed the result `number`.
|
|
266
|
+
*
|
|
267
|
+
* 13.15.3 ApplyStringOrNumericBinaryOperator: ToNumeric the LEFT operand, then
|
|
268
|
+
* the RIGHT -- in that order, since either may run user code (ToPrimitive) --
|
|
269
|
+
* and apply the Number operator. `gea::dynamicToNumber` is the runtime's whole
|
|
270
|
+
* ToNumber, ToPrimitive and the BigInt/Symbol TypeErrors included. The one
|
|
271
|
+
* outcome the `number` cell cannot hold is BigInt-by-BigInt, whose result is a
|
|
272
|
+
* BigInt: that aborts by name instead of producing a Number the language
|
|
273
|
+
* never would.
|
|
274
|
+
*/
|
|
275
|
+
const dynamicArithmeticOperators = new Set(['-', '*', '/', '%', '**']);
|
|
276
|
+
const dynamicArithmeticText = (ctx, operation, first, second) => {
|
|
277
|
+
if (!dynamicArithmeticOperators.has(operation.operator))
|
|
278
|
+
return null;
|
|
279
|
+
if (first.representation.kind !== 'dynamic' || second.representation.kind !== 'dynamic')
|
|
280
|
+
return null;
|
|
281
|
+
const result = operation.result.representation;
|
|
282
|
+
if (result.kind !== 'scalar' || result.domain !== 'number')
|
|
283
|
+
return null;
|
|
284
|
+
const numberCarrier = { kind: 'scalar', domain: 'number' };
|
|
285
|
+
const spelling = binaryOperatorFor(operation.operator, numberCarrier);
|
|
286
|
+
if (spelling === null)
|
|
287
|
+
return null;
|
|
288
|
+
const applied = spelling.kind === 'infix' ? `gea_left_number ${spelling.text} gea_right_number` : `${spelling.text}(gea_left_number, gea_right_number)`;
|
|
289
|
+
return (`([&]() -> double { const gea::Value& gea_left = ${operandText(ctx, first)}; const gea::Value& gea_right = ${operandText(ctx, second)}; ` +
|
|
290
|
+
'if (gea_left.tag() == gea::Value::Tag::BigInt && gea_right.tag() == gea::Value::Tag::BigInt) ' +
|
|
291
|
+
`gea::detail::refusePayloadMismatch("BigInt ${operation.operator} BigInt is a BigInt, and this cell was typed number"); ` +
|
|
292
|
+
'const double gea_left_number = gea::dynamicToNumber(gea_left); const double gea_right_number = gea::dynamicToNumber(gea_right); ' +
|
|
293
|
+
`return ${applied}; }())`);
|
|
294
|
+
};
|
|
248
295
|
const binaryOperatorFor = (operator, carrier) => {
|
|
249
296
|
if (carrier.kind === 'string')
|
|
250
297
|
return stringBinaryOperators.get(operator) ?? null;
|
|
@@ -365,6 +412,16 @@ const emitCompute = (ctx, lines, operation) => {
|
|
|
365
412
|
lines.push(`${defineValue(ctx, operation.result)} = ${cppUndefinedValue};`);
|
|
366
413
|
return;
|
|
367
414
|
}
|
|
415
|
+
// The one other operand-free unary: an intrinsic accessor getter's value,
|
|
416
|
+
// which reads nothing -- the chain that reached it was consumed whole.
|
|
417
|
+
const intrinsicGetter = operation.form === 'unary' ? intrinsicAccessorGetterOfOperator(operation.operator) : null;
|
|
418
|
+
if (intrinsicGetter !== null) {
|
|
419
|
+
const text = intrinsicAccessorGetterValueText(intrinsicGetter, operation.result.representation);
|
|
420
|
+
if (text === null)
|
|
421
|
+
throw createCppEmitBlockedError(`runtime-helper:${intrinsicAccessorGetterCapability(intrinsicGetter, operation.result.representation)}`, `the ${intrinsicGetter} getter has no rendering in a "${operation.result.representation.kind}" carrier`);
|
|
422
|
+
lines.push(`${defineValue(ctx, operation.result)} = ${text};`);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
368
425
|
const first = operands[0];
|
|
369
426
|
if (!first)
|
|
370
427
|
throw createCppEmitBlockedError('runtime-helper:computation:no-operands', 'a computation with no operands has no C++ spelling');
|
|
@@ -395,6 +452,30 @@ const emitCompute = (ctx, lines, operation) => {
|
|
|
395
452
|
// through the `operator` field as a decimal string (see `ir/model.ts`'s
|
|
396
453
|
// own doc for why) rather than a real language operator, since `.is<N>()`/
|
|
397
454
|
// `.get<N>()` need it as a compile-time template argument.
|
|
455
|
+
// `ir/literal-set-membership.ts`'s rewrite of `new Set([...]).has(x)`: the
|
|
456
|
+
// same SameValueZero `Set::has` asks of each item, against the literal's
|
|
457
|
+
// elements where they already are, with no Set built to hold them.
|
|
458
|
+
if (operation.form === 'same-value-zero-member') {
|
|
459
|
+
const key = first.representation;
|
|
460
|
+
const candidates = operands.slice(1).map((candidate) => {
|
|
461
|
+
const held = representationKey(candidate.representation);
|
|
462
|
+
// The key's own carrier, or the payload of an optional key, is compared
|
|
463
|
+
// in place; anything else is aligned to the key the way the literal's
|
|
464
|
+
// own element would have been.
|
|
465
|
+
if (held === representationKey(key) ||
|
|
466
|
+
(key.kind === 'optional' && held === representationKey(key.payload)) ||
|
|
467
|
+
(candidate.representation.kind === 'optional' && representationKey(candidate.representation.payload) === representationKey(key)))
|
|
468
|
+
return operandText(ctx, candidate);
|
|
469
|
+
return alignedText(ctx, key, candidate, 'same-value-zero-member');
|
|
470
|
+
});
|
|
471
|
+
const name = defineValue(ctx, operation.result);
|
|
472
|
+
if (candidates.length === 0) {
|
|
473
|
+
lines.push(`${name} = (static_cast<void>(${operandText(ctx, first)}), false);`);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
lines.push(`${name} = gea::sameValueZeroMember<${cppTypeOf(key)}>(${[operandText(ctx, first), ...candidates].join(', ')});`);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
398
479
|
if (operation.form === 'require-tagged-union-arm') {
|
|
399
480
|
const text = operandText(ctx, first);
|
|
400
481
|
const index = operation.operator;
|
|
@@ -523,7 +604,9 @@ const emitCompute = (ctx, lines, operation) => {
|
|
|
523
604
|
if (!step || !binaryOperatorFor(step, first.representation)) {
|
|
524
605
|
throw createCppEmitBlockedError(`runtime-helper:computation:update:${operation.operator}:${first.representation.kind}`, `update "${operation.operator}" on a "${first.representation.kind}" carrier has no C++ spelling in this emitter`);
|
|
525
606
|
}
|
|
526
|
-
const name = defineValue(ctx, operation.result)
|
|
607
|
+
const name = defineValue(ctx, operation.result);
|
|
608
|
+
const rounding = ctx.roundingArithmetic.has(operation.result.id) ? roundingIntegerHelpers.get(step) : undefined;
|
|
609
|
+
const raw = rounding === undefined ? `${operandText(ctx, first)} ${step} 1` : `${rounding}(${operandText(ctx, first)}, 1LL)`;
|
|
527
610
|
lines.push(`${name} = ${widenedStoreText(operation.result.representation, first.representation, raw) ?? raw};`);
|
|
528
611
|
return;
|
|
529
612
|
}
|
|
@@ -684,10 +767,67 @@ const emitCompute = (ctx, lines, operation) => {
|
|
|
684
767
|
// left here is exactly that `never`: BigInt mixed with Number, a Date's
|
|
685
768
|
// `valueOf`-first ToPrimitive, an object whose own `toString` would have
|
|
686
769
|
// to be called. Refused by name, never spelled by a second table.
|
|
770
|
+
// Two Maps whose carriers differ only in their value type -- a `Map<K, U>`
|
|
771
|
+
// and the `ReadonlyMap<K, V>` view of it -- are compared for identity, which
|
|
772
|
+
// no conversion of one into the other could preserve: a view is a second
|
|
773
|
+
// allocation over the same source. `gea::Ref<Map>`'s own `operator==` looks
|
|
774
|
+
// through the view (`Map::identity`), so the comparison names the one object
|
|
775
|
+
// both hold, exactly as `===` on two references does.
|
|
776
|
+
const firstCarrier = first.representation;
|
|
777
|
+
const secondCarrier = second.representation;
|
|
778
|
+
if (identitySpelling &&
|
|
779
|
+
representationKey(firstCarrier) !== representationKey(secondCarrier) &&
|
|
780
|
+
firstCarrier.kind === 'keyed-collection' &&
|
|
781
|
+
secondCarrier.kind === 'keyed-collection' &&
|
|
782
|
+
firstCarrier.family === 'map' &&
|
|
783
|
+
secondCarrier.family === 'map' &&
|
|
784
|
+
firstCarrier.ownership === 'shared-refcount' &&
|
|
785
|
+
secondCarrier.ownership === 'shared-refcount' &&
|
|
786
|
+
firstCarrier.recursive === undefined &&
|
|
787
|
+
secondCarrier.recursive === undefined) {
|
|
788
|
+
lines.push(`${defineValue(ctx, operation.result)} = ${operandText(ctx, first)} ${identitySpelling.text} ${operandText(ctx, second)};`);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
// A class read off an instance (`x.constructor`, a `constructor-identity`:
|
|
792
|
+
// the instance's class evaluation state) compared with a class value (a
|
|
793
|
+
// `constructor-family`, whose environment IS that evaluation's state -- see
|
|
794
|
+
// `gea::allocateNativeClassMethodEnvironment`). One class evaluation is one
|
|
795
|
+
// constructor object, so the two name the same object exactly when they
|
|
796
|
+
// name the same state; converting either side into the other would build a
|
|
797
|
+
// second handle to compare instead of asking the one both carry.
|
|
798
|
+
const classIdentitySide = firstCarrier.kind === 'constructor-identity' && secondCarrier.kind === 'constructor-family'
|
|
799
|
+
? 0
|
|
800
|
+
: secondCarrier.kind === 'constructor-identity' && firstCarrier.kind === 'constructor-family'
|
|
801
|
+
? 1
|
|
802
|
+
: null;
|
|
803
|
+
if (identitySpelling && classIdentitySide !== null) {
|
|
804
|
+
const identity = operandText(ctx, classIdentitySide === 0 ? first : second);
|
|
805
|
+
const family = operandText(ctx, classIdentitySide === 0 ? second : first);
|
|
806
|
+
lines.push(`${defineValue(ctx, operation.result)} = static_cast<const void*>((${identity}).get()) ${identitySpelling.text} static_cast<const void*>((${family}).environment);`);
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
// An open `any` Document compared with an object it may view
|
|
810
|
+
// (`gea::dictionary::aliasOf`): the one object both name, asked of the two
|
|
811
|
+
// boxes -- a Document's box IS the object it views.
|
|
812
|
+
if (identitySpelling &&
|
|
813
|
+
((isOpenDocument(firstCarrier) && documentViewable(secondCarrier)) || (isOpenDocument(secondCarrier) && documentViewable(firstCarrier)))) {
|
|
814
|
+
const left = dynamicCarrierBoxText(firstCarrier, operandText(ctx, first));
|
|
815
|
+
const right = dynamicCarrierBoxText(secondCarrier, operandText(ctx, second));
|
|
816
|
+
if (left !== null && right !== null) {
|
|
817
|
+
const negated = identitySpelling.text === '!=' ? '!' : '';
|
|
818
|
+
lines.push(`${defineValue(ctx, operation.result)} = ${negated}gea::Value::strictEquals(${left}, ${right});`);
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
687
822
|
if (representationKey(first.representation) !== representationKey(second.representation)) {
|
|
688
823
|
throw createCppEmitBlockedError(`conversion:${representationKey(first.representation)}->${representationKey(second.representation)}`, `binary "${operation.operator}" mixes a "${first.representation.kind}" and a "${second.representation.kind}" carrier, ` +
|
|
689
824
|
'and the census names no coercion that brings them together');
|
|
690
825
|
}
|
|
826
|
+
const dynamicArithmetic = dynamicArithmeticText(ctx, operation, first, second);
|
|
827
|
+
if (dynamicArithmetic !== null) {
|
|
828
|
+
lines.push(`${defineValue(ctx, operation.result)} = ${dynamicArithmetic};`);
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
691
831
|
const spelling = binaryOperatorFor(operation.operator, first.representation);
|
|
692
832
|
if (!spelling) {
|
|
693
833
|
throw createCppEmitBlockedError(`runtime-helper:computation:binary:${operation.operator}:${first.representation.kind}`, `binary "${operation.operator}" on a "${first.representation.kind}" carrier has no C++ spelling in this emitter`);
|
|
@@ -727,6 +867,14 @@ const emitCompute = (ctx, lines, operation) => {
|
|
|
727
867
|
lines.push(`${name} = ${integerBitwise}(${left}, ${right});`);
|
|
728
868
|
return;
|
|
729
869
|
}
|
|
870
|
+
// A narrowed sum whose integer answer may leave +-2^53 rounds as the Number
|
|
871
|
+
// does rather than carrying digits the Number never had (`ir/integers.ts`,
|
|
872
|
+
// `roundingArithmetic`).
|
|
873
|
+
const rounding = integral && ctx.roundingArithmetic.has(operation.result.id) ? roundingIntegerHelpers.get(operation.operator) : undefined;
|
|
874
|
+
if (rounding !== undefined) {
|
|
875
|
+
lines.push(`${name} = ${rounding}(${left}, ${right});`);
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
730
878
|
const expression = spelling.kind === 'infix' ? `${left} ${spelling.text} ${right}` : `${spelling.text}(${left}, ${right})`;
|
|
731
879
|
// Coerced operands compute the operator's own result -- a Number, a String
|
|
732
880
|
// for `+` over strings, a Boolean for a relational -- but the CELL is what
|
|
@@ -881,10 +1029,36 @@ const emitConvert = (ctx, lines, operation) => {
|
|
|
881
1029
|
defineValueAlias(ctx, operation.result, '(void)0');
|
|
882
1030
|
return;
|
|
883
1031
|
}
|
|
884
|
-
|
|
1032
|
+
// A string arm of a borrowed union formal: name it where it is read instead of copying it out (`borrowed-arm-projections.ts`).
|
|
1033
|
+
const projection = ctx.borrowedArmProjections.get(operation.result.id);
|
|
1034
|
+
if (projection !== undefined && projection.arm !== null) {
|
|
1035
|
+
ctx.deferredTexts.set(operation.result.id, `(gea::host::unionArmRef<${projection.arm}>(${cppFormalName(projection.ordinal)}))`);
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
const rawInput = owningConversionInputText(ctx, operation.source, operation.result.representation, operandText(ctx, operation.source));
|
|
1039
|
+
// A native sum widening owns its source: the unit function takes it by
|
|
1040
|
+
// value and the bare arm wrap consumes it once. A dying input moves into
|
|
1041
|
+
// that slot exactly as a call argument does (`emit-callable.ts`'s
|
|
1042
|
+
// `alignedText`); a copy here was one retain, one release and one
|
|
1043
|
+
// cycle-candidate buffering per widening of a fresh record or union --
|
|
1044
|
+
// `WriteConcern.fromOptions` widened each of its option records this way.
|
|
1045
|
+
// A presence-checked load stays as it is: `presentOrThrow` hands the cell
|
|
1046
|
+
// back by reference, and the widening then copies from that reference.
|
|
1047
|
+
const input = operation.presence !== 'checked' && nativeSumWidenable(operation.source.representation, operation.result.representation)
|
|
1048
|
+
? movedValueText(ctx, operation.source, operation.source.representation, rawInput)
|
|
1049
|
+
: rawInput;
|
|
885
1050
|
// A load no program fact proves present (`ir/presence-proof.ts`) tests the
|
|
886
1051
|
// cell first: `presentOrThrow` hands back the same cell or raises.
|
|
887
1052
|
const sourceText = operation.presence === 'checked' ? `gea::host::presentOrThrow(${input})` : input;
|
|
1053
|
+
if (operation.rebuild === 'unshared-array') {
|
|
1054
|
+
const rebuilt = unsharedArrayRebuildText(ctx, operation.source.representation, operation.result.representation, sourceText);
|
|
1055
|
+
if (rebuilt === null) {
|
|
1056
|
+
throw createCppEmitBlockedError(`conversion:${representationKey(operation.source.representation)}->${representationKey(operation.result.representation)}`, `rebuilds a fresh ${representationKey(operation.source.representation)} at ${representationKey(operation.result.representation)}, ` +
|
|
1057
|
+
`whose element conversion no installed load performs (conversion use ${operation.conversionUse})`);
|
|
1058
|
+
}
|
|
1059
|
+
lines.push(`${defineValue(ctx, operation.result)} = ${rebuilt};`);
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
888
1062
|
// The node lowering named on this instruction, rendered by its recipe
|
|
889
1063
|
// (`alignedValueText` asks the census for the same pair and renders the
|
|
890
1064
|
// same node; a pair the census refused is its drift row, and the chain's).
|
|
@@ -893,7 +1067,15 @@ const emitConvert = (ctx, lines, operation) => {
|
|
|
893
1067
|
// pair with the store node `alignedValueText` would look up, so for those
|
|
894
1068
|
// the instruction's own node is the only thing that says which one runs.
|
|
895
1069
|
const namedOverPair = named?.capability.kind === 'coercion' ||
|
|
896
|
-
(named?.capability.kind === 'static' &&
|
|
1070
|
+
(named?.capability.kind === 'static' &&
|
|
1071
|
+
(named.capability.materializer.id === EXACT_ARM_MATERIALIZER ||
|
|
1072
|
+
named.capability.materializer.id === NATIVE_BASE_VIEW_MATERIALIZER ||
|
|
1073
|
+
named.capability.materializer.id === ARM_VIEW_MATERIALIZER ||
|
|
1074
|
+
named.capability.materializer.id === ASSERTED_UNION_MATERIALIZER ||
|
|
1075
|
+
named.capability.materializer.id === ASSERTED_UNION_COPY_MATERIALIZER ||
|
|
1076
|
+
named.capability.materializer.id === FAMILY_MEMBER_VIEW_MATERIALIZER ||
|
|
1077
|
+
named.capability.materializer.id === CAUGHT_HANDOFF_MATERIALIZER ||
|
|
1078
|
+
named.capability.materializer.id === NULLISH_OPTIONAL_MATERIALIZER));
|
|
897
1079
|
const text = (namedOverPair
|
|
898
1080
|
? namedConversionText(ctx, 'emit.ts:1026', named, sourceText)
|
|
899
1081
|
: alignedValueText(ctx, 'emit.ts:1026', operation.source.representation, operation.result.representation, sourceText)) ??
|
|
@@ -919,34 +1101,63 @@ const emitConvert = (ctx, lines, operation) => {
|
|
|
919
1101
|
`which no installed load performs (conversion use ${operation.conversionUse})`);
|
|
920
1102
|
}
|
|
921
1103
|
const consumed = transfersFormalConversion(ctx.consumingFormalConversions, operation.result.id) === 'move' ? `std::move(${text})` : text;
|
|
1104
|
+
// The payload of a borrowed optional formal, rendered as its bare dereference: name the formal's own
|
|
1105
|
+
// storage where the payload is read instead of copying it into a temporary of its own
|
|
1106
|
+
// (`borrowed-arm-projections.ts`). Only when nothing consumes the value by move -- a moved view would
|
|
1107
|
+
// empty the caller's slot -- and only when the rendering is exactly `(*formal)`, so any widening or
|
|
1108
|
+
// checked load the census chose keeps its copy.
|
|
1109
|
+
if (projection !== undefined && projection.arm === null && consumed === text) {
|
|
1110
|
+
const formal = cppFormalName(projection.ordinal);
|
|
1111
|
+
if (text === `(*${formal})` || text === `((*${formal}))`) {
|
|
1112
|
+
ctx.deferredTexts.set(operation.result.id, text);
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
922
1116
|
lines.push(`${defineValue(ctx, operation.result)} = ${consumed};`);
|
|
923
1117
|
};
|
|
924
1118
|
/**
|
|
925
1119
|
* `await p`.
|
|
926
1120
|
*
|
|
927
|
-
*
|
|
928
|
-
*
|
|
929
|
-
*
|
|
930
|
-
*
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
1121
|
+
* Inside an async coroutine (`EmitContext.asyncCoroutineBody`) this is a real
|
|
1122
|
+
* suspension: `co_await` parks the frame on the promise and resumes it from one
|
|
1123
|
+
* promise job, so whatever else is queued -- another async function's
|
|
1124
|
+
* continuation, a timer's callback -- runs in between, as ECMA-262 27.7.5.3
|
|
1125
|
+
* says it does. `coroutineAwaitStatements` renders it for every carrier an
|
|
1126
|
+
* `await` accepts: a promise, an instance of a `Promise` subclass, a box that
|
|
1127
|
+
* may hold one, and an optional or a union with a thenable among its arms,
|
|
1128
|
+
* all of which `awaitedText` (prototype/emit-prototype-promise.ts) states as
|
|
1129
|
+
* ECMA-262 27.2.4.7.1 `PromiseResolve` once.
|
|
934
1130
|
*
|
|
935
|
-
*
|
|
936
|
-
*
|
|
937
|
-
*
|
|
938
|
-
*
|
|
939
|
-
*
|
|
940
|
-
*
|
|
941
|
-
*
|
|
942
|
-
*
|
|
943
|
-
* passed it through untouched, handing a `TaggedUnion<...>` to a consumer told
|
|
944
|
-
* it would get the payload. `awaitedText` (prototype/emit-prototype-promise.ts)
|
|
945
|
-
* is ECMA-262 27.2.4.7.1 `PromiseResolve` stated once, for all three shapes,
|
|
946
|
-
* and shared with `Promise.all`, which resolves each element by the same rule.
|
|
1131
|
+
* `.awaited()` survives for exactly one caller: a MODULE body's top-level
|
|
1132
|
+
* `await`, which runs at the bottom of the program's own stack and may drive
|
|
1133
|
+
* the event loop until the promise settles. Anywhere else it would be a nested
|
|
1134
|
+
* pump on the current C++ stack -- a timer firing inside it can start work that
|
|
1135
|
+
* traps the await beneath it forever, which is the mongodb driver's deadlock --
|
|
1136
|
+
* so an `await` in any other body that is not a coroutine refuses by name.
|
|
1137
|
+
* An async GENERATOR's frame is a coroutine of its own and renders its awaits
|
|
1138
|
+
* through that frame's machinery.
|
|
947
1139
|
*/
|
|
948
1140
|
const emitAwait = (ctx, lines, operation) => {
|
|
949
1141
|
const text = operandText(ctx, operation.operand);
|
|
1142
|
+
if (suspendsInPlace(ctx)) {
|
|
1143
|
+
const into = operation.result && operation.result.representation.kind !== 'void' ? defineValue(ctx, operation.result) : null;
|
|
1144
|
+
// A promise nothing reads after this await hands its count to the awaiter
|
|
1145
|
+
// instead of lending it a copy. The copy's release at resumption was a
|
|
1146
|
+
// count dip on a settled state whose creator frame had already let go, so
|
|
1147
|
+
// every `await asyncCall()` buffered its promise as a cycle candidate and
|
|
1148
|
+
// forgot it again when the cell died.
|
|
1149
|
+
const awaitedOperand = ctx.taskValues.has(operation.operand.value)
|
|
1150
|
+
? `std::move(${text})`
|
|
1151
|
+
: operation.operand.representation.kind === 'promise'
|
|
1152
|
+
? movedValueText(ctx, operation.operand, null, text)
|
|
1153
|
+
: text;
|
|
1154
|
+
lines.push(...coroutineAwaitStatements(ctx, 'emit.ts:emitAwait', operation.operand.representation, awaitedOperand, operation.result?.representation ?? null, into));
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
if (ctx.abi !== null && !ctx.generatorBody) {
|
|
1158
|
+
throw createCppEmitBlockedError('runtime-helper:boundary:async-resume', `awaits inside a function that is not emitted as an async coroutine (its result carries "${representationKey(ctx.abi.result)}" ` +
|
|
1159
|
+
'rather than a promise), and reading the promise in place would pump the event loop on this stack');
|
|
1160
|
+
}
|
|
950
1161
|
const expression = awaitedText(ctx, 'emit.ts:emitAwait', operation.operand.representation, text, operation.result?.representation ?? null) ?? text;
|
|
951
1162
|
if (!operation.result) {
|
|
952
1163
|
lines.push(`${expression};`);
|
|
@@ -973,9 +1184,12 @@ const emitAwait = (ctx, lines, operation) => {
|
|
|
973
1184
|
* `undefined` to yield into a typed cursor, so it is refused rather than
|
|
974
1185
|
* yielding a default-constructed element the program never wrote.
|
|
975
1186
|
*/
|
|
976
|
-
const emitYield = (ctx, lines, operation) => {
|
|
1187
|
+
const emitYield = (ctx, lines, operation, emitReturn) => {
|
|
977
1188
|
const cursor = ctx.abi?.result;
|
|
978
|
-
|
|
1189
|
+
// An `async function*` yields through the identical `co_yield`: its
|
|
1190
|
+
// `gea::AsyncGenerator` promise type is what answers the pending `next()`
|
|
1191
|
+
// promise with the yielded value (ECMA-262 27.6.3.8 AsyncGeneratorYield).
|
|
1192
|
+
if (cursor?.kind !== 'iterator' && cursor?.kind !== 'async-generator') {
|
|
979
1193
|
throw createCppEmitBlockedError('abrupt-edge:suspend', `appears in a body whose calling convention returns "${cursor ? representationKey(cursor) : 'nothing'}"; ` +
|
|
980
1194
|
'only a body returning an "iterator" cursor is emitted as a coroutine');
|
|
981
1195
|
}
|
|
@@ -990,14 +1204,47 @@ const emitYield = (ctx, lines, operation) => {
|
|
|
990
1204
|
if (!operation.operand && bareUndefined === null) {
|
|
991
1205
|
throw createCppEmitBlockedError('abrupt-edge:suspend', `yields no value; a bare \`yield\` yields \`undefined\`, which this cursor's "${representationKey(cursor.element)}" element carrier cannot hold`);
|
|
992
1206
|
}
|
|
993
|
-
const
|
|
1207
|
+
const yielded = operation.operand ? alignedText(ctx, cursor.element, operation.operand, 'yield') : bareUndefined;
|
|
1208
|
+
// 27.6.3.8 AsyncGeneratorYield AWAITS the value before settling the pending
|
|
1209
|
+
// `next()` with it; `gea::AsyncGenerator` adds no Await of its own, so the
|
|
1210
|
+
// tick is written here.
|
|
1211
|
+
const yieldText = cursor.kind === 'async-generator' ? `(co_yield ${awaitTickText(cursor.element, `${yielded}`)})` : `(co_yield ${yielded})`;
|
|
1212
|
+
// What the resumption carries (`gea::detail::YieldResumption`): the
|
|
1213
|
+
// `next(v)` value, or a `.return(v)` delivered at this yield. The latter is
|
|
1214
|
+
// an abrupt RETURN completion of the generator body (ECMA-262 27.5.3.2 step
|
|
1215
|
+
// 6.c, 27.6.3.7), and it is rendered as exactly that: a `return` terminator
|
|
1216
|
+
// through the enclosing rendering's hook, so the frame's own scope guards
|
|
1217
|
+
// run every `finally` on the way out and an enclosing `for await` closes
|
|
1218
|
+
// its cursor. It used to arrive as a thrown `ReturnSignal`, a C++ unwind
|
|
1219
|
+
// (plus a rethrow per enclosing close region) on every early exit from a
|
|
1220
|
+
// `for await` -- mongodb's `Connection.command` paid three of them per
|
|
1221
|
+
// command, a third of the driver's CPU.
|
|
1222
|
+
if (emitReturn === undefined)
|
|
1223
|
+
throw new Error(`yield ${operation.lineage} rendered with no return hook for its resumption`);
|
|
1224
|
+
// Hoisted like every other cell: a body is a goto graph, and a `goto`
|
|
1225
|
+
// past an in-line initialization is ill-formed.
|
|
1226
|
+
const resumption = `gea_resume_${ctx.nextValueOrdinal}`;
|
|
1227
|
+
ctx.nextValueOrdinal += 1;
|
|
1228
|
+
ctx.declarations.push({ name: resumption, type: `${cppTypeOf(cursor)}::Resumption` });
|
|
1229
|
+
lines.push(`${resumption} = ${yieldText};`);
|
|
1230
|
+
const carriesCompletion = cursor.completion.kind !== 'void' && cursor.completion.kind !== 'undefined';
|
|
1231
|
+
const completionValue = `${resumption}|completion`;
|
|
1232
|
+
if (carriesCompletion) {
|
|
1233
|
+
ctx.valueNames.set(completionValue, `std::move(${resumption}.completion)`);
|
|
1234
|
+
ctx.deliveredReturnValues.add(completionValue);
|
|
1235
|
+
}
|
|
1236
|
+
const returnLines = [];
|
|
1237
|
+
emitReturn(returnLines, {
|
|
1238
|
+
kind: 'return',
|
|
1239
|
+
lineage: null,
|
|
1240
|
+
value: carriesCompletion ? { value: completionValue, representation: cursor.completion } : null
|
|
1241
|
+
});
|
|
1242
|
+
lines.push(`if (${resumption}.returned) {`, ...returnLines, '}');
|
|
994
1243
|
// Statement form: nobody reads what `next(v)` sent back, so the resumed
|
|
995
|
-
// value -- whatever it turns out to be -- is
|
|
996
|
-
//
|
|
997
|
-
if (operation.result === null)
|
|
998
|
-
lines.push(`${yieldText};`);
|
|
1244
|
+
// value -- whatever it turns out to be -- is discarded, the same as any
|
|
1245
|
+
// other unread expression statement.
|
|
1246
|
+
if (operation.result === null)
|
|
999
1247
|
return;
|
|
1000
|
-
}
|
|
1001
1248
|
// A yield whose own value IS read needs a real resume channel to read it
|
|
1002
1249
|
// from: `TNext` collapsed to `undefined` (`representation/derive.ts`) means
|
|
1003
1250
|
// there is no storage behind `yieldText`'s own value to convert, so this
|
|
@@ -1008,7 +1255,7 @@ const emitYield = (ctx, lines, operation) => {
|
|
|
1008
1255
|
'and this generator\'s own resume channel is "undefined" -- either TNext never resolved to a native carrier, or this ' +
|
|
1009
1256
|
'generator is not annotated as one');
|
|
1010
1257
|
}
|
|
1011
|
-
const text = alignedValueText(ctx, 'emit.ts:1156', cursor.resume, operation.result.representation,
|
|
1258
|
+
const text = alignedValueText(ctx, 'emit.ts:1156', cursor.resume, operation.result.representation, `std::move(${resumption}.next)`);
|
|
1012
1259
|
if (text === null) {
|
|
1013
1260
|
throw createCppEmitBlockedError(`conversion:${representationKey(cursor.resume)}->${representationKey(operation.result.representation)}`, `resumes with "${representationKey(cursor.resume)}" where this read expects "${representationKey(operation.result.representation)}", ` +
|
|
1014
1261
|
'and no installed conversion reconciles them');
|
|
@@ -1049,7 +1296,7 @@ const emitUnresolvableReference = (ctx, lines, operation) => {
|
|
|
1049
1296
|
lines.push(`${name} = gea::host::detail::throwReferenceError<${type}>();`);
|
|
1050
1297
|
};
|
|
1051
1298
|
/** Every non-terminator kind this file lowers. Anything else falls to the `default` and refuses, including kinds added after this file was written. */
|
|
1052
|
-
const emitOperationStatements = (ctx, lines, operation) => {
|
|
1299
|
+
const emitOperationStatements = (ctx, lines, operation, emitReturn) => {
|
|
1053
1300
|
switch (operation.kind) {
|
|
1054
1301
|
case 'constant':
|
|
1055
1302
|
emitConstant(ctx, lines, operation);
|
|
@@ -1060,6 +1307,9 @@ const emitOperationStatements = (ctx, lines, operation) => {
|
|
|
1060
1307
|
case 'binding-write':
|
|
1061
1308
|
emitBindingWrite(ctx, lines, operation);
|
|
1062
1309
|
return;
|
|
1310
|
+
case 'binding-renew':
|
|
1311
|
+
emitBindingRenew(ctx, lines, operation);
|
|
1312
|
+
return;
|
|
1063
1313
|
case 'parameter':
|
|
1064
1314
|
emitParameter(ctx, lines, operation);
|
|
1065
1315
|
return;
|
|
@@ -1076,7 +1326,7 @@ const emitOperationStatements = (ctx, lines, operation) => {
|
|
|
1076
1326
|
emitAwait(ctx, lines, operation);
|
|
1077
1327
|
return;
|
|
1078
1328
|
case 'yield':
|
|
1079
|
-
emitYield(ctx, lines, operation);
|
|
1329
|
+
emitYield(ctx, lines, operation, emitReturn);
|
|
1080
1330
|
return;
|
|
1081
1331
|
case 'compute':
|
|
1082
1332
|
emitCompute(ctx, lines, operation);
|
|
@@ -1085,7 +1335,9 @@ const emitOperationStatements = (ctx, lines, operation) => {
|
|
|
1085
1335
|
emitCall(ctx, lines, operation);
|
|
1086
1336
|
return;
|
|
1087
1337
|
case 'commonjs-require':
|
|
1088
|
-
lines.push(
|
|
1338
|
+
lines.push(operation.target === null
|
|
1339
|
+
? `${defineValue(ctx, operation.result)} = gea::commonjs::absentPackage(${cppStringLiteral(operation.absentPackage ?? '')});`
|
|
1340
|
+
: `${defineValue(ctx, operation.result)} = ${cppCommonJsModuleName(operation.target)}();`);
|
|
1089
1341
|
return;
|
|
1090
1342
|
case 'commonjs-binding':
|
|
1091
1343
|
// Publication forces every unproved wrapper read to `dynamic`; a
|
|
@@ -1158,6 +1410,18 @@ const emitOperationStatements = (ctx, lines, operation) => {
|
|
|
1158
1410
|
case 'allocate-regexp':
|
|
1159
1411
|
emitAllocateRegExp(ctx, lines, operation);
|
|
1160
1412
|
return;
|
|
1413
|
+
case 'allocate-proxy':
|
|
1414
|
+
emitAllocateProxy(ctx, lines, operation);
|
|
1415
|
+
return;
|
|
1416
|
+
case 'proxy-part':
|
|
1417
|
+
emitProxyPart(ctx, lines, operation);
|
|
1418
|
+
return;
|
|
1419
|
+
case 'proxy-trap-check':
|
|
1420
|
+
emitProxyTrapCheck(ctx, lines, operation);
|
|
1421
|
+
return;
|
|
1422
|
+
case 'proxy-arm-test':
|
|
1423
|
+
emitProxyArmTest(ctx, lines, operation);
|
|
1424
|
+
return;
|
|
1161
1425
|
case 'allocate-template-object':
|
|
1162
1426
|
emitAllocateTemplateObject(ctx, lines, operation);
|
|
1163
1427
|
return;
|
|
@@ -1338,7 +1602,7 @@ const emitTerminator = (ctx, lines, labels, isSingleBlock, terminator, nextLabel
|
|
|
1338
1602
|
// ECMAScript exception does, so this is complete on its own, while `try`
|
|
1339
1603
|
// needs a catch-side carrier decision this does not make and does not
|
|
1340
1604
|
// pre-empt.
|
|
1341
|
-
lines.push(`
|
|
1605
|
+
lines.push(`GEA_THROW(${operandText(ctx, terminator.value)});`);
|
|
1342
1606
|
// A generator whose body throws before it ever yields or returns
|
|
1343
1607
|
// (`function* () { throw new Test262Error() }`) has no other keyword to
|
|
1344
1608
|
// make it a coroutine, and C++ would compile it as a plain function
|
|
@@ -1380,7 +1644,71 @@ const classTableLines = (ctx, lines, value) => {
|
|
|
1380
1644
|
ctx.pendingClassTableLines.set(root, opened);
|
|
1381
1645
|
return opened;
|
|
1382
1646
|
};
|
|
1383
|
-
|
|
1647
|
+
/**
|
|
1648
|
+
* A withheld operand evaluated once, however many times its consumer's
|
|
1649
|
+
* statements name it.
|
|
1650
|
+
*
|
|
1651
|
+
* Withholding (`emitOperation` below) turns a single-use value into the
|
|
1652
|
+
* expression that computes it, pasted at its one use -- and "one use" is a fact
|
|
1653
|
+
* about the IR, not about how the consumer renders: `Object.assign`'s static
|
|
1654
|
+
* arm reads its source once per field, in the presence test and the store, so
|
|
1655
|
+
* a withheld source (mongodb's `this.options`, a record conversion over a
|
|
1656
|
+
* sidecar) ran once per field. `evaluated-once.ts` binds an operand the
|
|
1657
|
+
* conversion printer names twice; this is the same rule for every other
|
|
1658
|
+
* consumer, where the rendering is statements rather than one expression.
|
|
1659
|
+
*
|
|
1660
|
+
* The binding takes the value's OWN name: withholding reclaimed its hoisted
|
|
1661
|
+
* declaration, so the name is free, unique in the body, and cannot collide with
|
|
1662
|
+
* an `evaluated-once.ts` binding the statements already carry. The block
|
|
1663
|
+
* scopes it to the consumer's statements, which jump nowhere -- labels open
|
|
1664
|
+
* blocks, not operations -- so no `goto` can cross its initialization.
|
|
1665
|
+
* Literals are left pasted (`spellConstants`); so is any withheld text that is
|
|
1666
|
+
* only a storage path, since reading it twice does no work.
|
|
1667
|
+
*/
|
|
1668
|
+
const bindPastedOperandsOnce = (ctx, lines, lineMark, operation) => {
|
|
1669
|
+
// A dense-window access names its operands once per ARM of one `if`/`else`
|
|
1670
|
+
// (`emit-properties.ts`'s dense store and read): the text appears twice and
|
|
1671
|
+
// runs once, and binding it anyway costs exactly what the window exists to
|
|
1672
|
+
// avoid. The bound name is an lvalue, so the hot arm's `.value = name` became
|
|
1673
|
+
// a COPY of the closure the factory just returned (a retain and a release
|
|
1674
|
+
// per iteration of the closure-table loop), and the block the binding opens
|
|
1675
|
+
// ends the read's own withholding, so the element was copied into a cell
|
|
1676
|
+
// instead of being called in place -- `test/hot-path-shapes.mjs` names
|
|
1677
|
+
// both. The arms are exclusive by construction, so the pasted text is safe.
|
|
1678
|
+
if (ctx.denseAccesses.has(operation))
|
|
1679
|
+
return;
|
|
1680
|
+
const bound = new Set();
|
|
1681
|
+
for (const operand of operandsOfIrOperation(operation)) {
|
|
1682
|
+
if (bound.has(operand.value) || ctx.constantTexts.has(operand.value))
|
|
1683
|
+
continue;
|
|
1684
|
+
// A folded `-1` is as much a literal as `1`: naming it turns a constant table's
|
|
1685
|
+
// element into a runtime local, and a braced initializer of `double`s rejects the
|
|
1686
|
+
// `int` that local holds as a narrowing conversion.
|
|
1687
|
+
if (isConstantExpression(ctx, operand.value, 0))
|
|
1688
|
+
continue;
|
|
1689
|
+
const text = ctx.deferredTexts.get(operand.value);
|
|
1690
|
+
const name = ctx.valueNames.get(operand.value);
|
|
1691
|
+
if (text === undefined || name === undefined)
|
|
1692
|
+
continue;
|
|
1693
|
+
if (!namesMoreThanOnce(lines.slice(lineMark).join('\n'), text))
|
|
1694
|
+
continue;
|
|
1695
|
+
bound.add(operand.value);
|
|
1696
|
+
for (let index = lineMark; index < lines.length; index += 1)
|
|
1697
|
+
lines[index] = lines[index].split(text).join(name);
|
|
1698
|
+
lines.splice(lineMark, 0, `{ auto&& ${name} = ${text};`);
|
|
1699
|
+
lines.push('}');
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
/** The stores `buildDyingArgumentIndex` moved to follow the reads of their formal (`SunkStore`). */
|
|
1703
|
+
const sunkStoresOf = (ctx) => ctx.dyingArguments instanceof DyingArgumentSet ? ctx.dyingArguments.sunkStores : noSunkStores;
|
|
1704
|
+
const noSunkStores = new Map();
|
|
1705
|
+
/** Sunk stores the block loop is emitting at their new position right now. */
|
|
1706
|
+
const emittingSunkStore = new WeakSet();
|
|
1707
|
+
const emitOperation = (ctx, lines, operation, emitReturn) => {
|
|
1708
|
+
// A store whose formal was proven dying only because the store moved behind its
|
|
1709
|
+
// reads would empty the formal under them if rendered where it is written.
|
|
1710
|
+
if (operation.kind === 'set' && sunkStoresOf(ctx).has(operation.value.value) && !emittingSunkStore.has(operation))
|
|
1711
|
+
throw new Error('a sunk constructor store was rendered at its source position');
|
|
1384
1712
|
try {
|
|
1385
1713
|
const result = resultOfIrOperation(operation);
|
|
1386
1714
|
if (result !== null && ctx.deadValues.has(result.id)) {
|
|
@@ -1388,12 +1716,15 @@ const emitOperation = (ctx, lines, operation) => {
|
|
|
1388
1716
|
return;
|
|
1389
1717
|
}
|
|
1390
1718
|
if (result === null || !ctx.deferrable.has(result.id)) {
|
|
1391
|
-
|
|
1719
|
+
const lineMark = lines.length;
|
|
1720
|
+
emitOperationStatements(ctx, lines, operation, emitReturn);
|
|
1721
|
+
bindPastedOperandsOnce(ctx, lines, lineMark, operation);
|
|
1392
1722
|
return;
|
|
1393
1723
|
}
|
|
1394
1724
|
const lineMark = lines.length;
|
|
1395
1725
|
const declarationMark = ctx.declarations.length;
|
|
1396
|
-
emitOperationStatements(ctx, lines, operation);
|
|
1726
|
+
emitOperationStatements(ctx, lines, operation, emitReturn);
|
|
1727
|
+
bindPastedOperandsOnce(ctx, lines, lineMark, operation);
|
|
1397
1728
|
// An array literal withheld whole records its own elements instead
|
|
1398
1729
|
// (`emit-arrays.ts`) and has neither a name nor a statement to reclaim.
|
|
1399
1730
|
if (ctx.pendingPacks.has(result.id))
|
|
@@ -1415,6 +1746,8 @@ const emitOperation = (ctx, lines, operation) => {
|
|
|
1415
1746
|
}
|
|
1416
1747
|
catch (error) {
|
|
1417
1748
|
if (isCppEmitBlockedError(error)) {
|
|
1749
|
+
if (operation.lineage !== null)
|
|
1750
|
+
error.lineage ??= operation.lineage;
|
|
1418
1751
|
const result = resultOfIrOperation(operation);
|
|
1419
1752
|
error.message += ` while emitting ${operation.kind}${result === null ? '' : ` -> ${result.id}`}${operation.lineage === null ? '' : ` from ${operation.lineage}`}`;
|
|
1420
1753
|
}
|
|
@@ -1468,9 +1801,46 @@ const settleDeadCalleeSideEffects = (ctx, operation) => {
|
|
|
1468
1801
|
return;
|
|
1469
1802
|
}
|
|
1470
1803
|
};
|
|
1804
|
+
/**
|
|
1805
|
+
* Where each rendered block falls through to, and which labels some `goto`
|
|
1806
|
+
* names, for blocks rendered in `order` -- the one rule for both the flat
|
|
1807
|
+
* layout and the dominator-nested one, since which `goto` is elided depends
|
|
1808
|
+
* on nothing but which block is written next.
|
|
1809
|
+
*/
|
|
1810
|
+
const layoutOf = (ctx, body, labels, order) => {
|
|
1811
|
+
const nextLabel = new Map();
|
|
1812
|
+
order.forEach((id, index) => {
|
|
1813
|
+
const next = order[index + 1];
|
|
1814
|
+
if (next !== undefined)
|
|
1815
|
+
nextLabel.set(id, requireBlockLabel(labels, next));
|
|
1816
|
+
});
|
|
1817
|
+
const labeled = new Set();
|
|
1818
|
+
for (const id of order) {
|
|
1819
|
+
const block = body.blocks.get(id);
|
|
1820
|
+
if (!block)
|
|
1821
|
+
continue;
|
|
1822
|
+
// A counted fill loop's header always spells the `goto` to its exit (`emitFillLoop`).
|
|
1823
|
+
const fill = ctx.fillLoops.get(id);
|
|
1824
|
+
if (fill) {
|
|
1825
|
+
labeled.add(requireBlockLabel(labels, fill.exit));
|
|
1826
|
+
if (fill.kind === 'append')
|
|
1827
|
+
continue;
|
|
1828
|
+
}
|
|
1829
|
+
for (const exit of spelledExitsOf(ctx, labels, block.terminator, nextLabel.get(id) ?? null))
|
|
1830
|
+
labeled.add(exit.label);
|
|
1831
|
+
}
|
|
1832
|
+
return { nextLabel, labeled };
|
|
1833
|
+
};
|
|
1471
1834
|
const threadedFlowOf = (ctx, body, labels, hoists, mergeWrites) => {
|
|
1472
1835
|
if (body.tryRegions.length > 0 || (body.iteratorCloseRegions?.length ?? 0) > 0 || body.blockOrder.length === 1) {
|
|
1473
|
-
return {
|
|
1836
|
+
return {
|
|
1837
|
+
labels,
|
|
1838
|
+
skipped: new Set(),
|
|
1839
|
+
labeled: new Set(labels.values()),
|
|
1840
|
+
nextLabel: new Map(),
|
|
1841
|
+
rendered: body.blockOrder,
|
|
1842
|
+
successors: null
|
|
1843
|
+
};
|
|
1474
1844
|
}
|
|
1475
1845
|
// A literal is spelled at its uses (`spellConstants`) and a merge is written
|
|
1476
1846
|
// by its predecessors (`mergeWritesOf`): neither renders where it sits. A
|
|
@@ -1524,7 +1894,7 @@ const threadedFlowOf = (ctx, body, labels, hoists, mergeWrites) => {
|
|
|
1524
1894
|
aliased.set(id, requireBlockLabel(labels, resolve(id)));
|
|
1525
1895
|
const successorsOf = (block) => {
|
|
1526
1896
|
const fill = ctx.fillLoops.get(block.id);
|
|
1527
|
-
if (fill)
|
|
1897
|
+
if (fill?.kind === 'append')
|
|
1528
1898
|
return [fill.exit];
|
|
1529
1899
|
const terminator = block.terminator;
|
|
1530
1900
|
switch (terminator.kind) {
|
|
@@ -1557,27 +1927,181 @@ const threadedFlowOf = (ctx, body, labels, hoists, mergeWrites) => {
|
|
|
1557
1927
|
}
|
|
1558
1928
|
}
|
|
1559
1929
|
const rendered = body.blockOrder.filter((id) => reachable.has(id));
|
|
1560
|
-
const
|
|
1561
|
-
rendered.forEach((id, index) => {
|
|
1562
|
-
const next = rendered[index + 1];
|
|
1563
|
-
if (next !== undefined)
|
|
1564
|
-
nextLabel.set(id, requireBlockLabel(aliased, next));
|
|
1565
|
-
});
|
|
1566
|
-
const labeled = new Set();
|
|
1930
|
+
const successors = new Map();
|
|
1567
1931
|
for (const id of rendered) {
|
|
1568
1932
|
const block = body.blocks.get(id);
|
|
1933
|
+
if (block)
|
|
1934
|
+
successors.set(id, [...new Set(successorsOf(block).map(resolve))]);
|
|
1935
|
+
}
|
|
1936
|
+
const { nextLabel, labeled } = layoutOf(ctx, body, aliased, rendered);
|
|
1937
|
+
return { labels: aliased, skipped: new Set(body.blockOrder.filter((id) => !reachable.has(id))), labeled, nextLabel, rendered, successors };
|
|
1938
|
+
};
|
|
1939
|
+
/**
|
|
1940
|
+
* The blocks of a dominator-planned body written as nested scopes, each local
|
|
1941
|
+
* declared at the head of the scope `declarationScopesOf` placed it in
|
|
1942
|
+
* (`emit-scopes.ts` says why that nesting keeps every `goto` legal), and the
|
|
1943
|
+
* declarations that stay at the top of the function.
|
|
1944
|
+
*
|
|
1945
|
+
* Guarded by the text itself: a block that spells a `goto` to anywhere its
|
|
1946
|
+
* planned successors do not name would be jumping along an edge the dominator
|
|
1947
|
+
* tree never saw, possibly into a scope past its declarations. Such a body is
|
|
1948
|
+
* written in the same order, flat, with every declaration at the top -- the
|
|
1949
|
+
* layout that needs no graph at all.
|
|
1950
|
+
*/
|
|
1951
|
+
const nestedBlocksOf = (plan, rendered, labels, successors, declarations, rootText, facts, internalLabels = new Map()) => {
|
|
1952
|
+
const flat = () => ({
|
|
1953
|
+
top: declarations,
|
|
1954
|
+
artifacts: plan.order.flatMap((id) => {
|
|
1955
|
+
const block = rendered.get(id);
|
|
1956
|
+
if (!block)
|
|
1957
|
+
return [];
|
|
1958
|
+
return block.label === null ? [block.artifact] : [{ text: `${block.label}:`, facts }, block.artifact];
|
|
1959
|
+
})
|
|
1960
|
+
});
|
|
1961
|
+
const mentions = new Map();
|
|
1962
|
+
for (const id of plan.order) {
|
|
1963
|
+
const block = rendered.get(id);
|
|
1569
1964
|
if (!block)
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1965
|
+
return flat();
|
|
1966
|
+
const allowed = new Set([
|
|
1967
|
+
...(successors.get(id) ?? []).map((next) => requireBlockLabel(labels, next)),
|
|
1968
|
+
...(internalLabels.get(id) ?? [])
|
|
1969
|
+
]);
|
|
1970
|
+
if (gotoTargetsOf(block.artifact.text).some((target) => !allowed.has(target)))
|
|
1971
|
+
return flat();
|
|
1972
|
+
mentions.set(id, identifiersOf(block.artifact.text));
|
|
1973
|
+
}
|
|
1974
|
+
const scopes = declarationScopesOf(plan, declarations, mentions, rootText);
|
|
1975
|
+
const top = [];
|
|
1976
|
+
const scoped = new Map();
|
|
1977
|
+
for (const entry of declarations) {
|
|
1978
|
+
const scope = scopes.get(entry.name) ?? null;
|
|
1979
|
+
if (scope === null) {
|
|
1980
|
+
top.push(entry);
|
|
1575
1981
|
continue;
|
|
1576
1982
|
}
|
|
1577
|
-
|
|
1578
|
-
|
|
1983
|
+
const list = scoped.get(scope);
|
|
1984
|
+
if (list)
|
|
1985
|
+
list.push(entry);
|
|
1986
|
+
else
|
|
1987
|
+
scoped.set(scope, [entry]);
|
|
1988
|
+
}
|
|
1989
|
+
const artifacts = [];
|
|
1990
|
+
const write = (id) => {
|
|
1991
|
+
const block = rendered.get(id);
|
|
1992
|
+
if (!block)
|
|
1993
|
+
return;
|
|
1994
|
+
const own = scoped.get(id) ?? [];
|
|
1995
|
+
const head = [];
|
|
1996
|
+
// A label must label a statement: one whose block writes nothing of its
|
|
1997
|
+
// own and opens no scope labels the empty statement.
|
|
1998
|
+
if (block.label !== null)
|
|
1999
|
+
head.push(own.length === 0 && block.artifact.text.trim() === '' ? `${block.label}: ;` : `${block.label}:`);
|
|
2000
|
+
if (own.length > 0)
|
|
2001
|
+
head.push('{', ...own.map((entry) => `${entry.type} ${entry.name};`));
|
|
2002
|
+
if (head.length > 0)
|
|
2003
|
+
artifacts.push({ text: head.join('\n'), facts });
|
|
2004
|
+
artifacts.push(block.artifact);
|
|
2005
|
+
for (const child of plan.children.get(id) ?? [])
|
|
2006
|
+
write(child);
|
|
2007
|
+
if (own.length > 0)
|
|
2008
|
+
artifacts.push({ text: '}', facts });
|
|
2009
|
+
};
|
|
2010
|
+
write(plan.entry);
|
|
2011
|
+
return { top, artifacts };
|
|
2012
|
+
};
|
|
2013
|
+
const isBareIdentifier = (text) => {
|
|
2014
|
+
if (text.length === 0)
|
|
2015
|
+
return false;
|
|
2016
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
2017
|
+
const code = text.charCodeAt(index);
|
|
2018
|
+
const word = (code >= 97 && code <= 122) || (code >= 65 && code <= 90) || code === 95 || (index > 0 && code >= 48 && code <= 57);
|
|
2019
|
+
if (!word)
|
|
2020
|
+
return false;
|
|
2021
|
+
}
|
|
2022
|
+
return true;
|
|
2023
|
+
};
|
|
2024
|
+
/**
|
|
2025
|
+
* A body with try or iterator-close regions, re-nested by dominance with each
|
|
2026
|
+
* region as ONE node.
|
|
2027
|
+
*
|
|
2028
|
+
* A region renders its own control flow -- a `try`/`catch`, a finally guard,
|
|
2029
|
+
* a completion guard -- so its blocks cannot be scattered across scopes. But
|
|
2030
|
+
* the region is a single statement headed by its entry's label, and every way
|
|
2031
|
+
* out of it is a spelled `goto` (the flat layout of such a body elides no
|
|
2032
|
+
* jump), a `return` or a throw: to the blocks around it, the region is one
|
|
2033
|
+
* block whose successors are the outer labels its text jumps to. The hot
|
|
2034
|
+
* async bodies of a driver sit almost entirely inside such regions, and the
|
|
2035
|
+
* flat layout gave every one of their locals the whole coroutine frame.
|
|
2036
|
+
*
|
|
2037
|
+
* `chunks` are the flat artifacts in render order, each headed by its block's
|
|
2038
|
+
* label line; `chunkIds` names the block (a region's entry) each was rendered
|
|
2039
|
+
* for. A declaration named only inside a region is scoped at the region's
|
|
2040
|
+
* node, which encloses the whole statement -- its finally guard's lambda too.
|
|
2041
|
+
*
|
|
2042
|
+
* `null` -- keep the flat layout -- when a chunk does not start with its own
|
|
2043
|
+
* label, when a jump names a label inside ANOTHER chunk (a region with no
|
|
2044
|
+
* handler renders its blocks bare, and an outer jump into one of them cannot
|
|
2045
|
+
* be re-nested), or when some chunk is unreachable along the spelled jumps.
|
|
2046
|
+
*/
|
|
2047
|
+
const regionScopedBlocksOf = (entry, chunkIds, chunks, labels, declarations, rootText, facts) => {
|
|
2048
|
+
if (chunkIds.length !== chunks.length)
|
|
2049
|
+
return null;
|
|
2050
|
+
const allLabels = new Set(labels.values());
|
|
2051
|
+
const nodeOfLabel = new Map();
|
|
2052
|
+
const internalOf = new Map();
|
|
2053
|
+
const internal = new Map();
|
|
2054
|
+
const texts = new Map();
|
|
2055
|
+
for (let index = 0; index < chunks.length; index += 1) {
|
|
2056
|
+
const id = chunkIds[index];
|
|
2057
|
+
const chunk = chunks[index];
|
|
2058
|
+
if (id === undefined || chunk === undefined || texts.has(id))
|
|
2059
|
+
return null;
|
|
2060
|
+
const label = requireBlockLabel(labels, id);
|
|
2061
|
+
const head = `${label}:`;
|
|
2062
|
+
if (chunk.text !== head && !chunk.text.startsWith(`${head}\n`))
|
|
2063
|
+
return null;
|
|
2064
|
+
const text = chunk.text.slice(head.length + 1);
|
|
2065
|
+
texts.set(id, { text, facts: chunk.facts });
|
|
2066
|
+
nodeOfLabel.set(label, id);
|
|
2067
|
+
const own = new Set();
|
|
2068
|
+
for (const line of text.split('\n')) {
|
|
2069
|
+
if (!line.endsWith(':'))
|
|
2070
|
+
continue;
|
|
2071
|
+
const name = line.slice(0, -1);
|
|
2072
|
+
// A label the region spells for itself (a finally guard's `_run` and
|
|
2073
|
+
// `_done` labels) is as internal as a block label: a jump to it stays in
|
|
2074
|
+
// the chunk. Counting only block labels sent every body with a finally
|
|
2075
|
+
// guard back to the flat layout, all of its locals in the frame.
|
|
2076
|
+
if (!allLabels.has(name) && !isBareIdentifier(name))
|
|
2077
|
+
continue;
|
|
2078
|
+
own.add(name);
|
|
2079
|
+
internalOf.set(name, id);
|
|
2080
|
+
}
|
|
2081
|
+
internal.set(id, own);
|
|
2082
|
+
}
|
|
2083
|
+
const successors = new Map();
|
|
2084
|
+
const targeted = new Set();
|
|
2085
|
+
for (const [id, { text }] of texts) {
|
|
2086
|
+
const next = new Set();
|
|
2087
|
+
for (const target of gotoTargetsOf(text)) {
|
|
2088
|
+
if (internal.get(id)?.has(target))
|
|
2089
|
+
continue;
|
|
2090
|
+
const node = nodeOfLabel.get(target);
|
|
2091
|
+
if (node === undefined || internalOf.has(target))
|
|
2092
|
+
return null;
|
|
2093
|
+
next.add(node);
|
|
2094
|
+
targeted.add(node);
|
|
2095
|
+
}
|
|
2096
|
+
successors.set(id, [...next]);
|
|
1579
2097
|
}
|
|
1580
|
-
|
|
2098
|
+
const plan = scopePlanOf(entry, chunkIds, successors);
|
|
2099
|
+
if (plan === null)
|
|
2100
|
+
return null;
|
|
2101
|
+
const rendered = new Map();
|
|
2102
|
+
for (const [id, artifact] of texts)
|
|
2103
|
+
rendered.set(id, { label: targeted.has(id) ? requireBlockLabel(labels, id) : null, artifact });
|
|
2104
|
+
return nestedBlocksOf(plan, rendered, labels, successors, declarations, rootText, facts, internal);
|
|
1581
2105
|
};
|
|
1582
2106
|
/** One `blockN` label per block, in `blockOrder`, so a forward jump (a loop back-edge included) always resolves before any block renders. */
|
|
1583
2107
|
const blockLabelsOf = (order) => {
|
|
@@ -1624,7 +2148,7 @@ export const emitBody = (body, placements, classes, hosts, deriver, wellKnownSym
|
|
|
1624
2148
|
symbolKeys, templateObjects, directCallableBindings = new Map(),
|
|
1625
2149
|
// `virtualDispatch` is every `class key` with a dispatch member (`virtual-methods.ts`);
|
|
1626
2150
|
// `narrowedStorage`/`narrowedFormals` are what the integer census settled here.
|
|
1627
|
-
virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new Set(), magnitudes: new Map() }, narrowedFormals = new Set(), repeatedConstructors = new Map(), dyingArguments = new Set(), instantiation = noInstantiationFacts, abiOfCallable = () => null, functionFacts = new Map(), hostMethodAliases = new Map(), callableMemberCandidates = new Map(), borrowableMemberBodies = new Set(), stableBorrowEntries = new Map(), printerDrift = [], conversions = null, nativeSelections = undefined, callableIdentityDemand = observesEveryCallableIdentity, nativeIntegrityRestricted =
|
|
2151
|
+
virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new Set(), magnitudes: new Map() }, narrowedFormals = new Set(), repeatedConstructors = new Map(), dyingArguments = new Set(), instantiation = noInstantiationFacts, abiOfCallable = () => null, functionFacts = new Map(), hostMethodAliases = new Map(), callableMemberCandidates = new Map(), borrowableMemberBodies = new Set(), stableBorrowEntries = new Map(), printerDrift = [], conversions = null, nativeSelections = undefined, callableIdentityDemand = observesEveryCallableIdentity, nativeIntegrityRestricted = restrictsEveryCarrier, fixedFieldStateConstant = false, definitionCells = new Set(), constructionOnlyFields = noConstructionOnlyFields, keyOrderUnobserved = new Set(), taskBodies = new Set()) => {
|
|
1628
2152
|
// Every fact this body settles before a single line renders, computed here
|
|
1629
2153
|
// -- from `body` and the plain, already-available inputs above -- and
|
|
1630
2154
|
// handed to `createEmitContext` as one argument instead of mutated onto the
|
|
@@ -1637,6 +2161,9 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
1637
2161
|
? placement.representation
|
|
1638
2162
|
: null;
|
|
1639
2163
|
});
|
|
2164
|
+
const borrowedArmProjections = borrowedArmProjectionsOf(body, stableBorrowEntries.get(cppBodyName(body.sourceOwner)), conversions);
|
|
2165
|
+
// Each such view is a reference into a borrowed formal, so it is as stable an actual as the formal.
|
|
2166
|
+
const stableWithProjections = new Set([...stableBorrowActuals, ...borrowedArmProjections.keys()]);
|
|
1640
2167
|
// A read has to know what the REST of the body does to the cell it reads.
|
|
1641
2168
|
// `emit-bindings.ts` lets a host object's read name its cell rather than
|
|
1642
2169
|
// copy out of it, and that identity only holds while the cell keeps
|
|
@@ -1660,13 +2187,21 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
1660
2187
|
bindingWriteCounts.set(operation.declaration, (bindingWriteCounts.get(operation.declaration) ?? 0) + 1);
|
|
1661
2188
|
}
|
|
1662
2189
|
}
|
|
1663
|
-
const owningClass =
|
|
2190
|
+
const owningClass = classLayoutsConstructedBy(classes, body.sourceOwner)[0] ?? null;
|
|
1664
2191
|
const constructorOf = owningClass
|
|
1665
2192
|
? { layout: owningClass, derived: constructedBaseOf(owningClass) !== null || owningClass.nativeBase !== null, callsSuper }
|
|
1666
2193
|
: null;
|
|
1667
2194
|
const formalInputs = ownedFormalInputsOf(body);
|
|
1668
|
-
const ownedDyingValues = new Set([...ownedDyingValuesOf(body), ...formalInputs.arguments]);
|
|
1669
|
-
const
|
|
2195
|
+
const ownedDyingValues = new Set([...ownedDyingValuesOf(body), ...ownedDyingMergeInputsOf(body), ...formalInputs.arguments]);
|
|
2196
|
+
const transferDyingValues = new Set([...ownedDyingValues, ...dyingTransferUsesOf(body)]);
|
|
2197
|
+
const layoutKeys = new Map();
|
|
2198
|
+
const origins = bodyValueOriginsOf(body, (representation) => {
|
|
2199
|
+
if (representation.kind !== 'native-record-ref' || representation.native !== null)
|
|
2200
|
+
return null;
|
|
2201
|
+
if (!layoutKeys.has(representation.shapeId))
|
|
2202
|
+
layoutKeys.set(representation.shapeId, recordFieldsOfShape(deriver, representation.shapeId)?.map((field) => field.key) ?? null);
|
|
2203
|
+
return layoutKeys.get(representation.shapeId) ?? null;
|
|
2204
|
+
});
|
|
1670
2205
|
const hostClassReads = hostClassReadsOf(body, placements);
|
|
1671
2206
|
const classObjectReads = classObjectReadsOf(body, placements);
|
|
1672
2207
|
const hostNamespaces = hostNamespaceReadsOf(body, placements, hosts, origins.staticKeyTexts);
|
|
@@ -1679,13 +2214,20 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
1679
2214
|
const directCalleeFacts = directCalleesOf(body, abiOfCallable);
|
|
1680
2215
|
const bodyFacts = {
|
|
1681
2216
|
generatorBody: body.generator === true,
|
|
2217
|
+
asyncCoroutineBody: isAsyncCoroutineBody(body),
|
|
2218
|
+
returnsUnderFinallyGuard: body.tryRegions.some((region) => region.finallyEntry !== null),
|
|
1682
2219
|
receiverValues,
|
|
1683
2220
|
bindingWriteCounts,
|
|
2221
|
+
stableCellReads: stableCellReadsOf(body, (declaration) => placements.get(declaration)?.storage.kind === 'local'),
|
|
2222
|
+
stableFieldReads: stableFieldReadsOf(body, receiverValues, constructionOnlyFields, nativeIntegrityRestricted, dyingArguments),
|
|
1684
2223
|
constructorOf,
|
|
1685
2224
|
ownedDyingValues,
|
|
2225
|
+
transferDyingValues,
|
|
2226
|
+
receiverRenames: receiverRenamesOf(body),
|
|
1686
2227
|
consumingFormalConversions: formalInputs.conversions,
|
|
1687
2228
|
classTableRoots: classTableRootsOf(body),
|
|
1688
|
-
stableBorrowActuals,
|
|
2229
|
+
stableBorrowActuals: stableWithProjections,
|
|
2230
|
+
borrowedArmProjections,
|
|
1689
2231
|
computeOrigins: origins.computeOrigins,
|
|
1690
2232
|
propertyReadOrigins: origins.propertyReadOrigins,
|
|
1691
2233
|
bindingReadDeclarations: origins.bindingReadDeclarations,
|
|
@@ -1694,6 +2236,10 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
1694
2236
|
calleeOnlyValues: origins.calleeOnlyValues,
|
|
1695
2237
|
recordFieldSources: origins.recordFieldSources,
|
|
1696
2238
|
thunkValues: origins.thunkValues,
|
|
2239
|
+
freshReceiverStores: origins.freshReceiverStores,
|
|
2240
|
+
outOfOrderFreshStores: origins.outOfOrderFreshStores,
|
|
2241
|
+
orderedFreshStores: origins.orderedFreshStores,
|
|
2242
|
+
spreadPriorKeys: origins.spreadPriorKeys,
|
|
1697
2243
|
hostClassReads,
|
|
1698
2244
|
classObjectReads,
|
|
1699
2245
|
// Every deferred host member read, decided from the IR, the unioned host
|
|
@@ -1713,7 +2259,7 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
1713
2259
|
directCallees: directCalleeFacts.directCallees,
|
|
1714
2260
|
directCalleeAbis: directCalleeFacts.directCalleeAbis
|
|
1715
2261
|
};
|
|
1716
|
-
const { ctx, prepass } = createEmitContext(body.abi, body.sourceOwner, placements, classes, hosts, deriver, bodyFacts, wellKnownSymbols, captures, symbolKeys, templateObjects, directCallableBindings, virtualDispatch, narrowedFormals, repeatedConstructors, dyingArguments, instantiation, abiOfCallable, functionFacts, hostMethodAliases, callableMemberCandidates, borrowableMemberBodies, stableBorrowEntries, printerDrift, conversions, nativeSelections, callableIdentityDemand, nativeIntegrityRestricted, fixedFieldStateConstant);
|
|
2262
|
+
const { ctx, prepass } = createEmitContext(body.abi, body.sourceOwner, placements, classes, hosts, deriver, bodyFacts, wellKnownSymbols, captures, symbolKeys, templateObjects, directCallableBindings, virtualDispatch, narrowedFormals, repeatedConstructors, dyingArguments, instantiation, abiOfCallable, functionFacts, hostMethodAliases, callableMemberCandidates, borrowableMemberBodies, stableBorrowEntries, printerDrift, conversions, nativeSelections, callableIdentityDemand, nativeIntegrityRestricted, fixedFieldStateConstant, definitionCells, keyOrderUnobserved, taskBodies, fusedAwaitCallsOf(body));
|
|
1717
2263
|
// `ownedValues` stays a genuine render-time OUTPUT buffer (`EmitContext`'s
|
|
1718
2264
|
// own doc: `defineValue` grows it as each operation's result is named) --
|
|
1719
2265
|
// unlike `ownedDyingValues` above, a formal argument's membership in it is
|
|
@@ -1765,6 +2311,11 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
1765
2311
|
// all: both are pure walks over `body` with no dependence on anything a
|
|
1766
2312
|
// printer emits.
|
|
1767
2313
|
const keyTexts = stringConstantsOf(body);
|
|
2314
|
+
const shadowGuardedCallees = new Set();
|
|
2315
|
+
for (const block of body.blocks.values())
|
|
2316
|
+
for (const operation of allOperationsOf(block))
|
|
2317
|
+
if (operation.kind === 'call' && operation.builtinShadowGuard !== undefined)
|
|
2318
|
+
shadowGuardedCallees.add(operation.callee.value);
|
|
1768
2319
|
const capturedQueryCells = new Set();
|
|
1769
2320
|
for (const block of body.blocks.values())
|
|
1770
2321
|
for (const operation of block.operations)
|
|
@@ -1949,7 +2500,14 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
1949
2500
|
? ctx.captures.of(producer.functionId).kind === 'none'
|
|
1950
2501
|
: producer.kind === 'binding-read'
|
|
1951
2502
|
? ctx.directCallableBindings.has(producer.declaration)
|
|
1952
|
-
: producer.kind === 'get' &&
|
|
2503
|
+
: producer.kind === 'get' &&
|
|
2504
|
+
(directClassMethodBody(ctx, producer, keyTexts.get(producer.key.value) ?? null) !== null ||
|
|
2505
|
+
// An overridden method is called `receiver->gea_vcall_m(args)`; the
|
|
2506
|
+
// carrier its read would spell (`nativeClassMethodValue`, a linear
|
|
2507
|
+
// identity-cache scan) is never read. `virtualCalleesOf` admits a
|
|
2508
|
+
// read only when every use is as an immediate callee, and a
|
|
2509
|
+
// `.call`/`.apply` rewrite reads the carrier for its shadow guard.
|
|
2510
|
+
(ctx.virtualCallees.has(producer.result.id) && !shadowGuardedCallees.has(producer.result.id))),
|
|
1953
2511
|
// A named construct entry still reads the constructor's per-evaluation
|
|
1954
2512
|
// prototype owner. Devirtualizing the code pointer cannot discard that
|
|
1955
2513
|
// carrier, even for a class whose methods capture nothing.
|
|
@@ -2014,6 +2572,10 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2014
2572
|
prepass.integerBindings.add(declaration);
|
|
2015
2573
|
for (const [value, form] of settled.remainderForms)
|
|
2016
2574
|
prepass.remainderForms.set(value, form);
|
|
2575
|
+
for (const value of settled.roundingArithmetic)
|
|
2576
|
+
prepass.roundingArithmetic.add(value);
|
|
2577
|
+
for (const [value, limit] of narrowedStorage.guarded ?? [])
|
|
2578
|
+
prepass.integerCallChecks.set(value, limit);
|
|
2017
2579
|
for (const [call, intrinsic] of settled.numericCalls)
|
|
2018
2580
|
prepass.numericCalls.set(call, intrinsic);
|
|
2019
2581
|
for (const value of settled.numericCallOnly)
|
|
@@ -2024,6 +2586,7 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2024
2586
|
// so each branch only assigns the pointee. Kept separate from declarations:
|
|
2025
2587
|
// declarations must remain uninitialized so gotos may cross their scope.
|
|
2026
2588
|
entryPrologue = earlyCapturedCellPrologue(ctx, body);
|
|
2589
|
+
collectCharCodeBuffers(ctx, prepass.deferrable, body);
|
|
2027
2590
|
collectCapacityHints(ctx, prepass, body);
|
|
2028
2591
|
return new Set(ctx.formalCells.keys());
|
|
2029
2592
|
}
|
|
@@ -2059,6 +2622,13 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2059
2622
|
// After the merges, because a block that writes one is not empty.
|
|
2060
2623
|
const flow = threadedFlowOf(ctx, body, orderLabels, hoists, mergeWrites);
|
|
2061
2624
|
const labels = flow.labels;
|
|
2625
|
+
// Blocks are written in a preorder of the rendered graph's dominator tree so
|
|
2626
|
+
// each local can live in the scope of the block that dominates its uses
|
|
2627
|
+
// (`emit-scopes.ts`); a body whose regions render their own control flow
|
|
2628
|
+
// keeps the flat layout.
|
|
2629
|
+
const plan = !isSingleBlock && flow.successors !== null ? scopePlanOf(body.entry, flow.rendered, flow.successors) : null;
|
|
2630
|
+
const layout = plan === null ? { nextLabel: flow.nextLabel, labeled: flow.labeled } : layoutOf(ctx, body, labels, plan.order);
|
|
2631
|
+
const renderedBlocks = new Map();
|
|
2062
2632
|
// A try region's blocks are rendered together, as one `try { } catch (...)
|
|
2063
2633
|
// { }` chunk, by `renderTryRegion` -- never one at a time by the loop below.
|
|
2064
2634
|
// `consumedByRegion` is filled in as each region is rendered, so the loop
|
|
@@ -2078,12 +2648,15 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2078
2648
|
return null;
|
|
2079
2649
|
};
|
|
2080
2650
|
const blocks = [];
|
|
2651
|
+
// The block (a plain block, or a region's entry) each flat artifact in
|
|
2652
|
+
// `blocks` was rendered for -- what `regionScopedBlocksOf` re-nests.
|
|
2653
|
+
const chunkIds = [];
|
|
2081
2654
|
// Invariant 5's seal (`emit-context.ts`'s `sealFactFieldsForRender`): from
|
|
2082
2655
|
// here to the end of the loop every operation renders against a context
|
|
2083
2656
|
// whose facts are settled. Inert unless `GEA_SEAL_EMIT_CONTEXT` is set.
|
|
2084
2657
|
const unseal = sealFactFieldsForRender(ctx);
|
|
2085
2658
|
try {
|
|
2086
|
-
for (const blockId of body.blockOrder) {
|
|
2659
|
+
for (const blockId of plan?.order ?? body.blockOrder) {
|
|
2087
2660
|
if (consumedByRegion.has(blockId))
|
|
2088
2661
|
continue;
|
|
2089
2662
|
const block = body.blocks.get(blockId);
|
|
@@ -2113,13 +2686,13 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2113
2686
|
for (const operation of hoists.into.get(partBlock) ?? [])
|
|
2114
2687
|
emitOperation(partCtx, partLines, operation);
|
|
2115
2688
|
},
|
|
2116
|
-
emitBlockTail: (partCtx, partLines, partBlock) => {
|
|
2689
|
+
emitBlockTail: (partCtx, partLines, partBlock, partLabels) => {
|
|
2117
2690
|
emitDenseSetup(partCtx, partLines, partBlock);
|
|
2118
2691
|
const partFill = partCtx.fillLoops.get(partBlock);
|
|
2119
2692
|
if (!partFill)
|
|
2120
2693
|
return false;
|
|
2121
|
-
emitFillLoop(partCtx, partLines, partFill, requireBlockLabel(
|
|
2122
|
-
return
|
|
2694
|
+
emitFillLoop(partCtx, partLines, partFill, requireBlockLabel(partLabels, partFill.exit));
|
|
2695
|
+
return partFill.kind === 'append';
|
|
2123
2696
|
}
|
|
2124
2697
|
};
|
|
2125
2698
|
const iteratorCloseRegion = iteratorCloseRegionByEntry.get(blockId);
|
|
@@ -2132,6 +2705,7 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2132
2705
|
text: lines.join('\n'),
|
|
2133
2706
|
facts: { kind: 'materialized', representation: { kind: 'void' }, owner, lineage: iteratorCloseRegion.lineage }
|
|
2134
2707
|
});
|
|
2708
|
+
chunkIds.push(blockId);
|
|
2135
2709
|
continue;
|
|
2136
2710
|
}
|
|
2137
2711
|
const region = regionByTryEntry.get(blockId);
|
|
@@ -2144,18 +2718,31 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2144
2718
|
text: lines.join('\n'),
|
|
2145
2719
|
facts: { kind: 'materialized', representation: { kind: 'void' }, owner, lineage: lineageOf(consumed) }
|
|
2146
2720
|
});
|
|
2721
|
+
chunkIds.push(blockId);
|
|
2147
2722
|
continue;
|
|
2148
2723
|
}
|
|
2149
2724
|
if (flow.skipped.has(blockId))
|
|
2150
2725
|
continue;
|
|
2151
2726
|
const lines = [];
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2727
|
+
const label = !isSingleBlock && layout.labeled.has(requireBlockLabel(labels, blockId)) ? requireBlockLabel(labels, blockId) : null;
|
|
2728
|
+
if (label !== null && plan === null)
|
|
2729
|
+
lines.push(`${label}:`);
|
|
2730
|
+
const sunkStores = sunkStoresOf(ctx);
|
|
2731
|
+
const heldStores = new Map();
|
|
2732
|
+
for (const [index, operation] of block.operations.entries()) {
|
|
2733
|
+
const sunk = operation.kind === 'set' ? sunkStores.get(operation.value.value) : undefined;
|
|
2734
|
+
if (sunk !== undefined && sunk.block === blockId) {
|
|
2735
|
+
heldStores.set(sunk.anchor, [...(heldStores.get(sunk.anchor) ?? []), operation]);
|
|
2157
2736
|
continue;
|
|
2158
|
-
|
|
2737
|
+
}
|
|
2738
|
+
const result = 'result' in operation ? operation.result : null;
|
|
2739
|
+
if (!(result && hoists.relocated.has(result.id))) {
|
|
2740
|
+
emitOperation(ctx, lines, operation, (targetLines, terminator) => emitTerminator(ctx, targetLines, labels, isSingleBlock, terminator));
|
|
2741
|
+
}
|
|
2742
|
+
for (const held of heldStores.get(index) ?? []) {
|
|
2743
|
+
emittingSunkStore.add(held);
|
|
2744
|
+
emitOperation(ctx, lines, held);
|
|
2745
|
+
}
|
|
2159
2746
|
}
|
|
2160
2747
|
// AFTER the block's own statements: a preheader assigns the cells a hoisted read names.
|
|
2161
2748
|
for (const operation of hoists.into.get(blockId) ?? [])
|
|
@@ -2168,7 +2755,12 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2168
2755
|
if (converted === null) {
|
|
2169
2756
|
throw createCppEmitBlockedError(`conversion:${representationKey(write.value.representation)}->${representationKey(write.target)}`, `cannot convert merge input from "${representationKey(write.value.representation)}" to "${representationKey(write.target)}"`);
|
|
2170
2757
|
}
|
|
2171
|
-
|
|
2758
|
+
// A dying input MOVES into the merge (`ownedDyingMergeInputsOf`), unless
|
|
2759
|
+
// the hoist plan relocated its definition out of this block: the
|
|
2760
|
+
// predecessor then re-runs without redefining it, and a second visit
|
|
2761
|
+
// would move an emptied value.
|
|
2762
|
+
const moved = converted === raw && !hoists.relocated.has(write.value.value) ? movedValueText(ctx, write.value, write.target, raw) : converted;
|
|
2763
|
+
lines.push(`${write.name} = ${moved};`);
|
|
2172
2764
|
}
|
|
2173
2765
|
// Last of all, so every value a window's condition names -- a hoisted read,
|
|
2174
2766
|
// a merge -- is already assigned in this block.
|
|
@@ -2177,9 +2769,9 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2177
2769
|
const fill = ctx.fillLoops.get(blockId);
|
|
2178
2770
|
if (fill)
|
|
2179
2771
|
emitFillLoop(ctx, lines, fill, requireBlockLabel(labels, fill.exit));
|
|
2180
|
-
|
|
2181
|
-
emitTerminator(ctx, lines, labels, isSingleBlock, block.terminator,
|
|
2182
|
-
|
|
2772
|
+
if (!fill || fill.kind === 'pcm')
|
|
2773
|
+
emitTerminator(ctx, lines, labels, isSingleBlock, block.terminator, layout.nextLabel.get(blockId) ?? null);
|
|
2774
|
+
const artifact = {
|
|
2183
2775
|
text: lines.join('\n'),
|
|
2184
2776
|
facts: {
|
|
2185
2777
|
kind: 'materialized',
|
|
@@ -2194,7 +2786,13 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2194
2786
|
// trace back to the source that produced it.
|
|
2195
2787
|
lineage: allOperationsOf(block).find((operation) => operation.lineage !== null)?.lineage ?? null
|
|
2196
2788
|
}
|
|
2197
|
-
}
|
|
2789
|
+
};
|
|
2790
|
+
if (plan !== null)
|
|
2791
|
+
renderedBlocks.set(blockId, { label, artifact });
|
|
2792
|
+
else {
|
|
2793
|
+
blocks.push(artifact);
|
|
2794
|
+
chunkIds.push(blockId);
|
|
2795
|
+
}
|
|
2198
2796
|
}
|
|
2199
2797
|
}
|
|
2200
2798
|
finally {
|
|
@@ -2218,11 +2816,48 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2218
2816
|
// rendered, and first in the output because a `goto` may not jump into the
|
|
2219
2817
|
// scope of a variable whose declaration initializes it.
|
|
2220
2818
|
const declarationFacts = { kind: 'materialized', representation: { kind: 'void' }, owner, lineage: null };
|
|
2819
|
+
let topDeclarations = ctx.declarations;
|
|
2820
|
+
if (plan !== null && flow.successors !== null) {
|
|
2821
|
+
const nested = nestedBlocksOf(plan, renderedBlocks, labels, flow.successors, ctx.declarations, entryPrologue.join('\n'), declarationFacts);
|
|
2822
|
+
topDeclarations = nested.top;
|
|
2823
|
+
blocks.push(...nested.artifacts);
|
|
2824
|
+
}
|
|
2825
|
+
else if (!isSingleBlock && flow.successors === null) {
|
|
2826
|
+
const nested = regionScopedBlocksOf(body.entry, chunkIds, blocks, labels, ctx.declarations, entryPrologue.join('\n'), declarationFacts);
|
|
2827
|
+
if (nested !== null) {
|
|
2828
|
+
topDeclarations = nested.top;
|
|
2829
|
+
blocks.splice(0, blocks.length, ...nested.artifacts);
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
// A guarded call result the census narrowed is an integer only because the
|
|
2833
|
+
// call site checks it; a result rendered by some other path would be read as
|
|
2834
|
+
// one unchecked. Refuse rather than let that stand.
|
|
2835
|
+
for (const value of ctx.integerCallChecks.keys())
|
|
2836
|
+
if (!ctx.checkedIntegerCalls.has(value) && !ctx.deadValues.has(value) && !ctx.unreadValues.has(value))
|
|
2837
|
+
throw createCppEmitBlockedError('call-abi:unchecked-guarded-integer-result', 'a call result narrowed from its guarded candidate was rendered without the check that makes it an integer');
|
|
2221
2838
|
const declarations = {
|
|
2222
|
-
text:
|
|
2839
|
+
text: topDeclarations.map((entry) => `${entry.type} ${entry.name};`).join('\n'),
|
|
2223
2840
|
facts: declarationFacts
|
|
2224
2841
|
};
|
|
2225
2842
|
const prologue = entryPrologue.length === 0 ? [] : [{ text: entryPrologue.join('\n'), facts: declarationFacts }];
|
|
2843
|
+
// 27.7.5.1 AsyncFunctionStart: an async body's abrupt completion REJECTS its
|
|
2844
|
+
// promise; it never propagates out of the call. An async COROUTINE gets that
|
|
2845
|
+
// from its promise type's `unhandled_exception`, and a `return` inside one
|
|
2846
|
+
// would be ill-formed anyway. An async body with no suspension runs straight
|
|
2847
|
+
// through as a plain function, so a `throw` would otherwise leave the C++
|
|
2848
|
+
// function as an exception, and a caller that only chained `.then(ok, err)`
|
|
2849
|
+
// died of it. The guard encloses every block, so no `goto` crosses into it;
|
|
2850
|
+
// the declarations stay outside, where they already are.
|
|
2851
|
+
if (!ctx.asyncCoroutineBody && body.async === true && body.generator !== true && body.abi?.result.kind === 'promise') {
|
|
2852
|
+
const result = cppTypeOf(body.abi.result);
|
|
2853
|
+
return [
|
|
2854
|
+
declarations,
|
|
2855
|
+
...prologue,
|
|
2856
|
+
{ text: 'try {', facts: declarationFacts },
|
|
2857
|
+
...blocks,
|
|
2858
|
+
{ text: `} catch (...) { return ${result}::rejected_with(std::current_exception()); }`, facts: declarationFacts }
|
|
2859
|
+
];
|
|
2860
|
+
}
|
|
2226
2861
|
return [declarations, ...prologue, ...blocks];
|
|
2227
2862
|
};
|
|
2228
2863
|
// Re-exported so a consumer that emits bodies has one import for the naming
|