@geastack/compiler 1.0.37 → 1.0.38
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 +5 -0
- package/dist/cli.js +10 -0
- package/dist/compiler.d.ts +10 -3
- package/dist/compiler.js +364 -224
- package/dist/conversion/build.d.ts +13 -1
- package/dist/conversion/build.js +336 -141
- package/dist/conversion/graph-validation.d.ts +7 -2
- package/dist/conversion/graph-validation.js +36 -22
- package/dist/conversion/native-sum.js +106 -17
- package/dist/diagnostics/sweep.js +1 -1
- package/dist/ir/callable-class-flow.d.ts +0 -11
- package/dist/ir/callable-class-flow.js +970 -169
- package/dist/ir/certificate.d.ts +1 -1
- package/dist/ir/certificate.js +12 -1
- package/dist/ir/certify/carrier-keys.d.ts +17 -1
- package/dist/ir/certify/carrier-keys.js +35 -2
- package/dist/ir/certify/function-source.js +2 -1
- package/dist/ir/certify/has-property-key.d.ts +6 -0
- package/dist/ir/certify/has-property-key.js +8 -1
- package/dist/ir/certify/property-access-keys.js +2 -1
- package/dist/ir/certify/runtime-helper.js +2 -1
- package/dist/ir/emission-representations.d.ts +2 -2
- package/dist/ir/emission-representations.js +9 -3
- package/dist/ir/generic-call-entry.d.ts +3 -1
- package/dist/ir/logical-receivers.js +29 -1
- package/dist/ir/lower-completion.js +11 -6
- package/dist/ir/lower-destructuring.js +3 -2
- package/dist/ir/native-host-method-reads.d.ts +5 -0
- package/dist/ir/native-host-method-reads.js +30 -21
- package/dist/ir/operation-conversions.js +4 -1
- package/dist/ir/publish-conversion-recipes.js +12 -1
- package/dist/plugins/apple/jsx.js +1 -1
- package/dist/plugins/gea/component-classes.js +1 -1
- package/dist/plugins/gea/component-inline.js +1 -1
- package/dist/plugins/gea/contract.d.ts +1 -1
- package/dist/plugins/gea/contract.js +1 -1
- package/dist/plugins/gea/host.js +27 -1
- package/dist/plugins/gea/lower.js +8 -1
- package/dist/plugins/gea/producer.js +1 -1
- package/dist/plugins/gea/reactive-slots.d.ts +1 -1
- package/dist/plugins/gea/reactive-slots.js +1 -1
- package/dist/plugins/load.js +51 -22
- package/dist/preflight/run.d.ts +12 -1
- package/dist/preflight/run.js +65 -29
- package/dist/projection/native-callable-data.js +2 -1
- package/dist/representation/plan.js +102 -4
- package/dist/semantics/alias-this-field-declaration-transform.js +1 -1
- package/dist/semantics/ambient-type-realization-transform.js +1 -1
- package/dist/semantics/ambient.d.ts +1 -1
- package/dist/semantics/ambient.js +1 -1
- package/dist/semantics/borrowed-builtin-call-bind-source-transform.js +1 -1
- package/dist/semantics/borrowed-method-receiver-copy-source-transform.js +1 -1
- package/dist/semantics/call-invalidated-narrowing.d.ts +1 -1
- package/dist/semantics/call-invalidated-narrowing.js +4 -2
- package/dist/semantics/callable-own-data-slots.d.ts +6 -0
- package/dist/semantics/callable-own-data-slots.js +177 -101
- package/dist/semantics/class-alias.d.ts +1 -1
- package/dist/semantics/class-alias.js +1 -1
- package/dist/semantics/class-heritage.d.ts +1 -1
- package/dist/semantics/class-heritage.js +1 -1
- package/dist/semantics/commonjs-wrapper.d.ts +4 -3
- package/dist/semantics/commonjs-wrapper.js +50 -7
- package/dist/semantics/constructor-function-class-source-transform.js +1 -1
- package/dist/semantics/constructor-slot-subclasses.d.ts +1 -1
- package/dist/semantics/constructor-slot-subclasses.js +1 -1
- package/dist/semantics/declaration-overlay-transform.js +3 -2
- package/dist/semantics/declared-integers.d.ts +1 -1
- package/dist/semantics/declared-integers.js +1 -1
- package/dist/semantics/define-property-source-transform.js +1 -1
- package/dist/semantics/diagnostic-source-preparation.d.ts +1 -1
- package/dist/semantics/documentation-ranges.d.ts +1 -1
- package/dist/semantics/documentation-ranges.js +1 -1
- package/dist/semantics/dynamic-fallback.d.ts +1 -1
- package/dist/semantics/dynamic-fallback.js +1 -1
- package/dist/semantics/frontend-timing.js +19 -0
- package/dist/semantics/frontend.d.ts +2 -2
- package/dist/semantics/frontend.js +127 -54
- package/dist/semantics/host-declaration-provenance.d.ts +1 -1
- package/dist/semantics/host-methods.d.ts +1 -1
- package/dist/semantics/host-methods.js +1 -1
- package/dist/semantics/host-protocols.d.ts +1 -1
- package/dist/semantics/host-protocols.js +1 -1
- package/dist/semantics/inherited-accessor.d.ts +1 -1
- package/dist/semantics/inherited-accessor.js +1 -1
- package/dist/semantics/interface-families.d.ts +1 -1
- package/dist/semantics/interface-families.js +1 -1
- package/dist/semantics/interface-implementors.d.ts +1 -1
- package/dist/semantics/interface-implementors.js +1 -1
- package/dist/semantics/jsdoc-namepath-transform.js +1 -1
- package/dist/semantics/jsx-runtime-provider.d.ts +1 -1
- package/dist/semantics/jsx-runtime-provider.js +1 -1
- package/dist/semantics/known-caller-predicate-parameters.d.ts +1 -1
- package/dist/semantics/known-caller-predicate-parameters.js +1 -1
- package/dist/semantics/model/edges.d.ts +124 -0
- package/dist/semantics/model/edges.js +192 -0
- package/dist/semantics/model/graph.d.ts +26 -2
- package/dist/semantics/model/graph.js +54 -0
- package/dist/semantics/model/sealed-facts.d.ts +19 -0
- package/dist/semantics/model/sealed-facts.js +221 -0
- package/dist/semantics/model/selected-signature.d.ts +1 -1
- package/dist/semantics/model/selected-signature.js +1 -1
- package/dist/semantics/module-resolution.d.ts +1 -1
- package/dist/semantics/module-resolution.js +1 -1
- package/dist/semantics/native-function-signatures.d.ts +1 -1
- package/dist/semantics/native-function-signatures.js +1 -1
- package/dist/semantics/native-object-data-slots.js +20 -4
- package/dist/semantics/new-callee-class-tag-source-transform.js +1 -1
- package/dist/semantics/node-project.d.ts +1 -1
- package/dist/semantics/node-project.js +1 -1
- package/dist/semantics/node-source-hooks.js +1 -1
- package/dist/semantics/normalize/absent-globals.d.ts +1 -1
- package/dist/semantics/normalize/absent-globals.js +1 -1
- package/dist/semantics/normalize/any-cast-member-call.d.ts +1 -1
- package/dist/semantics/normalize/any-cast-member-call.js +1 -1
- package/dist/semantics/normalize/arguments-objects.d.ts +1 -1
- package/dist/semantics/normalize/arguments-objects.js +1 -1
- package/dist/semantics/normalize/asserted-argument-arms.d.ts +1 -1
- package/dist/semantics/normalize/asserted-argument-arms.js +1 -1
- package/dist/semantics/normalize/asserted-arm-absence.d.ts +1 -1
- package/dist/semantics/normalize/asserted-arm-absence.js +1 -1
- package/dist/semantics/normalize/assignment-patterns.d.ts +1 -1
- package/dist/semantics/normalize/assignment-patterns.js +1 -1
- package/dist/semantics/normalize/bag-absence.d.ts +1 -1
- package/dist/semantics/normalize/bag-absence.js +1 -1
- package/dist/semantics/normalize/binding-fixpoint.js +9 -2
- package/dist/semantics/normalize/bivariant-slot-parameter.d.ts +1 -1
- package/dist/semantics/normalize/bivariant-slot-parameter.js +1 -1
- package/dist/semantics/normalize/callable-data-write.d.ts +1 -1
- package/dist/semantics/normalize/callable-data-write.js +1 -1
- package/dist/semantics/normalize/callback-parameter-contracts.d.ts +1 -1
- package/dist/semantics/normalize/callback-parameter-contracts.js +1 -1
- package/dist/semantics/normalize/cells/agreement.d.ts +18 -1
- package/dist/semantics/normalize/cells/agreement.js +8 -0
- package/dist/semantics/normalize/cells/candidates.d.ts +1 -1
- package/dist/semantics/normalize/cells/candidates.js +1 -1
- package/dist/semantics/normalize/cells/facts.d.ts +1 -1
- package/dist/semantics/normalize/cells/facts.js +1 -1
- package/dist/semantics/normalize/cells/index.d.ts +2 -2
- package/dist/semantics/normalize/cells/index.js +1 -1
- package/dist/semantics/normalize/cells/model.d.ts +1 -1
- package/dist/semantics/normalize/cells/policies/bag.d.ts +1 -1
- package/dist/semantics/normalize/cells/policies/collection.d.ts +1 -1
- package/dist/semantics/normalize/cells/policies/collection.js +1 -1
- package/dist/semantics/normalize/cells/policies/field.d.ts +1 -1
- package/dist/semantics/normalize/cells/policies/field.js +1 -1
- package/dist/semantics/normalize/cells/policies/index.d.ts +1 -1
- package/dist/semantics/normalize/cells/policies/local.d.ts +1 -1
- package/dist/semantics/normalize/cells/policies/local.js +1 -1
- package/dist/semantics/normalize/cells/policies/parameter.d.ts +1 -1
- package/dist/semantics/normalize/cells/policies/parameter.js +1 -1
- package/dist/semantics/normalize/cells/policies/return.d.ts +1 -1
- package/dist/semantics/normalize/cells/policies/return.js +1 -1
- package/dist/semantics/normalize/cells/policies/shared.d.ts +1 -1
- package/dist/semantics/normalize/cells/policy.d.ts +1 -1
- package/dist/semantics/normalize/census.d.ts +1 -1
- package/dist/semantics/normalize/census.js +45 -12
- package/dist/semantics/normalize/class-instance-record-statement.d.ts +1 -1
- package/dist/semantics/normalize/class-instance-record-statement.js +1 -1
- package/dist/semantics/normalize/collection-bindings.d.ts +1 -1
- package/dist/semantics/normalize/collection-bindings.js +1 -1
- package/dist/semantics/normalize/commonjs-module-record.d.ts +1 -1
- package/dist/semantics/normalize/commonjs-module-record.js +1 -1
- package/dist/semantics/normalize/commonjs-require.d.ts +1 -1
- package/dist/semantics/normalize/commonjs-require.js +1 -1
- package/dist/semantics/normalize/contribution.d.ts +4 -3
- package/dist/semantics/normalize/contribution.js +145 -42
- package/dist/semantics/normalize/dead-event-emissions.d.ts +1 -1
- package/dist/semantics/normalize/dead-event-emissions.js +1 -1
- package/dist/semantics/normalize/dead-method-copies.d.ts +1 -1
- package/dist/semantics/normalize/dead-method-copies.js +1 -1
- package/dist/semantics/normalize/dead-typeof-guards.d.ts +1 -1
- package/dist/semantics/normalize/dead-typeof-guards.js +1 -1
- package/dist/semantics/normalize/deferred-intrinsic-protocols.d.ts +1 -1
- package/dist/semantics/normalize/deferred-intrinsic-protocols.js +1 -1
- package/dist/semantics/normalize/derived-expression-type.d.ts +1 -1
- package/dist/semantics/normalize/derived-expression-type.js +4 -4
- package/dist/semantics/normalize/evaluation-order.d.ts +1 -1
- package/dist/semantics/normalize/evaluation-order.js +1 -1
- package/dist/semantics/normalize/field-bindings.d.ts +1 -1
- package/dist/semantics/normalize/field-bindings.js +4 -3
- package/dist/semantics/normalize/flow/array-element-continuation.d.ts +1 -1
- package/dist/semantics/normalize/flow/array-element-continuation.js +3 -3
- package/dist/semantics/normalize/flow/callable-array-origins.d.ts +1 -1
- package/dist/semantics/normalize/flow/callable-array-origins.js +1 -1
- package/dist/semantics/normalize/flow/callable-completions.d.ts +1 -1
- package/dist/semantics/normalize/flow/callable-completions.js +1 -1
- package/dist/semantics/normalize/flow/callable-reach.d.ts +1 -1
- package/dist/semantics/normalize/flow/callable-reach.js +73 -52
- package/dist/semantics/normalize/flow/class-family-member-read.d.ts +1 -1
- package/dist/semantics/normalize/flow/class-family-member-read.js +3 -3
- package/dist/semantics/normalize/flow/collection-value-continuation.d.ts +1 -1
- package/dist/semantics/normalize/flow/collection-value-continuation.js +1 -1
- package/dist/semantics/normalize/flow/component-solver.d.ts +181 -3
- package/dist/semantics/normalize/flow/component-solver.js +705 -164
- package/dist/semantics/normalize/flow/computed-key-set.d.ts +1 -1
- package/dist/semantics/normalize/flow/computed-key-set.js +1 -1
- package/dist/semantics/normalize/flow/export-importers.d.ts +1 -1
- package/dist/semantics/normalize/flow/export-importers.js +13 -3
- package/dist/semantics/normalize/flow/host-text-sink.d.ts +1 -1
- package/dist/semantics/normalize/flow/host-text-sink.js +1 -1
- package/dist/semantics/normalize/flow/intrinsic-array-callback-frames.d.ts +1 -1
- package/dist/semantics/normalize/flow/intrinsic-array-callback-frames.js +1 -1
- package/dist/semantics/normalize/flow/intrinsic-data-definition.d.ts +1 -1
- package/dist/semantics/normalize/flow/intrinsic-data-definition.js +1 -1
- package/dist/semantics/normalize/flow/invocation-facts.d.ts +1 -1
- package/dist/semantics/normalize/flow/invocation-facts.js +1 -1
- package/dist/semantics/normalize/flow/member-call-forwarding.d.ts +1 -1
- package/dist/semantics/normalize/flow/member-call-forwarding.js +1 -1
- package/dist/semantics/normalize/flow/model.d.ts +1 -1
- package/dist/semantics/normalize/flow/model.js +5 -1
- package/dist/semantics/normalize/flow/native-collection-protocol.d.ts +1 -1
- package/dist/semantics/normalize/flow/native-collection-protocol.js +1 -1
- package/dist/semantics/normalize/flow/node-path-token.d.ts +1 -1
- package/dist/semantics/normalize/flow/object-binding-continuation.d.ts +1 -1
- package/dist/semantics/normalize/flow/object-binding-continuation.js +1 -1
- package/dist/semantics/normalize/flow/origin-authority.d.ts +1 -1
- package/dist/semantics/normalize/flow/owned-class-receivers.d.ts +1 -1
- package/dist/semantics/normalize/flow/owned-class-receivers.js +1 -1
- package/dist/semantics/normalize/flow/parameter-values.d.ts +1 -1
- package/dist/semantics/normalize/flow/parameter-values.js +1 -1
- package/dist/semantics/normalize/flow/record-alias-closure.d.ts +1 -1
- package/dist/semantics/normalize/flow/record-alias-closure.js +1 -1
- package/dist/semantics/normalize/flow/seeded-origins.d.ts +1 -1
- package/dist/semantics/normalize/flow/seeded-origins.js +1 -1
- package/dist/semantics/normalize/flow/source-accessor-descriptor.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-accessor-descriptor.js +1 -1
- package/dist/semantics/normalize/flow/source-callable-own-data.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-callable-own-data.js +1 -1
- package/dist/semantics/normalize/flow/source-callable-readonly-set.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-callable-readonly-set.js +1 -1
- package/dist/semantics/normalize/flow/source-class-data.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-class-data.js +1 -1
- package/dist/semantics/normalize/flow/source-class-instanceof.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-class-instanceof.js +1 -1
- package/dist/semantics/normalize/flow/source-class-static-data.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-class-static-data.js +1 -1
- package/dist/semantics/normalize/flow/source-commonjs-exports.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-construction-frames.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-construction-frames.js +1 -1
- package/dist/semantics/normalize/flow/source-descriptor-protocol.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-descriptor-protocol.js +1 -1
- package/dist/semantics/normalize/flow/source-executing-parameter-values.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-executing-parameter-values.js +1 -1
- package/dist/semantics/normalize/flow/source-global-binding.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-global-binding.js +1 -1
- package/dist/semantics/normalize/flow/source-intrinsic-member-data.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-intrinsic-member-data.js +1 -1
- package/dist/semantics/normalize/flow/source-invocation-frame-layout.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-invocation-frame-layout.js +24 -32
- package/dist/semantics/normalize/flow/source-invocation-receiver.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-invocation-receiver.js +1 -1
- package/dist/semantics/normalize/flow/source-native-class-alias.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-native-class-alias.js +1 -1
- package/dist/semantics/normalize/flow/source-native-iterable-integrity.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-native-iterable-integrity.js +1 -1
- package/dist/semantics/normalize/flow/source-native-origin.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-native-origin.js +1 -1
- package/dist/semantics/normalize/flow/source-normal-predecessor.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-normal-predecessor.js +1 -1
- package/dist/semantics/normalize/flow/source-property-key.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-property-key.js +1 -1
- package/dist/semantics/normalize/flow/source-prototype-method-identity.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-prototype-method-identity.js +1 -1
- package/dist/semantics/normalize/flow/source-proxy-operation.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-proxy-operation.js +1 -1
- package/dist/semantics/normalize/flow/source-raw-constructor-entry.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-raw-constructor-entry.js +1 -1
- package/dist/semantics/normalize/flow/source-read-protocol.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-read-protocol.js +1 -1
- package/dist/semantics/normalize/flow/source-record-data.d.ts +1 -1
- package/dist/semantics/normalize/flow/source-record-data.js +1 -1
- package/dist/semantics/normalize/flow/source-value-session.d.ts +33 -3
- package/dist/semantics/normalize/flow/source-value-session.js +381 -173
- package/dist/semantics/normalize/flow/standard-prototype-method-source.d.ts +1 -1
- package/dist/semantics/normalize/flow/standard-prototype-method-source.js +1 -1
- package/dist/semantics/normalize/flow/targets.d.ts +1 -1
- package/dist/semantics/normalize/flow/targets.js +1 -1
- package/dist/semantics/normalize/flow/value-flow.d.ts +1 -1
- package/dist/semantics/normalize/flow/value-flow.js +243 -52
- package/dist/semantics/normalize/flow/value-provenance.d.ts +1 -1
- package/dist/semantics/normalize/flow/value-provenance.js +1 -1
- package/dist/semantics/normalize/fresh-dictionary-storage.d.ts +1 -1
- package/dist/semantics/normalize/fresh-dictionary-storage.js +1 -1
- package/dist/semantics/normalize/fresh-ordinary-object.d.ts +1 -1
- package/dist/semantics/normalize/fresh-ordinary-object.js +1 -1
- package/dist/semantics/normalize/fresh-table-last-use.d.ts +1 -1
- package/dist/semantics/normalize/fresh-table-last-use.js +1 -1
- package/dist/semantics/normalize/gating.d.ts +3 -3
- package/dist/semantics/normalize/gating.js +17 -20
- package/dist/semantics/normalize/generic-function-choice.d.ts +1 -1
- package/dist/semantics/normalize/generic-function-choice.js +1 -1
- package/dist/semantics/normalize/global-host-mutations.d.ts +1 -1
- package/dist/semantics/normalize/global-host-mutations.js +420 -138
- package/dist/semantics/normalize/host-effect-contracts.d.ts +1 -1
- package/dist/semantics/normalize/host-effect-contracts.js +1 -1
- package/dist/semantics/normalize/host-mutation-computed-keys.d.ts +1 -1
- package/dist/semantics/normalize/host-mutation-key-reader.d.ts +1 -1
- package/dist/semantics/normalize/host-mutation-key-reader.js +1 -1
- package/dist/semantics/normalize/identities.d.ts +41 -1
- package/dist/semantics/normalize/identities.js +75 -9
- package/dist/semantics/normalize/implicit-arguments-tuple.d.ts +1 -1
- package/dist/semantics/normalize/implicit-arguments-tuple.js +1 -1
- package/dist/semantics/normalize/implicit-arguments.d.ts +1 -1
- package/dist/semantics/normalize/implicit-arguments.js +1 -1
- package/dist/semantics/normalize/installed-global-properties.d.ts +1 -1
- package/dist/semantics/normalize/installed-global-properties.js +1 -1
- package/dist/semantics/normalize/instantiation.d.ts +1 -1
- package/dist/semantics/normalize/instantiation.js +1 -1
- package/dist/semantics/normalize/intrinsic-accessor-getter.d.ts +1 -1
- package/dist/semantics/normalize/intrinsic-accessor-getter.js +1 -1
- package/dist/semantics/normalize/intrinsic-property-call.d.ts +1 -1
- package/dist/semantics/normalize/intrinsic-property-call.js +1 -1
- package/dist/semantics/normalize/intrinsic-prototype.d.ts +1 -1
- package/dist/semantics/normalize/intrinsic-prototype.js +1 -1
- package/dist/semantics/normalize/intrinsic-return-identity.d.ts +1 -1
- package/dist/semantics/normalize/intrinsic-return-identity.js +1 -1
- package/dist/semantics/normalize/intrinsic-static-member.d.ts +1 -1
- package/dist/semantics/normalize/jsdoc-type-names.d.ts +1 -1
- package/dist/semantics/normalize/jsdoc-type-names.js +1 -1
- package/dist/semantics/normalize/local-bindings.d.ts +1 -1
- package/dist/semantics/normalize/local-bindings.js +3 -2
- package/dist/semantics/normalize/logical-object-truthiness.d.ts +1 -1
- package/dist/semantics/normalize/logical-object-truthiness.js +1 -1
- package/dist/semantics/normalize/logical-result-type.d.ts +1 -1
- package/dist/semantics/normalize/logical-result-type.js +1 -1
- package/dist/semantics/normalize/merged-declaration.d.ts +1 -1
- package/dist/semantics/normalize/merged-declaration.js +1 -1
- package/dist/semantics/normalize/namespace-paths.d.ts +1 -1
- package/dist/semantics/normalize/namespace-paths.js +1 -1
- package/dist/semantics/normalize/never-override-result.d.ts +1 -1
- package/dist/semantics/normalize/never-override-result.js +1 -1
- package/dist/semantics/normalize/normalize.d.ts +23 -4
- package/dist/semantics/normalize/normalize.js +125 -15
- package/dist/semantics/normalize/null-blind-parameter.d.ts +1 -1
- package/dist/semantics/normalize/null-blind-parameter.js +1 -1
- package/dist/semantics/normalize/nullable-memo.d.ts +28 -0
- package/dist/semantics/normalize/nullable-memo.js +99 -0
- package/dist/semantics/normalize/object-bag-bindings.d.ts +1 -1
- package/dist/semantics/normalize/object-bag-bindings.js +15 -4
- package/dist/semantics/normalize/omitted-stated-parameter.d.ts +1 -1
- package/dist/semantics/normalize/omitted-stated-parameter.js +1 -1
- package/dist/semantics/normalize/open-type-form.d.ts +1 -1
- package/dist/semantics/normalize/open-type-form.js +1 -1
- package/dist/semantics/normalize/override-field-arms.d.ts +1 -1
- package/dist/semantics/normalize/override-field-arms.js +1 -1
- package/dist/semantics/normalize/parameter-bindings.d.ts +1 -52
- package/dist/semantics/normalize/parameter-bindings.js +105 -10
- package/dist/semantics/normalize/parameter-slot.d.ts +1 -1
- package/dist/semantics/normalize/parameter-slot.js +1 -1
- package/dist/semantics/normalize/physical-overload-result.d.ts +1 -1
- package/dist/semantics/normalize/physical-overload-result.js +1 -1
- package/dist/semantics/normalize/primitive-property-absence.d.ts +1 -1
- package/dist/semantics/normalize/producer-context.d.ts +1 -1
- package/dist/semantics/normalize/producers/allocations.d.ts +1 -1
- package/dist/semantics/normalize/producers/allocations.js +1 -1
- package/dist/semantics/normalize/producers/binding-kind.d.ts +1 -1
- package/dist/semantics/normalize/producers/binding-kind.js +1 -1
- package/dist/semantics/normalize/producers/bindings.d.ts +1 -1
- package/dist/semantics/normalize/producers/bindings.js +1 -1
- package/dist/semantics/normalize/producers/boundary.d.ts +1 -1
- package/dist/semantics/normalize/producers/boundary.js +1 -1
- package/dist/semantics/normalize/producers/cited-value-type.d.ts +1 -1
- package/dist/semantics/normalize/producers/cited-value-type.js +1 -1
- package/dist/semantics/normalize/producers/class-lifecycle.js +1 -1
- package/dist/semantics/normalize/producers/computations.js +1 -1
- package/dist/semantics/normalize/producers/conditional-guard.d.ts +1 -1
- package/dist/semantics/normalize/producers/control-loops.d.ts +1 -1
- package/dist/semantics/normalize/producers/control-loops.js +1 -1
- package/dist/semantics/normalize/producers/control.d.ts +1 -1
- package/dist/semantics/normalize/producers/control.js +1 -1
- package/dist/semantics/normalize/producers/declaration-lifecycle.js +1 -1
- package/dist/semantics/normalize/producers/destructuring.d.ts +1 -1
- package/dist/semantics/normalize/producers/destructuring.js +1 -1
- package/dist/semantics/normalize/producers/dynamic-language.js +1 -1
- package/dist/semantics/normalize/producers/enums.d.ts +1 -1
- package/dist/semantics/normalize/producers/enums.js +1 -1
- package/dist/semantics/normalize/producers/erasure.d.ts +1 -1
- package/dist/semantics/normalize/producers/erasure.js +1 -1
- package/dist/semantics/normalize/producers/exact-arms.d.ts +1 -1
- package/dist/semantics/normalize/producers/exact-arms.js +1 -1
- package/dist/semantics/normalize/producers/intrinsic-accessor-getter.d.ts +1 -1
- package/dist/semantics/normalize/producers/invocations.d.ts +1 -1
- package/dist/semantics/normalize/producers/invocations.js +1 -1
- package/dist/semantics/normalize/producers/iteration-yield.d.ts +1 -1
- package/dist/semantics/normalize/producers/iteration-yield.js +1 -1
- package/dist/semantics/normalize/producers/jsx.js +1 -1
- package/dist/semantics/normalize/producers/logical-merge-type.d.ts +1 -1
- package/dist/semantics/normalize/producers/logical-merge-type.js +1 -1
- package/dist/semantics/normalize/producers/mint.js +88 -5
- package/dist/semantics/normalize/producers/native-callable-readonly-set.d.ts +1 -1
- package/dist/semantics/normalize/producers/native-own-assignment.d.ts +1 -1
- package/dist/semantics/normalize/producers/native-own-assignment.js +1 -1
- package/dist/semantics/normalize/producers/nullish.d.ts +1 -1
- package/dist/semantics/normalize/producers/nullish.js +1 -1
- package/dist/semantics/normalize/producers/object-assignment.d.ts +1 -1
- package/dist/semantics/normalize/producers/object-assignment.js +1 -1
- package/dist/semantics/normalize/producers/object-tag.d.ts +1 -1
- package/dist/semantics/normalize/producers/object-tag.js +1 -1
- package/dist/semantics/normalize/producers/optional-chain.d.ts +1 -1
- package/dist/semantics/normalize/producers/optional-chain.js +1 -1
- package/dist/semantics/normalize/producers/properties.d.ts +1 -1
- package/dist/semantics/normalize/producers/properties.js +1 -1
- package/dist/semantics/normalize/producers/protocol.d.ts +1 -1
- package/dist/semantics/normalize/producers/protocol.js +1 -1
- package/dist/semantics/normalize/producers/references.d.ts +1 -1
- package/dist/semantics/normalize/producers/references.js +1 -1
- package/dist/semantics/normalize/producers/shared.d.ts +1 -1
- package/dist/semantics/normalize/producers/shared.js +1 -1
- package/dist/semantics/normalize/producers/spread-arguments.d.ts +1 -1
- package/dist/semantics/normalize/producers/spread-arguments.js +1 -1
- package/dist/semantics/normalize/producers/tagged-template.d.ts +1 -1
- package/dist/semantics/normalize/producers/tagged-template.js +1 -1
- package/dist/semantics/normalize/producers/tuple-spread.d.ts +1 -1
- package/dist/semantics/normalize/producers/tuple-spread.js +1 -1
- package/dist/semantics/normalize/property-key-domain.d.ts +8 -1
- package/dist/semantics/normalize/property-key-domain.js +74 -47
- package/dist/semantics/normalize/reachability.d.ts +1 -1
- package/dist/semantics/normalize/reachability.js +3 -2
- package/dist/semantics/normalize/reassigned-bindings.d.ts +1 -1
- package/dist/semantics/normalize/record-home-arms.d.ts +1 -1
- package/dist/semantics/normalize/record-home-arms.js +1 -1
- package/dist/semantics/normalize/record-link-families.d.ts +1 -1
- package/dist/semantics/normalize/record-link-families.js +1 -1
- package/dist/semantics/normalize/record-stand-in-arms.d.ts +1 -1
- package/dist/semantics/normalize/record-stand-in-arms.js +1 -1
- package/dist/semantics/normalize/record-storage-families.d.ts +1 -1
- package/dist/semantics/normalize/record-storage-families.js +1 -1
- package/dist/semantics/normalize/return-bindings.d.ts +1 -1
- package/dist/semantics/normalize/return-bindings.js +1 -1
- package/dist/semantics/normalize/return-paths.d.ts +1 -1
- package/dist/semantics/normalize/return-paths.js +1 -1
- package/dist/semantics/normalize/round-tables.d.ts +21 -0
- package/dist/semantics/normalize/round-tables.js +59 -0
- package/dist/semantics/normalize/script-global-redefinition.d.ts +1 -1
- package/dist/semantics/normalize/script-global-redefinition.js +1 -1
- package/dist/semantics/normalize/shared-array-storage.d.ts +1 -1
- package/dist/semantics/normalize/shared-array-storage.js +1 -1
- package/dist/semantics/normalize/sloppy-absence.d.ts +1 -1
- package/dist/semantics/normalize/sloppy-absence.js +1 -1
- package/dist/semantics/normalize/source-native-iterable.d.ts +2 -2
- package/dist/semantics/normalize/source-native-iterable.js +4 -2
- package/dist/semantics/normalize/source-object-prototype-absence.d.ts +1 -1
- package/dist/semantics/normalize/source-object-prototype-absence.js +1 -1
- package/dist/semantics/normalize/specialization.d.ts +1 -1
- package/dist/semantics/normalize/specialization.js +1 -1
- package/dist/semantics/normalize/specialized-source-frames.d.ts +1 -1
- package/dist/semantics/normalize/specialized-source-frames.js +12 -4
- package/dist/semantics/normalize/structural-any-binding-consumer.d.ts +1 -1
- package/dist/semantics/normalize/structural-any-binding-consumer.js +1 -1
- package/dist/semantics/normalize/structural-array-element.d.ts +1 -1
- package/dist/semantics/normalize/structural-array-element.js +1 -1
- package/dist/semantics/normalize/structural-array-read.d.ts +1 -1
- package/dist/semantics/normalize/structural-array-read.js +1 -1
- package/dist/semantics/normalize/structural-callable.d.ts +1 -1
- package/dist/semantics/normalize/structural-callable.js +1 -1
- package/dist/semantics/normalize/structural-creation-order.d.ts +1 -1
- package/dist/semantics/normalize/structural-creation-order.js +1 -1
- package/dist/semantics/normalize/structural-declarations.d.ts +1 -1
- package/dist/semantics/normalize/structural-declarations.js +1 -1
- package/dist/semantics/normalize/structural-declared-body.d.ts +1 -1
- package/dist/semantics/normalize/structural-declared-body.js +1 -1
- package/dist/semantics/normalize/structural-generics.d.ts +1 -1
- package/dist/semantics/normalize/structural-generics.js +1 -1
- package/dist/semantics/normalize/structural-indexed-access.d.ts +1 -1
- package/dist/semantics/normalize/structural-indexed-access.js +1 -1
- package/dist/semantics/normalize/structural-instantiated-member.d.ts +1 -1
- package/dist/semantics/normalize/structural-instantiated-member.js +199 -68
- package/dist/semantics/normalize/structural-joins.d.ts +1 -1
- package/dist/semantics/normalize/structural-layout-relevance.d.ts +1 -1
- package/dist/semantics/normalize/structural-layout-relevance.js +1 -1
- package/dist/semantics/normalize/structural-layout-type.d.ts +1 -1
- package/dist/semantics/normalize/structural-layout-type.js +14 -2
- package/dist/semantics/normalize/structural-leaves.d.ts +1 -1
- package/dist/semantics/normalize/structural-leaves.js +1 -1
- package/dist/semantics/normalize/structural-local-union.d.ts +1 -1
- package/dist/semantics/normalize/structural-local-union.js +21 -16
- package/dist/semantics/normalize/structural-members.d.ts +1 -1
- package/dist/semantics/normalize/structural-members.js +1 -1
- package/dist/semantics/normalize/structural-mutable-field.d.ts +1 -2
- package/dist/semantics/normalize/structural-mutable-field.js +17 -4
- package/dist/semantics/normalize/structural-mutable-method.d.ts +1 -1
- package/dist/semantics/normalize/structural-mutable-method.js +1 -1
- package/dist/semantics/normalize/structural-parts.d.ts +1 -1
- package/dist/semantics/normalize/structural-parts.js +1 -1
- package/dist/semantics/normalize/structural-receiver.d.ts +1 -1
- package/dist/semantics/normalize/structural-receiver.js +1 -1
- package/dist/semantics/normalize/structural-rules.d.ts +4 -4
- package/dist/semantics/normalize/structural-rules.js +30 -12
- package/dist/semantics/normalize/structural-self-reference.d.ts +1 -1
- package/dist/semantics/normalize/structural-self-reference.js +1 -1
- package/dist/semantics/normalize/structural.d.ts +1 -1
- package/dist/semantics/normalize/structural.js +2467 -2239
- package/dist/semantics/normalize/suppressed-write-arms.d.ts +1 -1
- package/dist/semantics/normalize/suppressed-write-arms.js +1 -1
- package/dist/semantics/normalize/symbol-keyed-this-slots.d.ts +1 -1
- package/dist/semantics/normalize/symbol-keyed-this-slots.js +1 -1
- package/dist/semantics/normalize/unreduced-type-form.d.ts +1 -1
- package/dist/semantics/normalize/unreduced-type-form.js +1 -1
- package/dist/semantics/normalize/unresolvable-names.d.ts +1 -1
- package/dist/semantics/normalize/unresolvable-names.js +1 -1
- package/dist/semantics/normalize/unshared-array-result.d.ts +1 -1
- package/dist/semantics/normalize/unshared-array-result.js +1 -1
- package/dist/semantics/package-sources.d.ts +1 -1
- package/dist/semantics/package-sources.js +1 -1
- package/dist/semantics/program.d.ts +1 -1
- package/dist/semantics/program.js +11 -5
- package/dist/semantics/prototype-install-source-transform.js +1 -1
- package/dist/semantics/prototype-object-class-source-transform.js +1 -1
- package/dist/semantics/prototype-reparenting.d.ts +1 -1
- package/dist/semantics/prototype-reparenting.js +1 -1
- package/dist/semantics/shared-declaration-files.d.ts +1 -1
- package/dist/semantics/source-transform-exports.js +1 -1
- package/dist/semantics/stable-checker.d.ts +9 -1
- package/dist/semantics/stable-checker.js +21 -5
- package/dist/semantics/subclass-member-overlay-transform.js +46 -5
- package/dist/semantics/symbol-keyed-expando-source-transform.js +1 -1
- package/dist/semantics/this-constructor-source-transform.js +1 -1
- package/dist/semantics/typescript.d.ts +12 -0
- package/dist/semantics/typescript.js +12 -0
- package/dist/semantics/uncached-jsdoc-tags.d.ts +16 -0
- package/dist/semantics/uncached-jsdoc-tags.js +23 -0
- package/dist/semantics/unchecked-guard-argument-copies.d.ts +1 -1
- package/dist/semantics/unchecked-guard-argument-copies.js +1 -1
- package/dist/semantics/unchecked-write-member-declarations.d.ts +1 -1
- package/dist/semantics/unchecked-write-member-declarations.js +1 -1
- package/dist/semantics/uninstantiable-classes.d.ts +1 -1
- package/dist/semantics/uninstantiable-classes.js +1 -1
- package/dist/targets/cpp/conversions.js +137 -87
- package/dist/targets/cpp/emit-in.js +2 -1
- package/dist/targets/cpp/emit-iterator.d.ts +6 -5
- package/dist/targets/cpp/emit-iterator.js +23 -13
- package/dist/targets/cpp/emit-narrowing.d.ts +8 -0
- package/dist/targets/cpp/emit-narrowing.js +11 -1
- package/dist/targets/cpp/emit-record-view.d.ts +9 -0
- package/dist/targets/cpp/emit-record-view.js +12 -1
- package/package.json +7 -1
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
const NO_GROUNDING_KEYS = [];
|
|
2
|
+
const groundingKeysOf = (node) => {
|
|
3
|
+
const keys = node.groundingKeys;
|
|
4
|
+
if (keys === undefined)
|
|
5
|
+
return NO_GROUNDING_KEYS;
|
|
6
|
+
// Fail closed: keys with no domain to carry are a malformed node, not an empty one.
|
|
7
|
+
if (node.groundingDomain === undefined)
|
|
8
|
+
throw new Error('grounding keys need a grounding domain');
|
|
9
|
+
return Array.isArray(keys) ? keys : [keys];
|
|
10
|
+
};
|
|
1
11
|
/**
|
|
2
12
|
* Solve a lazily discovered dependency graph. `all-dependencies` admits a
|
|
3
13
|
* recursive component when every member has complete local facts and every
|
|
@@ -6,31 +16,68 @@
|
|
|
6
16
|
* a cycle and propagates witnesses over explicitly labelled dependency edges.
|
|
7
17
|
* An acyclic unseeded node remains a complete, vacuous answer.
|
|
8
18
|
*/
|
|
9
|
-
export const dependencyComponentSolver = (expand, mode) =>
|
|
19
|
+
export const dependencyComponentSolver = (expand, mode) => {
|
|
20
|
+
const expanded = new Map();
|
|
21
|
+
return componentEngine({
|
|
22
|
+
slotOf: (key) => {
|
|
23
|
+
let slot = expanded.get(key);
|
|
24
|
+
if (slot === undefined)
|
|
25
|
+
expanded.set(key, (slot = {
|
|
26
|
+
node: expand(key),
|
|
27
|
+
componentRead: false,
|
|
28
|
+
componentAnswer: null,
|
|
29
|
+
groundedInNoDomain: false,
|
|
30
|
+
groundedInFirstDomain: UNSETTLED
|
|
31
|
+
}));
|
|
32
|
+
return slot;
|
|
33
|
+
},
|
|
34
|
+
existingSlotOf: (key) => expanded.get(key),
|
|
35
|
+
localOf: (slot) => slot.node,
|
|
36
|
+
dependenciesOf: (slot) => slot.node.dependencies
|
|
37
|
+
}, mode).solve;
|
|
38
|
+
};
|
|
39
|
+
const componentAnswers = {
|
|
40
|
+
completeGrounded: Object.freeze({ status: 'complete', grounded: true }),
|
|
41
|
+
complete: Object.freeze({ status: 'complete', grounded: false }),
|
|
42
|
+
refusedGrounded: Object.freeze({ status: 'refused', grounded: true }),
|
|
43
|
+
refused: Object.freeze({ status: 'refused', grounded: false })
|
|
44
|
+
};
|
|
45
|
+
const componentAnswer = (complete, grounded) => complete
|
|
46
|
+
? grounded
|
|
47
|
+
? componentAnswers.completeGrounded
|
|
48
|
+
: componentAnswers.complete
|
|
49
|
+
: grounded
|
|
50
|
+
? componentAnswers.refusedGrounded
|
|
51
|
+
: componentAnswers.refused;
|
|
52
|
+
const UNSETTLED = 0;
|
|
53
|
+
const GROUNDED = 1;
|
|
54
|
+
const UNGROUNDED = 2;
|
|
10
55
|
/**
|
|
11
56
|
* The same solver, plus eviction for a graph that keeps growing underneath it.
|
|
12
57
|
* `invalidate` forgets every cached answer that could have read a changed
|
|
13
58
|
* node: the changed nodes themselves and everything that reaches them over
|
|
14
|
-
* required edges. A node nothing cached ever
|
|
59
|
+
* required edges. A node nothing cached ever read cannot have contributed
|
|
15
60
|
* to a cached answer, so the walk stops there. Every other answer is a pure
|
|
16
61
|
* function of nodes that did not change, and stays.
|
|
17
62
|
*/
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
63
|
+
const componentEngine = (graph, mode) => {
|
|
64
|
+
// No `groundedDomains` in an answer. It is a pure function of the graph
|
|
65
|
+
// (`groundingDomainsFrom`, memoized per node), never of how components
|
|
66
|
+
// closed, so storing it per node only meant computing it for every node of
|
|
67
|
+
// every component -- the whole value-origin subgraph walked ~115,000 times
|
|
68
|
+
// on a large program -- when the only places it can change an answer are a
|
|
69
|
+
// cyclic component's requirement check and the published result of a node
|
|
70
|
+
// someone actually asks about.
|
|
71
|
+
const { existingSlotOf, localOf, dependenciesOf } = graph;
|
|
72
|
+
// `groundingDomainsFrom`'s memo: a bit of the node for the empty answer and
|
|
73
|
+
// this table for any other. A field per node holding the set was ~1.8 MB on
|
|
74
|
+
// a 48K-line app's source-value solve (~224K nodes), and a table holding
|
|
75
|
+
// every answer was as large again, since ~45K of them are the empty one.
|
|
76
|
+
const domainsByRoot = new Map();
|
|
29
77
|
const nodeOf = (key) => {
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
nodes.set(key, node);
|
|
78
|
+
const slot = graph.slotOf(key);
|
|
79
|
+
if (!slot.componentRead) {
|
|
80
|
+
slot.componentRead = true;
|
|
34
81
|
// Checked here, once per node, rather than inside the grounding walk.
|
|
35
82
|
// There it was `dependencies.includes(...)` per grounding edge, so a node
|
|
36
83
|
// carrying g grounding edges over d required ones paid g*d comparisons --
|
|
@@ -38,15 +85,20 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
38
85
|
// the node's own dependencies answers all g in O(d + g), and moving the
|
|
39
86
|
// check to expansion makes it cover EVERY node the solver sees instead of
|
|
40
87
|
// only the ones some grounding walk happened to reach.
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
88
|
+
const local = localOf(slot);
|
|
89
|
+
const grounding = local.groundingDependencies;
|
|
90
|
+
const keyed = groundingKeysOf(local);
|
|
91
|
+
if ((grounding !== undefined && grounding.length > 0) || keyed.length > 0) {
|
|
92
|
+
const declared = new Set(dependenciesOf(slot));
|
|
93
|
+
for (const edge of grounding ?? [])
|
|
45
94
|
if (!declared.has(edge.dependency))
|
|
46
95
|
throw new Error('grounding dependency must also be a closure dependency');
|
|
96
|
+
for (const dependency of keyed)
|
|
97
|
+
if (!declared.has(dependency))
|
|
98
|
+
throw new Error('grounding dependency must also be a closure dependency');
|
|
47
99
|
}
|
|
48
100
|
}
|
|
49
|
-
return
|
|
101
|
+
return slot;
|
|
50
102
|
};
|
|
51
103
|
/**
|
|
52
104
|
* Grounding walks only the domain-labelled subgraph, never all closure edges.
|
|
@@ -70,8 +122,24 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
70
122
|
* admitted here unconditionally, before any edge is walked.
|
|
71
123
|
*/
|
|
72
124
|
const NO_DOMAINS = new Set();
|
|
125
|
+
// A node's published grounding is kept for the life of its answer and is
|
|
126
|
+
// nearly always one domain (this compiler has one): one shared set per
|
|
127
|
+
// domain, not one per grounded node.
|
|
128
|
+
const singleDomains = new Map();
|
|
129
|
+
const onlyDomain = (domain) => {
|
|
130
|
+
let set = singleDomains.get(domain);
|
|
131
|
+
if (set === undefined)
|
|
132
|
+
singleDomains.set(domain, (set = new Set([domain])));
|
|
133
|
+
return set;
|
|
134
|
+
};
|
|
73
135
|
const NO_MEMBERS = [];
|
|
74
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Only the components `explain` has something to say about -- an unseeded
|
|
138
|
+
* cycle or an unmet grounding domain -- which is nearly none of them:
|
|
139
|
+
* `explain` reads a component for those two facts alone, so a members list
|
|
140
|
+
* kept for every component was ~190K arrays for nothing.
|
|
141
|
+
*/
|
|
142
|
+
const explained = new Map();
|
|
75
143
|
/**
|
|
76
144
|
* Whether a node reaches a witness of `domain` over edges labelled with
|
|
77
145
|
* `domain`, for every node any walk has settled. A node's own seed counts.
|
|
@@ -92,11 +160,29 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
92
160
|
* (checked in `nodeOf`), so a node whose answer could have read a changed
|
|
93
161
|
* node is one of the required dependents `invalidate` already evicts.
|
|
94
162
|
*/
|
|
163
|
+
let firstDomain;
|
|
95
164
|
const groundedIn = new Map();
|
|
165
|
+
// A settled node is one a walk visited, so it has a slot (`nodeOf`).
|
|
166
|
+
const settledIn = (domain) => {
|
|
167
|
+
firstDomain ??= domain;
|
|
168
|
+
if (domain === firstDomain)
|
|
169
|
+
return {
|
|
170
|
+
get: (key) => {
|
|
171
|
+
const code = existingSlotOf(key)?.groundedInFirstDomain ?? UNSETTLED;
|
|
172
|
+
return code === UNSETTLED ? undefined : code === GROUNDED;
|
|
173
|
+
},
|
|
174
|
+
set: (key, grounded) => {
|
|
175
|
+
existingSlotOf(key).groundedInFirstDomain = grounded ? GROUNDED : UNGROUNDED;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
let table = groundedIn.get(domain);
|
|
179
|
+
if (table === undefined)
|
|
180
|
+
groundedIn.set(domain, (table = new Map()));
|
|
181
|
+
const settled = table;
|
|
182
|
+
return { get: (key) => settled.get(key), set: (key, grounded) => void settled.set(key, grounded) };
|
|
183
|
+
};
|
|
96
184
|
const groundedFor = (domain, start) => {
|
|
97
|
-
|
|
98
|
-
if (settled === undefined)
|
|
99
|
-
groundedIn.set(domain, (settled = new Map()));
|
|
185
|
+
const settled = settledIn(domain);
|
|
100
186
|
const known = settled.get(start);
|
|
101
187
|
if (known !== undefined)
|
|
102
188
|
return known;
|
|
@@ -105,33 +191,40 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
105
191
|
const inRegion = new Set(region);
|
|
106
192
|
const predecessors = new Map();
|
|
107
193
|
const witnesses = [];
|
|
194
|
+
// One grounding edge of `key` in this domain: true when it reaches a settled witness, which ends `key`'s edges.
|
|
195
|
+
const follow = (key, dependency) => {
|
|
196
|
+
const answer = settled.get(dependency);
|
|
197
|
+
if (answer === true) {
|
|
198
|
+
witnesses.push(key);
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
if (answer === false)
|
|
202
|
+
return false;
|
|
203
|
+
let incoming = predecessors.get(dependency);
|
|
204
|
+
if (incoming === undefined)
|
|
205
|
+
predecessors.set(dependency, (incoming = []));
|
|
206
|
+
incoming.push(key);
|
|
207
|
+
if (!inRegion.has(dependency)) {
|
|
208
|
+
inRegion.add(dependency);
|
|
209
|
+
region.push(dependency);
|
|
210
|
+
}
|
|
211
|
+
return false;
|
|
212
|
+
};
|
|
108
213
|
for (let cursor = 0; cursor < region.length; cursor++) {
|
|
109
214
|
const key = region[cursor];
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
215
|
+
const local = localOf(nodeOf(key));
|
|
216
|
+
if (local.groundingSeeds?.includes(domain)) {
|
|
112
217
|
witnesses.push(key);
|
|
113
218
|
continue;
|
|
114
219
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const dependency = edge.dependency;
|
|
119
|
-
const answer = settled.get(dependency);
|
|
120
|
-
if (answer === true) {
|
|
121
|
-
witnesses.push(key);
|
|
220
|
+
let witnessed = false;
|
|
221
|
+
for (const edge of local.groundingDependencies ?? [])
|
|
222
|
+
if (edge.domain === domain && (witnessed = follow(key, edge.dependency)))
|
|
122
223
|
break;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (incoming === undefined)
|
|
128
|
-
predecessors.set(dependency, (incoming = []));
|
|
129
|
-
incoming.push(key);
|
|
130
|
-
if (!inRegion.has(dependency)) {
|
|
131
|
-
inRegion.add(dependency);
|
|
132
|
-
region.push(dependency);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
224
|
+
if (!witnessed && local.groundingDomain === domain)
|
|
225
|
+
for (const dependency of groundingKeysOf(local))
|
|
226
|
+
if (follow(key, dependency))
|
|
227
|
+
break;
|
|
135
228
|
}
|
|
136
229
|
// Backward from the witnesses: everything that reaches one is grounded.
|
|
137
230
|
const grounded = new Set(witnesses);
|
|
@@ -146,17 +239,20 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
146
239
|
return grounded.has(start);
|
|
147
240
|
};
|
|
148
241
|
const groundingDomainsFrom = (root) => {
|
|
149
|
-
const
|
|
242
|
+
const rootSlot = nodeOf(root);
|
|
243
|
+
if (rootSlot.groundedInNoDomain)
|
|
244
|
+
return NO_DOMAINS;
|
|
245
|
+
const known = domainsByRoot.get(root);
|
|
150
246
|
if (known !== undefined)
|
|
151
247
|
return known;
|
|
152
|
-
const rootNode =
|
|
248
|
+
const rootNode = localOf(rootSlot);
|
|
153
249
|
// A node that neither witnesses a domain nor labels an edge with one can
|
|
154
250
|
// only ever answer the empty set, and that is most of them: `seeded-origin`
|
|
155
251
|
// clients (`seeded-origins.ts`) never set a grounding field at all, and a
|
|
156
252
|
// solver is built per query there. Answering without allocating a walk is
|
|
157
253
|
// what keeps this off that path entirely.
|
|
158
|
-
if (!rootNode.groundingSeeds?.length && !rootNode.groundingDependencies?.length) {
|
|
159
|
-
|
|
254
|
+
if (!rootNode.groundingSeeds?.length && !rootNode.groundingDependencies?.length && groundingKeysOf(rootNode).length === 0) {
|
|
255
|
+
rootSlot.groundedInNoDomain = true;
|
|
160
256
|
return NO_DOMAINS;
|
|
161
257
|
}
|
|
162
258
|
// The root's own seeds, whatever their domain, and each domain one of its
|
|
@@ -165,8 +261,16 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
165
261
|
for (const edge of rootNode.groundingDependencies ?? [])
|
|
166
262
|
if (!found.has(edge.domain) && groundedFor(edge.domain, edge.dependency))
|
|
167
263
|
found.add(edge.domain);
|
|
168
|
-
|
|
169
|
-
|
|
264
|
+
const keyedDomain = rootNode.groundingDomain;
|
|
265
|
+
for (const dependency of groundingKeysOf(rootNode))
|
|
266
|
+
if (!found.has(keyedDomain) && groundedFor(keyedDomain, dependency))
|
|
267
|
+
found.add(keyedDomain);
|
|
268
|
+
const answer = found.size === 0 ? NO_DOMAINS : found.size === 1 ? onlyDomain(found.values().next().value) : found;
|
|
269
|
+
if (answer === NO_DOMAINS)
|
|
270
|
+
rootSlot.groundedInNoDomain = true;
|
|
271
|
+
else
|
|
272
|
+
domainsByRoot.set(root, answer);
|
|
273
|
+
return answer;
|
|
170
274
|
};
|
|
171
275
|
const explainFrom = (root) => {
|
|
172
276
|
const paths = new Map([[root, [root]]]);
|
|
@@ -178,7 +282,8 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
178
282
|
const causes = [];
|
|
179
283
|
for (let cursor = 0; cursor < queue.length; cursor++) {
|
|
180
284
|
const key = queue[cursor];
|
|
181
|
-
const
|
|
285
|
+
const slot = nodeOf(key);
|
|
286
|
+
const node = localOf(slot);
|
|
182
287
|
const path = paths.get(key);
|
|
183
288
|
const reasons = node.causes ?? [];
|
|
184
289
|
if (!node.locallyComplete && reasons.length === 0 && !emittedIncomplete.has(key)) {
|
|
@@ -196,7 +301,7 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
196
301
|
causes.push({ kind: 'opaque', root: key, cause, path });
|
|
197
302
|
}
|
|
198
303
|
}
|
|
199
|
-
const component =
|
|
304
|
+
const component = explained.get(key);
|
|
200
305
|
if (component?.unseededCycle && !emittedCycles.has(component)) {
|
|
201
306
|
emittedCycles.add(component);
|
|
202
307
|
causes.push({ kind: 'unseeded-cycle', members: component.members, path });
|
|
@@ -212,7 +317,7 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
212
317
|
causes.push({ kind: 'unseeded-cycle', domain, members: component.members, unmet: component.unmet, path });
|
|
213
318
|
}
|
|
214
319
|
}
|
|
215
|
-
for (const dependency of
|
|
320
|
+
for (const dependency of dependenciesOf(slot)) {
|
|
216
321
|
if (paths.has(dependency))
|
|
217
322
|
continue;
|
|
218
323
|
paths.set(dependency, [...path, dependency]);
|
|
@@ -224,10 +329,11 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
224
329
|
/**
|
|
225
330
|
* A node's published grounding, computed when someone asks for it rather than
|
|
226
331
|
* when its component closed. Same function, same memo, same answer: the walk
|
|
227
|
-
* reads only
|
|
228
|
-
* change what it returns. In `grounding-domains` mode the
|
|
229
|
-
* flag is the domain set's emptiness, exactly as the
|
|
230
|
-
* record it; in the other modes it stays the seed
|
|
332
|
+
* reads only nodes whose facts cannot change while the memo stands, so when
|
|
333
|
+
* it runs cannot change what it returns. In `grounding-domains` mode the
|
|
334
|
+
* legacy aggregate flag is the domain set's emptiness, exactly as the
|
|
335
|
+
* component loop used to record it; in the other modes it stays the seed
|
|
336
|
+
* witness that loop computes.
|
|
231
337
|
*
|
|
232
338
|
* A plain object, not one with accessors. Deferring these two fields behind
|
|
233
339
|
* getters was tried and cost 4.7% of a whole compile in this one function:
|
|
@@ -245,9 +351,10 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
245
351
|
explain: () => explainFrom(root)
|
|
246
352
|
};
|
|
247
353
|
};
|
|
354
|
+
const answerOf = (key) => existingSlotOf(key)?.componentAnswer ?? null;
|
|
248
355
|
const solve = (root) => {
|
|
249
|
-
const known =
|
|
250
|
-
if (known !==
|
|
356
|
+
const known = answerOf(root);
|
|
357
|
+
if (known !== null)
|
|
251
358
|
return publish(root, known);
|
|
252
359
|
const indices = new Map();
|
|
253
360
|
const low = new Map();
|
|
@@ -266,8 +373,8 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
266
373
|
let lowest = index;
|
|
267
374
|
stack.push(key);
|
|
268
375
|
active.add(key);
|
|
269
|
-
for (const dependency of nodeOf(key)
|
|
270
|
-
if (
|
|
376
|
+
for (const dependency of dependenciesOf(nodeOf(key))) {
|
|
377
|
+
if (answerOf(dependency) !== null)
|
|
271
378
|
continue;
|
|
272
379
|
const seen = indices.get(dependency);
|
|
273
380
|
if (seen === undefined) {
|
|
@@ -299,15 +406,16 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
299
406
|
const unseededDomains = new Set();
|
|
300
407
|
const unmet = [];
|
|
301
408
|
for (const current of members) {
|
|
302
|
-
const
|
|
409
|
+
const slot = nodeOf(current);
|
|
410
|
+
const node = localOf(slot);
|
|
303
411
|
complete &&= node.locallyComplete;
|
|
304
412
|
grounded ||= node.seed === true;
|
|
305
|
-
for (const dependency of
|
|
413
|
+
for (const dependency of dependenciesOf(slot)) {
|
|
306
414
|
if (memberSet === null ? dependency === key : memberSet.has(dependency)) {
|
|
307
415
|
cyclic = true;
|
|
308
416
|
continue;
|
|
309
417
|
}
|
|
310
|
-
const dependencyResult =
|
|
418
|
+
const dependencyResult = answerOf(dependency);
|
|
311
419
|
complete &&= dependencyResult?.status === 'complete';
|
|
312
420
|
grounded ||= dependencyResult?.grounded === true;
|
|
313
421
|
}
|
|
@@ -322,7 +430,7 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
322
430
|
if (mode === 'grounding-domains' && complete && cyclic) {
|
|
323
431
|
for (const current of members) {
|
|
324
432
|
const groundedForNode = groundingDomainsFrom(current);
|
|
325
|
-
for (const domain of nodeOf(current).groundingRequirements ?? []) {
|
|
433
|
+
for (const domain of localOf(nodeOf(current)).groundingRequirements ?? []) {
|
|
326
434
|
if (groundedForNode.has(domain))
|
|
327
435
|
continue;
|
|
328
436
|
unseededDomains.add(domain);
|
|
@@ -332,18 +440,20 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
332
440
|
if (unseededDomains.size > 0)
|
|
333
441
|
complete = false;
|
|
334
442
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
443
|
+
const component = unseededDomains.size > 0
|
|
444
|
+
? { members, unseededCycle, unseededDomains, unmet }
|
|
445
|
+
: unseededCycle
|
|
446
|
+
? { members, unseededCycle, unseededDomains: NO_DOMAINS, unmet: NO_MEMBERS }
|
|
447
|
+
: null;
|
|
448
|
+
const answer = componentAnswer(complete, grounded);
|
|
340
449
|
for (const current of members) {
|
|
341
|
-
|
|
342
|
-
|
|
450
|
+
nodeOf(current).componentAnswer = answer;
|
|
451
|
+
if (component !== null)
|
|
452
|
+
explained.set(current, component);
|
|
343
453
|
}
|
|
344
454
|
};
|
|
345
455
|
visit(root);
|
|
346
|
-
return publish(root,
|
|
456
|
+
return publish(root, answerOf(root));
|
|
347
457
|
};
|
|
348
458
|
const invalidate = (changed, requiredDependentsOf) => {
|
|
349
459
|
const queue = [...changed];
|
|
@@ -353,11 +463,15 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
353
463
|
if (seen.has(key))
|
|
354
464
|
continue;
|
|
355
465
|
seen.add(key);
|
|
356
|
-
|
|
466
|
+
const slot = existingSlotOf(key);
|
|
467
|
+
if (slot === undefined || !slot.componentRead)
|
|
357
468
|
continue;
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
469
|
+
slot.componentRead = false;
|
|
470
|
+
slot.componentAnswer = null;
|
|
471
|
+
slot.groundedInNoDomain = false;
|
|
472
|
+
domainsByRoot.delete(key);
|
|
473
|
+
slot.groundedInFirstDomain = UNSETTLED;
|
|
474
|
+
explained.delete(key);
|
|
361
475
|
for (const settled of groundedIn.values())
|
|
362
476
|
settled.delete(key);
|
|
363
477
|
for (const dependent of requiredDependentsOf(key))
|
|
@@ -366,6 +480,294 @@ const invalidatableComponentSolver = (expand, mode) => {
|
|
|
366
480
|
};
|
|
367
481
|
return { solve, invalidate };
|
|
368
482
|
};
|
|
483
|
+
/** Past this many entries an edge collection becomes a hash table: a lookup is a linear scan below it. */
|
|
484
|
+
const SMALL_EDGES = 8;
|
|
485
|
+
const edgeCount = (edges) => edges === null ? 0 : edges instanceof Map || edges instanceof Set ? edges.size : Array.isArray(edges) ? edges.length : 1;
|
|
486
|
+
const NO_EDGE_STATES = [];
|
|
487
|
+
const edgeStates = (edges) => edges === null ? NO_EDGE_STATES : edges instanceof Set || Array.isArray(edges) ? edges : [edges];
|
|
488
|
+
const withDependent = (edges, state) => {
|
|
489
|
+
if (edges === null)
|
|
490
|
+
return state;
|
|
491
|
+
if (edges instanceof Set)
|
|
492
|
+
return edges.add(state);
|
|
493
|
+
const small = Array.isArray(edges) ? edges : [edges];
|
|
494
|
+
return small.length < SMALL_EDGES ? small.concat([state]) : new Set(small).add(state);
|
|
495
|
+
};
|
|
496
|
+
const edgeHas = (edges, state) => edges === null
|
|
497
|
+
? false
|
|
498
|
+
: edges instanceof Set
|
|
499
|
+
? edges.has(state)
|
|
500
|
+
: Array.isArray(edges)
|
|
501
|
+
? edges.includes(state)
|
|
502
|
+
: edges === state;
|
|
503
|
+
/** `withDependent` for a collection that may already hold `state`. */
|
|
504
|
+
const withMember = (edges, state) => edgeHas(edges, state) ? edges : withDependent(edges, state);
|
|
505
|
+
const NO_FACT = Symbol('no fact');
|
|
506
|
+
const NO_FACTS = new Set();
|
|
507
|
+
const INDEXED = 1;
|
|
508
|
+
const COMPONENT_READ = 2;
|
|
509
|
+
/**
|
|
510
|
+
* Every observed edge is required, in the order observed. ~151K of a
|
|
511
|
+
* 48K-line app's ~155K states that require anything require exactly what
|
|
512
|
+
* they observe: a second copy of the edge list, as keys, for each of them.
|
|
513
|
+
*/
|
|
514
|
+
const REQUIRES_OBSERVED = 4;
|
|
515
|
+
/**
|
|
516
|
+
* A state's component answer is one of the four shared `componentAnswers` or
|
|
517
|
+
* none, so it is three bits of `flags` rather than a field: a field is 8 bytes
|
|
518
|
+
* on each of a 48K-line app's ~224K states.
|
|
519
|
+
*/
|
|
520
|
+
const ANSWER_SHIFT = 3;
|
|
521
|
+
const ANSWER_MASK = 7 << ANSWER_SHIFT;
|
|
522
|
+
const answerCodes = [
|
|
523
|
+
null,
|
|
524
|
+
componentAnswers.completeGrounded,
|
|
525
|
+
componentAnswers.complete,
|
|
526
|
+
componentAnswers.refusedGrounded,
|
|
527
|
+
componentAnswers.refused
|
|
528
|
+
];
|
|
529
|
+
/**
|
|
530
|
+
* This state's fact collection may also be another state's, so it is copied
|
|
531
|
+
* before it is written. ~23K of a 48K-line app's ~28K multi-fact states hold
|
|
532
|
+
* the same facts, in the same order, as some other state -- 300K of 335K
|
|
533
|
+
* entries -- mostly because a node forwards what it reads.
|
|
534
|
+
*/
|
|
535
|
+
const SHARED_FACTS = 64;
|
|
536
|
+
/**
|
|
537
|
+
* The required edges are some other list, kept by the solver beside its
|
|
538
|
+
* states (`explicitRequired`) rather than in a field every state pays for:
|
|
539
|
+
* ~4K states of ~224K.
|
|
540
|
+
*/
|
|
541
|
+
const EXPLICIT_REQUIRED = 128;
|
|
542
|
+
/** `groundedInFirstDomain`, two bits of `flags`. */
|
|
543
|
+
const GROUNDED_SHIFT = 8;
|
|
544
|
+
const GROUNDED_MASK = 3 << GROUNDED_SHIFT;
|
|
545
|
+
/** `groundedInNoDomain`. */
|
|
546
|
+
const NO_GROUNDING_DOMAIN = 1 << 10;
|
|
547
|
+
/** A key that is its own state (`keysAreStates`) has been made a node of the solver: `stateOf` has run for it. */
|
|
548
|
+
const MINTED = 1 << 11;
|
|
549
|
+
/** One of the facts a state holds when it holds exactly one, told apart from the collection forms (see `FactState.facts`). */
|
|
550
|
+
const isLoneFact = (value) => typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof Set);
|
|
551
|
+
/**
|
|
552
|
+
* One node of a `dependencyFactSolver`, which is also its own fact set:
|
|
553
|
+
* `read`/`observe` hand the state itself out as the node's live
|
|
554
|
+
* `ReadonlySet`. A consumer may keep that set to compare its size later (the
|
|
555
|
+
* own-key stamps in `source-value-session.ts`), so it has to be one object for
|
|
556
|
+
* the node's life -- and the state already is.
|
|
557
|
+
*
|
|
558
|
+
* The facts are held inline while there is at most one, in a `Set` only from
|
|
559
|
+
* the second. Half the nodes of a 48K-line app's solve hold no fact and a
|
|
560
|
+
* third hold exactly one, and the smallest `Set` is a 152-byte hash table:
|
|
561
|
+
* ~30 MB of tables for ~200K sets of at most one element. Iteration is in
|
|
562
|
+
* insertion order and `has` is SameValueZero, as for a `Set`.
|
|
563
|
+
*
|
|
564
|
+
* A class, so ~224K instances share one shape and one copy of the methods,
|
|
565
|
+
* and so its two booleans can share one field. Abstract over where the key
|
|
566
|
+
* lives: a caller that interns one record per key can make that record the
|
|
567
|
+
* state itself (`keysAreStates`), and a key record and a state per node were
|
|
568
|
+
* two headers and a pointer each way -- ~9 MB on a 48K-line app.
|
|
569
|
+
*/
|
|
570
|
+
export class FactState {
|
|
571
|
+
/**
|
|
572
|
+
* Every scheduled edge, holding the dependency's STATE and not just its
|
|
573
|
+
* key. A transfer re-reads the same edges on every re-evaluation, so
|
|
574
|
+
* resolving the key through the global state map each time was a lookup
|
|
575
|
+
* per edge read across the whole solve -- the single largest self-time
|
|
576
|
+
* entry in a large program's profile. The owner already has to touch this
|
|
577
|
+
* collection to know the edge exists; carrying the state in it makes the
|
|
578
|
+
* repeat read free.
|
|
579
|
+
*
|
|
580
|
+
* This and the two edge collections below are null until the first edge
|
|
581
|
+
* that would go in them, a lone state or an exactly sized array while they
|
|
582
|
+
* are small, and a hash table only past `SMALL_EDGES`. A 48K-line app's
|
|
583
|
+
* solve holds ~224K states; three quarters of them have at most one edge
|
|
584
|
+
* of each kind, and a one-entry Map or Set is ~180 bytes of hash table:
|
|
585
|
+
* ~90 MB of tables for edges a field holds in 8. Insertion order, which
|
|
586
|
+
* `propagate`'s wake-ups and `explain`'s paths follow, is the same in
|
|
587
|
+
* every form.
|
|
588
|
+
*
|
|
589
|
+
* Observed edges never become a table: past `SMALL_EDGES` they are an
|
|
590
|
+
* array of this state's own, grown by `push`, and whether an edge exists is
|
|
591
|
+
* asked of the dependency's `dependents` instead (`observedState`). A
|
|
592
|
+
* key-to-state Map was ~1.3 KB a state for the ~4K states that observe
|
|
593
|
+
* more than eight.
|
|
594
|
+
*/
|
|
595
|
+
observedDependencies = null;
|
|
596
|
+
/**
|
|
597
|
+
* Dependents, held as states for the same reason `key` is: `propagate`
|
|
598
|
+
* fires an edge by re-enqueuing its owner, and it already holds that
|
|
599
|
+
* owner's state from the moment the edge was recorded.
|
|
600
|
+
*/
|
|
601
|
+
dependents = null;
|
|
602
|
+
/** The last seal, which the component solve reads as this node's local facts. */
|
|
603
|
+
sealed = undefined;
|
|
604
|
+
flags = 0;
|
|
605
|
+
/**
|
|
606
|
+
* No fact, one fact held as itself, two to `SMALL_EDGES` facts in an
|
|
607
|
+
* exactly sized array, more in a `Set`: ~22K of a 48K-line app's ~28K
|
|
608
|
+
* multi-fact states hold at most eight, and the smallest `Set` holding two
|
|
609
|
+
* is ~180 bytes of hash table. One field for all four forms rather than one
|
|
610
|
+
* for the lone fact and one for the collection: a lone fact that could be
|
|
611
|
+
* mistaken for a collection (`isLoneFact`) is held as a one-element array.
|
|
612
|
+
*/
|
|
613
|
+
facts = NO_FACT;
|
|
614
|
+
/** Seeded: this state's facts are visible to `holdersOf`. */
|
|
615
|
+
get indexed() {
|
|
616
|
+
return (this.flags & INDEXED) !== 0;
|
|
617
|
+
}
|
|
618
|
+
set indexed(value) {
|
|
619
|
+
this.flags = value ? this.flags | INDEXED : this.flags & ~INDEXED;
|
|
620
|
+
}
|
|
621
|
+
get requiresObserved() {
|
|
622
|
+
return (this.flags & REQUIRES_OBSERVED) !== 0;
|
|
623
|
+
}
|
|
624
|
+
set requiresObserved(value) {
|
|
625
|
+
this.flags = value ? this.flags | REQUIRES_OBSERVED : this.flags & ~REQUIRES_OBSERVED;
|
|
626
|
+
}
|
|
627
|
+
get groundedInFirstDomain() {
|
|
628
|
+
return ((this.flags & GROUNDED_MASK) >> GROUNDED_SHIFT);
|
|
629
|
+
}
|
|
630
|
+
set groundedInFirstDomain(value) {
|
|
631
|
+
this.flags = (this.flags & ~GROUNDED_MASK) | (value << GROUNDED_SHIFT);
|
|
632
|
+
}
|
|
633
|
+
get groundedInNoDomain() {
|
|
634
|
+
return (this.flags & NO_GROUNDING_DOMAIN) !== 0;
|
|
635
|
+
}
|
|
636
|
+
set groundedInNoDomain(value) {
|
|
637
|
+
this.flags = value ? this.flags | NO_GROUNDING_DOMAIN : this.flags & ~NO_GROUNDING_DOMAIN;
|
|
638
|
+
}
|
|
639
|
+
get minted() {
|
|
640
|
+
return (this.flags & MINTED) !== 0;
|
|
641
|
+
}
|
|
642
|
+
set minted(value) {
|
|
643
|
+
this.flags = value ? this.flags | MINTED : this.flags & ~MINTED;
|
|
644
|
+
}
|
|
645
|
+
get explicitRequired() {
|
|
646
|
+
return (this.flags & EXPLICIT_REQUIRED) !== 0;
|
|
647
|
+
}
|
|
648
|
+
set explicitRequired(value) {
|
|
649
|
+
this.flags = value ? this.flags | EXPLICIT_REQUIRED : this.flags & ~EXPLICIT_REQUIRED;
|
|
650
|
+
}
|
|
651
|
+
get componentAnswer() {
|
|
652
|
+
return answerCodes[(this.flags & ANSWER_MASK) >> ANSWER_SHIFT];
|
|
653
|
+
}
|
|
654
|
+
set componentAnswer(answer) {
|
|
655
|
+
const code = answerCodes.indexOf(answer);
|
|
656
|
+
// Fail closed: only the shared answers have a code.
|
|
657
|
+
if (code < 0)
|
|
658
|
+
throw new Error('component answer is not one of the shared answers');
|
|
659
|
+
this.flags = (this.flags & ~ANSWER_MASK) | (code << ANSWER_SHIFT);
|
|
660
|
+
}
|
|
661
|
+
get componentRead() {
|
|
662
|
+
return (this.flags & COMPONENT_READ) !== 0;
|
|
663
|
+
}
|
|
664
|
+
set componentRead(value) {
|
|
665
|
+
this.flags = value ? this.flags | COMPONENT_READ : this.flags & ~COMPONENT_READ;
|
|
666
|
+
}
|
|
667
|
+
get size() {
|
|
668
|
+
const facts = this.facts;
|
|
669
|
+
if (facts === NO_FACT)
|
|
670
|
+
return 0;
|
|
671
|
+
if (Array.isArray(facts))
|
|
672
|
+
return facts.length;
|
|
673
|
+
return facts instanceof Set ? facts.size : 1;
|
|
674
|
+
}
|
|
675
|
+
has(value) {
|
|
676
|
+
const facts = this.facts;
|
|
677
|
+
if (facts === NO_FACT)
|
|
678
|
+
return false;
|
|
679
|
+
// `includes` is SameValueZero, as `Set.prototype.has` is.
|
|
680
|
+
if (Array.isArray(facts))
|
|
681
|
+
return facts.includes(value);
|
|
682
|
+
if (facts instanceof Set)
|
|
683
|
+
return facts.has(value);
|
|
684
|
+
// A lone fact is an object (`isLoneFact`), so identity is SameValueZero here.
|
|
685
|
+
return facts === value;
|
|
686
|
+
}
|
|
687
|
+
add(value) {
|
|
688
|
+
const facts = this.facts;
|
|
689
|
+
if (facts === NO_FACT) {
|
|
690
|
+
this.facts = isLoneFact(value) ? value : [value];
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
if (facts instanceof Set) {
|
|
694
|
+
if ((this.flags & SHARED_FACTS) === 0) {
|
|
695
|
+
facts.add(value);
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
if (facts.has(value))
|
|
699
|
+
return;
|
|
700
|
+
this.facts = new Set(facts).add(value);
|
|
701
|
+
this.flags &= ~SHARED_FACTS;
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
if (this.has(value))
|
|
705
|
+
return;
|
|
706
|
+
// A new array rather than a push: a pushed array keeps growth slack,
|
|
707
|
+
// and no reader iterates a state's facts while they are added
|
|
708
|
+
// (`factsFrom`), so a replaced array is never mid-iteration.
|
|
709
|
+
const small = Array.isArray(facts) ? facts : [facts];
|
|
710
|
+
this.facts = small.length < SMALL_EDGES ? small.concat([value]) : new Set(small).add(value);
|
|
711
|
+
this.flags &= ~SHARED_FACTS;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Holds `other`'s fact collection when it is the same facts in the same
|
|
715
|
+
* order, so iteration is unchanged; both are marked shared, and `add`
|
|
716
|
+
* copies a shared `Set` before writing it (an array is never written: it is
|
|
717
|
+
* replaced). Only collections are shared: none or a lone fact costs nothing.
|
|
718
|
+
*/
|
|
719
|
+
shareFactsOf(other) {
|
|
720
|
+
const mine = this.facts;
|
|
721
|
+
const theirs = other.facts;
|
|
722
|
+
if (mine === theirs)
|
|
723
|
+
return true;
|
|
724
|
+
if (!(mine instanceof Set || Array.isArray(mine)) || !(theirs instanceof Set || Array.isArray(theirs)))
|
|
725
|
+
return false;
|
|
726
|
+
if (this.size !== other.size)
|
|
727
|
+
return false;
|
|
728
|
+
const left = mine.values();
|
|
729
|
+
const right = theirs.values();
|
|
730
|
+
for (let a = left.next(), b = right.next(); !a.done; a = left.next(), b = right.next())
|
|
731
|
+
if (a.value !== b.value)
|
|
732
|
+
return false;
|
|
733
|
+
this.facts = theirs;
|
|
734
|
+
this.flags |= SHARED_FACTS;
|
|
735
|
+
other.flags |= SHARED_FACTS;
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
values() {
|
|
739
|
+
const facts = this.facts;
|
|
740
|
+
if (facts === NO_FACT)
|
|
741
|
+
return NO_FACTS.values();
|
|
742
|
+
if (Array.isArray(facts) || facts instanceof Set)
|
|
743
|
+
return facts.values();
|
|
744
|
+
return [facts].values();
|
|
745
|
+
}
|
|
746
|
+
keys() {
|
|
747
|
+
return this.values();
|
|
748
|
+
}
|
|
749
|
+
[Symbol.iterator]() {
|
|
750
|
+
return this.values();
|
|
751
|
+
}
|
|
752
|
+
entries() {
|
|
753
|
+
const facts = this.facts;
|
|
754
|
+
if (facts instanceof Set)
|
|
755
|
+
return facts.entries();
|
|
756
|
+
return [...this.values()].map((value) => [value, value]).values();
|
|
757
|
+
}
|
|
758
|
+
forEach(callback, thisArg) {
|
|
759
|
+
for (const value of this)
|
|
760
|
+
callback.call(thisArg, value, value, this);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
/** A state for a key that cannot hold one, kept in the solver's own table. */
|
|
764
|
+
class KeyedFactState extends FactState {
|
|
765
|
+
solverKey;
|
|
766
|
+
constructor(solverKey) {
|
|
767
|
+
super();
|
|
768
|
+
this.solverKey = solverKey;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
369
771
|
/** `GEA_SOLVER_COUNTS` exit reports of the solvers still alive at exit. */
|
|
370
772
|
const exitReports = new Set();
|
|
371
773
|
if (process.env['GEA_SOLVER_COUNTS'] !== undefined)
|
|
@@ -373,8 +775,114 @@ if (process.env['GEA_SOLVER_COUNTS'] !== undefined)
|
|
|
373
775
|
for (const report of exitReports)
|
|
374
776
|
report.deref()?.();
|
|
375
777
|
});
|
|
376
|
-
|
|
377
|
-
|
|
778
|
+
/**
|
|
779
|
+
* `expand` is either one definition for every node (its callbacks are handed
|
|
780
|
+
* the node's key) or a function minting one per node, called once as the node
|
|
781
|
+
* is created.
|
|
782
|
+
*
|
|
783
|
+
* With `keysAreStates`, every key is a `FactState` subclass instance the
|
|
784
|
+
* caller interned once per question, and the key is the node's state: a table
|
|
785
|
+
* keyed by key costs a hash entry per node -- ~7 MB of table for a 48K-line
|
|
786
|
+
* app's ~224K nodes -- and a separate state per key a header and two pointers.
|
|
787
|
+
* Such keys must be private to one solver. Otherwise states are kept in a
|
|
788
|
+
* table keyed by key.
|
|
789
|
+
*/
|
|
790
|
+
export const dependencyFactSolver = (expand, mode, keysAreStates = false) => {
|
|
791
|
+
const table = keysAreStates ? null : new Map();
|
|
792
|
+
const existingStateOf = (key) => {
|
|
793
|
+
if (table !== null)
|
|
794
|
+
return table.get(key);
|
|
795
|
+
const state = key;
|
|
796
|
+
return state.minted ? state : undefined;
|
|
797
|
+
};
|
|
798
|
+
let stateCount = 0;
|
|
799
|
+
// Every state, for the `GEA_SOLVER_SIZES` report alone: keys that are states have no iteration.
|
|
800
|
+
const everyState = process.env['GEA_SOLVER_SIZES'] === undefined ? null : [];
|
|
801
|
+
// A definition per key is kept beside the states only for a caller that
|
|
802
|
+
// supplies one; a shared definition is not stored per state at all.
|
|
803
|
+
const definitions = typeof expand === 'function' ? new Map() : null;
|
|
804
|
+
const definitionOf = (state) => definitions === null ? expand : definitions.get(state.solverKey);
|
|
805
|
+
const observedState = (owner, dependency) => {
|
|
806
|
+
const observed = owner.observedDependencies;
|
|
807
|
+
if (observed === null)
|
|
808
|
+
return undefined;
|
|
809
|
+
if (!Array.isArray(observed))
|
|
810
|
+
return observed.solverKey === dependency ? observed : undefined;
|
|
811
|
+
if (observed.length <= SMALL_EDGES) {
|
|
812
|
+
for (const candidate of observed)
|
|
813
|
+
if (candidate.solverKey === dependency)
|
|
814
|
+
return candidate;
|
|
815
|
+
return undefined;
|
|
816
|
+
}
|
|
817
|
+
// An owner is among a dependency's dependents exactly when it observes
|
|
818
|
+
// it: the two edges are only ever added together (`factsFrom`).
|
|
819
|
+
const state = existingStateOf(dependency);
|
|
820
|
+
return state !== undefined && edgeHas(state.dependents, owner) ? state : undefined;
|
|
821
|
+
};
|
|
822
|
+
const withObserved = (observed, dependencyState) => {
|
|
823
|
+
if (observed === null)
|
|
824
|
+
return dependencyState;
|
|
825
|
+
if (!Array.isArray(observed))
|
|
826
|
+
return [observed, dependencyState];
|
|
827
|
+
if (observed.length < SMALL_EDGES)
|
|
828
|
+
return observed.concat([dependencyState]);
|
|
829
|
+
// Past `SMALL_EDGES` the array is this state's own (copied once, here) and grows in place.
|
|
830
|
+
if (observed.length === SMALL_EDGES)
|
|
831
|
+
return [...observed, dependencyState];
|
|
832
|
+
observed.push(dependencyState);
|
|
833
|
+
return observed;
|
|
834
|
+
};
|
|
835
|
+
// A key is held alone only when it cannot be mistaken for a collection of
|
|
836
|
+
// keys: an object that is neither an array nor a `Set`. Any other key (none
|
|
837
|
+
// in this solver's one caller) takes the one-element array it always had.
|
|
838
|
+
const loneRequired = (dependency) => typeof dependency === 'object' && dependency !== null && !Array.isArray(dependency) && !(dependency instanceof Set);
|
|
839
|
+
const explicitRequired = new Map();
|
|
840
|
+
const explicitRequiredOf = (state) => (state.explicitRequired ? explicitRequired.get(state) : null);
|
|
841
|
+
const setExplicitRequired = (state, required) => {
|
|
842
|
+
if (required === null)
|
|
843
|
+
return;
|
|
844
|
+
explicitRequired.set(state, required);
|
|
845
|
+
state.explicitRequired = true;
|
|
846
|
+
};
|
|
847
|
+
// A dependent of `dependency` observes it, so under `requiresObserved` it also requires it.
|
|
848
|
+
const isRequired = (state, dependency) => {
|
|
849
|
+
if (state.requiresObserved)
|
|
850
|
+
return observedState(state, dependency) !== undefined;
|
|
851
|
+
const required = explicitRequiredOf(state);
|
|
852
|
+
if (required === null)
|
|
853
|
+
return false;
|
|
854
|
+
if (required instanceof Set)
|
|
855
|
+
return required.has(dependency);
|
|
856
|
+
if (Array.isArray(required))
|
|
857
|
+
return required.includes(dependency);
|
|
858
|
+
return required === dependency;
|
|
859
|
+
};
|
|
860
|
+
const withRequired = (required, dependency) => {
|
|
861
|
+
if (required === null)
|
|
862
|
+
return loneRequired(dependency) ? dependency : [dependency];
|
|
863
|
+
if (required instanceof Set)
|
|
864
|
+
return required.add(dependency);
|
|
865
|
+
const small = Array.isArray(required) ? required : [required];
|
|
866
|
+
return small.length < SMALL_EDGES ? small.concat([dependency]) : new Set(small).add(dependency);
|
|
867
|
+
};
|
|
868
|
+
// A copy for an array: a long one grows in place while its owner runs.
|
|
869
|
+
const observedKeys = (observed) => observed === null
|
|
870
|
+
? NO_DEPENDENCIES
|
|
871
|
+
: Array.isArray(observed)
|
|
872
|
+
? observed.map((state) => state.solverKey)
|
|
873
|
+
: [observed.solverKey];
|
|
874
|
+
const requiredOf = (state) => {
|
|
875
|
+
if (state === undefined)
|
|
876
|
+
return NO_DEPENDENCIES;
|
|
877
|
+
if (state.requiresObserved)
|
|
878
|
+
return observedKeys(state.observedDependencies);
|
|
879
|
+
const required = explicitRequiredOf(state);
|
|
880
|
+
return required === null
|
|
881
|
+
? NO_DEPENDENCIES
|
|
882
|
+
: required instanceof Set || Array.isArray(required)
|
|
883
|
+
? required
|
|
884
|
+
: [required];
|
|
885
|
+
};
|
|
378
886
|
// States, not keys: `propagate` used to hold keys and call `stateOf(key)`
|
|
379
887
|
// on every drain, a Map lookup per edge fire across a large program's millions
|
|
380
888
|
// of observe edges. The State is already in hand wherever an edge fires or is
|
|
@@ -391,29 +899,28 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
391
899
|
// after the drain and needs to know what the drain touched.
|
|
392
900
|
const sealDirty = new Set();
|
|
393
901
|
const enqueue = (state) => {
|
|
394
|
-
sealDirty.add(state.
|
|
902
|
+
sealDirty.add(state.solverKey);
|
|
395
903
|
if (queued.has(state))
|
|
396
904
|
return;
|
|
397
905
|
queued.add(state);
|
|
398
906
|
queue.push(state);
|
|
399
907
|
};
|
|
400
908
|
const stateOf = (key) => {
|
|
401
|
-
let state =
|
|
909
|
+
let state = existingStateOf(key);
|
|
402
910
|
if (state === undefined) {
|
|
403
911
|
// No edge readers kept on the state: three closures and their context
|
|
404
912
|
// for the life of every state, when only a running transfer or seal ever
|
|
405
913
|
// calls them. `transferOf`/`sealOf` mint them for that call.
|
|
406
|
-
const built =
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
observedDependencies: null,
|
|
410
|
-
requiredDependencies: null,
|
|
411
|
-
facts: new Set(),
|
|
412
|
-
dependents: null,
|
|
413
|
-
indexed: false
|
|
414
|
-
};
|
|
914
|
+
const built = table !== null ? new KeyedFactState(key) : key;
|
|
915
|
+
if (definitions !== null)
|
|
916
|
+
definitions.set(key, expand(key));
|
|
415
917
|
state = built;
|
|
416
|
-
|
|
918
|
+
if (table !== null)
|
|
919
|
+
table.set(key, built);
|
|
920
|
+
else
|
|
921
|
+
built.minted = true;
|
|
922
|
+
stateCount++;
|
|
923
|
+
everyState?.push(built);
|
|
417
924
|
enqueue(built);
|
|
418
925
|
}
|
|
419
926
|
return state;
|
|
@@ -431,7 +938,7 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
431
938
|
return;
|
|
432
939
|
state.indexed = true;
|
|
433
940
|
// Facts it published before it was seeded never reached the index.
|
|
434
|
-
for (const fact of state
|
|
941
|
+
for (const fact of state)
|
|
435
942
|
index(state, fact);
|
|
436
943
|
};
|
|
437
944
|
// The reverse of `observedDependencies`/`dependents`: every state that has
|
|
@@ -439,6 +946,8 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
439
946
|
// `holdersOf` about it. Only seeded states publish here (see
|
|
440
947
|
// `DependencyFactHoldersOf`), so its size is bounded by the candidates'
|
|
441
948
|
// facts, not by every (state, fact) pair in the program.
|
|
949
|
+
// Each in the small edge forms (`EdgeStates`): ~12K of these sets on a
|
|
950
|
+
// 48K-line app, most holding a few states, at ~200 bytes of table apiece.
|
|
442
951
|
const holders = new Map();
|
|
443
952
|
const valueSubscribers = new Map();
|
|
444
953
|
// A node that asked `holdersOf(fact)` before this state held it named no
|
|
@@ -448,33 +957,33 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
448
957
|
// answer forever and never be asked again, which is the silently-wrong
|
|
449
958
|
// result SEMANTIC-AUTHORITY ranks below a slow one.
|
|
450
959
|
const index = (state, fact) => {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
960
|
+
const holding = holders.get(fact) ?? null;
|
|
961
|
+
const held = withMember(holding, state);
|
|
962
|
+
if (held !== holding)
|
|
963
|
+
holders.set(fact, held);
|
|
455
964
|
const subscribers = valueSubscribers.get(fact);
|
|
456
965
|
if (subscribers !== undefined)
|
|
457
|
-
for (const subscriber of subscribers)
|
|
966
|
+
for (const subscriber of edgeStates(subscribers))
|
|
458
967
|
enqueue(subscriber);
|
|
459
968
|
};
|
|
460
969
|
const NO_HOLDERS = [];
|
|
461
970
|
const holdersOfFrom = (ownerState, fact) => {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
971
|
+
const subscribers = valueSubscribers.get(fact) ?? null;
|
|
972
|
+
const subscribed = withMember(subscribers, ownerState);
|
|
973
|
+
if (subscribed !== subscribers)
|
|
974
|
+
valueSubscribers.set(fact, subscribed);
|
|
975
|
+
// Idempotent by construction (a membership test), so re-asking on every re-evaluation
|
|
466
976
|
// of the same node costs a lookup and nothing else -- no revision to bump,
|
|
467
977
|
// no queue entry to make, because registering the subscription changes
|
|
468
978
|
// nothing about what THIS transfer already computed with the holders it
|
|
469
979
|
// just read below. It only matters for facts published AFTER this call,
|
|
470
980
|
// which `propagate` below wakes through this same set.
|
|
471
|
-
subscribers.add(ownerState);
|
|
472
981
|
const holding = holders.get(fact);
|
|
473
982
|
if (holding === undefined)
|
|
474
983
|
return NO_HOLDERS;
|
|
475
984
|
const found = [];
|
|
476
|
-
for (const holder of holding)
|
|
477
|
-
found.push(holder.
|
|
985
|
+
for (const holder of edgeStates(holding))
|
|
986
|
+
found.push(holder.solverKey);
|
|
478
987
|
return found;
|
|
479
988
|
};
|
|
480
989
|
// The owner's state is handed in rather than looked up: every transfer and
|
|
@@ -482,31 +991,43 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
482
991
|
// for a state the caller is already holding was, on a large program, a quarter
|
|
483
992
|
// of the whole compile.
|
|
484
993
|
const factsFrom = (ownerState, dependency, required) => {
|
|
485
|
-
let
|
|
486
|
-
let dependencyState = observed === null ? undefined : observed.get(dependency);
|
|
994
|
+
let dependencyState = observedState(ownerState, dependency);
|
|
487
995
|
let changed = false;
|
|
996
|
+
// While every edge so far was required (a first edge that is required
|
|
997
|
+
// starts it), a required new edge keeps `requiresObserved`. The first new
|
|
998
|
+
// edge that is only observed ends it: the required edges are then exactly
|
|
999
|
+
// the ones observed so far, in that order, and from here on are kept in
|
|
1000
|
+
// `explicitRequired`.
|
|
1001
|
+
let joinsObserved = false;
|
|
488
1002
|
if (dependencyState === undefined) {
|
|
1003
|
+
if (required)
|
|
1004
|
+
joinsObserved = ownerState.requiresObserved || ownerState.observedDependencies === null;
|
|
1005
|
+
else if (ownerState.requiresObserved) {
|
|
1006
|
+
let materialized = null;
|
|
1007
|
+
for (const key of observedKeys(ownerState.observedDependencies))
|
|
1008
|
+
materialized = withRequired(materialized, key);
|
|
1009
|
+
setExplicitRequired(ownerState, materialized);
|
|
1010
|
+
ownerState.requiresObserved = false;
|
|
1011
|
+
}
|
|
489
1012
|
dependencyState = stateOf(dependency);
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
observed
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
dependencyState.dependents = dependents = new Set();
|
|
496
|
-
dependents.add(ownerState);
|
|
1013
|
+
ownerState.observedDependencies = withObserved(ownerState.observedDependencies, dependencyState);
|
|
1014
|
+
// Appended without a membership test: an owner joins a dependency's
|
|
1015
|
+
// dependents exactly when its observed edge to it is new, and observed
|
|
1016
|
+
// edges are never removed, so it cannot already be there.
|
|
1017
|
+
dependencyState.dependents = withDependent(dependencyState.dependents, ownerState);
|
|
497
1018
|
dependencyRevision++;
|
|
498
1019
|
changed = true;
|
|
499
1020
|
}
|
|
500
|
-
if (
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
1021
|
+
if (joinsObserved) {
|
|
1022
|
+
ownerState.requiresObserved = true;
|
|
1023
|
+
componentDirty.add(ownerState.solverKey);
|
|
1024
|
+
dependencyRevision++;
|
|
1025
|
+
}
|
|
1026
|
+
else if (required && !ownerState.requiresObserved && !isRequired(ownerState, dependency)) {
|
|
1027
|
+
setExplicitRequired(ownerState, withRequired(explicitRequiredOf(ownerState), dependency));
|
|
1028
|
+
componentDirty.add(ownerState.solverKey);
|
|
1029
|
+
dependencyRevision++;
|
|
1030
|
+
changed = true;
|
|
510
1031
|
}
|
|
511
1032
|
// A new observation may expose facts on the next pass. An upgrade also
|
|
512
1033
|
// invalidates the current seal even though the fact edge already existed.
|
|
@@ -519,14 +1040,14 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
519
1040
|
// `propagate` adds a node's facts only AFTER its transfer has returned --
|
|
520
1041
|
// `evaluate` builds its result eagerly and hands back a set of its own --
|
|
521
1042
|
// so no reader is ever iterating a set that is being written.
|
|
522
|
-
return dependencyState
|
|
1043
|
+
return dependencyState;
|
|
523
1044
|
};
|
|
524
1045
|
const readFrom = (ownerState, dependency) => factsFrom(ownerState, dependency, true);
|
|
525
1046
|
const observeFrom = (ownerState, dependency) => factsFrom(ownerState, dependency, false);
|
|
526
1047
|
// A state's edge readers, minted per transfer or seal call rather than kept
|
|
527
1048
|
// on every state (see `stateOf`).
|
|
528
|
-
const transferOf = (state) => state.
|
|
529
|
-
const sealOf = (state) => state.
|
|
1049
|
+
const transferOf = (state) => definitionOf(state).transfer((dependency) => readFrom(state, dependency), (dependency) => observeFrom(state, dependency), (fact) => holdersOfFrom(state, fact), state.solverKey);
|
|
1050
|
+
const sealOf = (state) => definitionOf(state).seal((dependency) => readFrom(state, dependency), (dependency) => observeFrom(state, dependency), (fact) => holdersOfFrom(state, fact), state.solverKey);
|
|
530
1051
|
const propagate = () => {
|
|
531
1052
|
for (let cursor = 0; cursor < queue.length; cursor++) {
|
|
532
1053
|
const state = queue[cursor];
|
|
@@ -539,23 +1060,35 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
539
1060
|
// dependent already queued. The set can still grow mid-transfer (a state
|
|
540
1061
|
// that reads itself), and then the newcomer must be woken too.
|
|
541
1062
|
let wokenSize = -1;
|
|
1063
|
+
let added = false;
|
|
542
1064
|
for (const fact of transferOf(state)) {
|
|
543
|
-
if (state.
|
|
1065
|
+
if (state.has(fact))
|
|
544
1066
|
continue;
|
|
545
|
-
|
|
1067
|
+
added = true;
|
|
1068
|
+
state.add(fact);
|
|
546
1069
|
const dependents = state.dependents;
|
|
547
|
-
const size = dependents
|
|
1070
|
+
const size = edgeCount(dependents);
|
|
548
1071
|
if (wokenSize !== size) {
|
|
549
1072
|
wokenSize = size;
|
|
550
|
-
if (dependents
|
|
1073
|
+
if (dependents instanceof Set || Array.isArray(dependents))
|
|
551
1074
|
for (const dependent of dependents)
|
|
552
1075
|
enqueue(dependent);
|
|
1076
|
+
else if (dependents !== null)
|
|
1077
|
+
enqueue(dependents);
|
|
553
1078
|
}
|
|
554
1079
|
// Recorded at the exact point a fact is genuinely NEW, so `holders`
|
|
555
1080
|
// never grows for a re-observed fact.
|
|
556
1081
|
if (state.indexed)
|
|
557
1082
|
index(state, fact);
|
|
558
1083
|
}
|
|
1084
|
+
// A node forwarding what it reads ends up with the same facts as that
|
|
1085
|
+
// dependency: share its collection (`shareFactsOf`). Only a short edge
|
|
1086
|
+
// list is searched, and only a dependency of the same size compared.
|
|
1087
|
+
const observed = state.observedDependencies;
|
|
1088
|
+
if (added && state.size > 1 && observed !== null && (!Array.isArray(observed) || observed.length <= SMALL_EDGES))
|
|
1089
|
+
for (const dependency of edgeStates(observed))
|
|
1090
|
+
if (dependency.size === state.size && state.shareFactsOf(dependency))
|
|
1091
|
+
break;
|
|
559
1092
|
}
|
|
560
1093
|
queue.length = 0;
|
|
561
1094
|
};
|
|
@@ -565,17 +1098,16 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
565
1098
|
// every query re-sealed the whole graph it had explored so far, so the last
|
|
566
1099
|
// query of a large program paid for all of it. Only what `enqueue` marked is
|
|
567
1100
|
// re-sealed, which is exactly what could have changed.
|
|
568
|
-
const sealed = new Map();
|
|
569
1101
|
// Nodes whose seal or required-edge set moved since the component solve last
|
|
570
1102
|
// ran: the only facts a component answer reads.
|
|
571
1103
|
const componentDirty = new Set();
|
|
572
1104
|
const requiredDependentsOf = function* (key) {
|
|
573
|
-
const state =
|
|
574
|
-
if (state === undefined
|
|
1105
|
+
const state = existingStateOf(key);
|
|
1106
|
+
if (state === undefined)
|
|
575
1107
|
return;
|
|
576
|
-
for (const dependent of state.dependents)
|
|
577
|
-
if (dependent.
|
|
578
|
-
yield dependent.
|
|
1108
|
+
for (const dependent of edgeStates(state.dependents))
|
|
1109
|
+
if (dependent.requiresObserved || isRequired(dependent, key))
|
|
1110
|
+
yield dependent.solverKey;
|
|
579
1111
|
};
|
|
580
1112
|
// A changed seal evicts every cached component answer that reaches it, so
|
|
581
1113
|
// reporting a change for a re-seal that reproduces the same answer evicts
|
|
@@ -591,6 +1123,7 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
591
1123
|
// `Cause` per (node, reason) for exactly that reason.
|
|
592
1124
|
const domainsEqual = (a, b) => a.length === b.length && a.every((domain, index) => domain === b[index]);
|
|
593
1125
|
const groundingEdgesEqual = (a, b) => a.length === b.length && a.every((edge, index) => edge.domain === b[index].domain && edge.dependency === b[index].dependency);
|
|
1126
|
+
const keysEqual = (a, b) => a.length === b.length && a.every((key, index) => key === b[index]);
|
|
594
1127
|
const causesEqual = (a, b) => a.length === b.length && a.every((cause, index) => cause === b[index]);
|
|
595
1128
|
const sealChanged = (previous, next) => previous === undefined ||
|
|
596
1129
|
previous.locallyComplete !== next.locallyComplete ||
|
|
@@ -598,7 +1131,9 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
598
1131
|
!causesEqual(previous.causes ?? [], next.causes ?? []) ||
|
|
599
1132
|
!domainsEqual(previous.groundingRequirements ?? [], next.groundingRequirements ?? []) ||
|
|
600
1133
|
!domainsEqual(previous.groundingSeeds ?? [], next.groundingSeeds ?? []) ||
|
|
601
|
-
!groundingEdgesEqual(previous.groundingDependencies ?? [], next.groundingDependencies ?? [])
|
|
1134
|
+
!groundingEdgesEqual(previous.groundingDependencies ?? [], next.groundingDependencies ?? []) ||
|
|
1135
|
+
previous.groundingDomain !== next.groundingDomain ||
|
|
1136
|
+
!keysEqual(groundingKeysOf(previous), groundingKeysOf(next));
|
|
602
1137
|
const counts = { roots: 0, transfers: 0, seals: 0, componentNodes: 0 };
|
|
603
1138
|
// What the heap is actually holding, for the runs where memory is the wall
|
|
604
1139
|
// rather than time. Counted only when asked for: it walks every state.
|
|
@@ -619,20 +1154,20 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
619
1154
|
// GEA_SOLVER_SIZES-gated path that prints nothing in production, and
|
|
620
1155
|
// falls back to a single 'unknown' bucket for any key not shaped this way.
|
|
621
1156
|
const perKind = new Map();
|
|
622
|
-
for (const state of
|
|
623
|
-
observed += state.observedDependencies
|
|
624
|
-
required += state.
|
|
625
|
-
dependents += state.dependents
|
|
626
|
-
facts += state.
|
|
627
|
-
const kind = state.
|
|
1157
|
+
for (const state of everyState ?? []) {
|
|
1158
|
+
observed += edgeCount(state.observedDependencies);
|
|
1159
|
+
required += [...requiredOf(state)].length;
|
|
1160
|
+
dependents += edgeCount(state.dependents);
|
|
1161
|
+
facts += state.size;
|
|
1162
|
+
const kind = state.solverKey.kind;
|
|
628
1163
|
const bucketKey = typeof kind === 'string' ? kind : 'unknown';
|
|
629
1164
|
let bucket = perKind.get(bucketKey);
|
|
630
1165
|
if (bucket === undefined)
|
|
631
1166
|
perKind.set(bucketKey, (bucket = { states: 0, observed: 0, required: 0, facts: 0 }));
|
|
632
1167
|
bucket.states++;
|
|
633
|
-
bucket.observed += state.observedDependencies
|
|
634
|
-
bucket.required += state.
|
|
635
|
-
bucket.facts += state.
|
|
1168
|
+
bucket.observed += edgeCount(state.observedDependencies);
|
|
1169
|
+
bucket.required += [...requiredOf(state)].length;
|
|
1170
|
+
bucket.facts += state.size;
|
|
636
1171
|
}
|
|
637
1172
|
const byKind = [...perKind]
|
|
638
1173
|
.sort(([, a], [, b]) => b.observed - a.observed)
|
|
@@ -663,7 +1198,7 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
663
1198
|
const report = () => {
|
|
664
1199
|
if (!countsEnabled)
|
|
665
1200
|
return;
|
|
666
|
-
console.error(`[SOLVER] roots=${counts.roots} states=${
|
|
1201
|
+
console.error(`[SOLVER] roots=${counts.roots} states=${stateCount} transfers=${counts.transfers} seals=${counts.seals} component-expansions=${counts.componentNodes}${sizes()}${describeRoot()}`);
|
|
667
1202
|
};
|
|
668
1203
|
// Weakly: an exit listener closing over `report` kept every solver's whole
|
|
669
1204
|
// graph alive for the rest of the process, so a run measured with counts on
|
|
@@ -688,16 +1223,16 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
688
1223
|
const dirty = [...sealDirty];
|
|
689
1224
|
sealDirty.clear();
|
|
690
1225
|
for (const key of dirty) {
|
|
691
|
-
const state =
|
|
1226
|
+
const state = existingStateOf(key);
|
|
692
1227
|
if (state === undefined)
|
|
693
1228
|
continue;
|
|
694
1229
|
counts.seals++;
|
|
695
1230
|
if (countsEnabled && counts.seals % 200000 === 0)
|
|
696
1231
|
report();
|
|
697
1232
|
const next = sealOf(state);
|
|
698
|
-
if (sealChanged(sealed
|
|
1233
|
+
if (sealChanged(state.sealed, next))
|
|
699
1234
|
componentDirty.add(key);
|
|
700
|
-
sealed
|
|
1235
|
+
state.sealed = next;
|
|
701
1236
|
}
|
|
702
1237
|
if (queue.length === 0 && sealDirty.size === 0 && dependencyRevision === revisionBeforeSeal)
|
|
703
1238
|
break;
|
|
@@ -712,15 +1247,21 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
712
1247
|
// observe edge -- neither of which any component answer reads. Only the
|
|
713
1248
|
// answers that could have read a changed node are evicted.
|
|
714
1249
|
if (componentSolver === null)
|
|
715
|
-
componentSolver =
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
1250
|
+
componentSolver = componentEngine({
|
|
1251
|
+
slotOf: (key) => {
|
|
1252
|
+
const state = existingStateOf(key);
|
|
1253
|
+
if (state === undefined || state.sealed === undefined)
|
|
1254
|
+
throw new Error('unsealed dependency fact node');
|
|
1255
|
+
if (!state.componentRead) {
|
|
1256
|
+
counts.componentNodes++;
|
|
1257
|
+
if (countsEnabled && counts.componentNodes % 200000 === 0)
|
|
1258
|
+
report();
|
|
1259
|
+
}
|
|
1260
|
+
return state;
|
|
1261
|
+
},
|
|
1262
|
+
existingSlotOf: existingStateOf,
|
|
1263
|
+
localOf: (state) => state.sealed,
|
|
1264
|
+
dependenciesOf: (state) => requiredOf(state)
|
|
724
1265
|
}, mode);
|
|
725
1266
|
else if (componentDirty.size > 0)
|
|
726
1267
|
componentSolver.invalidate(componentDirty, requiredDependentsOf);
|
|
@@ -731,7 +1272,7 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
731
1272
|
status: 'complete',
|
|
732
1273
|
grounded: result.grounded,
|
|
733
1274
|
groundedDomains: result.groundedDomains,
|
|
734
|
-
facts: new Set(stateOf(root)
|
|
1275
|
+
facts: new Set(stateOf(root)),
|
|
735
1276
|
explain: result.explain
|
|
736
1277
|
};
|
|
737
1278
|
return {
|
|
@@ -741,5 +1282,5 @@ export const dependencyFactSolver = (expand, mode) => {
|
|
|
741
1282
|
explain: result.explain
|
|
742
1283
|
};
|
|
743
1284
|
};
|
|
744
|
-
return { solve, requiredDependenciesOf: (key) =>
|
|
1285
|
+
return { solve, requiredDependenciesOf: (key) => requiredOf(existingStateOf(key)), seed };
|
|
745
1286
|
};
|