@typeonce/effect-machine 0.47.1 → 0.48.0
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/AGENTS.md +374 -22
- package/CLAUDE.md +374 -22
- package/README.md +56 -7
- package/ai-docs/src/10_modeling/01_create-a-machine.ts +3 -3
- package/ai-docs/src/10_modeling/index.md +64 -17
- package/ai-docs/src/20_root-api/index.md +2 -2
- package/ai-docs/src/35_cluster/index.md +213 -0
- package/ai-docs/src/37_new-host/index.md +90 -0
- package/dist/LocalMachine.d.ts +417 -0
- package/dist/LocalMachine.d.ts.map +1 -0
- package/dist/LocalMachine.js +193 -0
- package/dist/LocalMachine.js.map +1 -0
- package/dist/Machine.d.ts +1120 -812
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +195 -186
- package/dist/Machine.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +8 -10
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js +7 -6
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/capability.d.ts +101 -0
- package/dist/internal/machine/capability.d.ts.map +1 -0
- package/dist/internal/machine/capability.js +70 -0
- package/dist/internal/machine/capability.js.map +1 -0
- package/dist/internal/machine/{invocationDefinition.d.ts → capturedInvocation.d.ts} +11 -11
- package/dist/internal/machine/capturedInvocation.d.ts.map +1 -0
- package/dist/internal/machine/{invocationDefinition.js → capturedInvocation.js} +2 -2
- package/dist/internal/machine/capturedInvocation.js.map +1 -0
- package/dist/internal/machine/child.d.ts +14 -0
- package/dist/internal/machine/child.d.ts.map +1 -0
- package/dist/internal/machine/child.js +19 -0
- package/dist/internal/machine/child.js.map +1 -0
- package/dist/internal/machine/childRegistry.d.ts +0 -2
- package/dist/internal/machine/childRegistry.d.ts.map +1 -1
- package/dist/internal/machine/childRegistry.js +2 -2
- package/dist/internal/machine/childRegistry.js.map +1 -1
- package/dist/internal/machine/cluster.d.ts +19 -4
- package/dist/internal/machine/cluster.d.ts.map +1 -1
- package/dist/internal/machine/cluster.js +263 -110
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/clusterChild.d.ts +66 -0
- package/dist/internal/machine/clusterChild.d.ts.map +1 -0
- package/dist/internal/machine/clusterChild.js +105 -0
- package/dist/internal/machine/clusterChild.js.map +1 -0
- package/dist/internal/machine/clusterFailure.d.ts +14 -0
- package/dist/internal/machine/clusterFailure.d.ts.map +1 -0
- package/dist/internal/machine/clusterFailure.js +44 -0
- package/dist/internal/machine/clusterFailure.js.map +1 -0
- package/dist/internal/machine/clusterInstance.d.ts +194 -0
- package/dist/internal/machine/clusterInstance.d.ts.map +1 -0
- package/dist/internal/machine/clusterInstance.js +1076 -0
- package/dist/internal/machine/clusterInstance.js.map +1 -0
- package/dist/internal/machine/clusterKeepAlive.d.ts +47 -0
- package/dist/internal/machine/clusterKeepAlive.d.ts.map +1 -0
- package/dist/internal/machine/clusterKeepAlive.js +72 -0
- package/dist/internal/machine/clusterKeepAlive.js.map +1 -0
- package/dist/internal/machine/clusterProgress.d.ts +73 -0
- package/dist/internal/machine/clusterProgress.d.ts.map +1 -0
- package/dist/internal/machine/clusterProgress.js +116 -0
- package/dist/internal/machine/clusterProgress.js.map +1 -0
- package/dist/internal/machine/clusterProtocol.d.ts +37 -4
- package/dist/internal/machine/clusterProtocol.d.ts.map +1 -1
- package/dist/internal/machine/clusterProtocol.js +18 -4
- package/dist/internal/machine/clusterProtocol.js.map +1 -1
- package/dist/internal/machine/clusterProxy.d.ts +46 -0
- package/dist/internal/machine/clusterProxy.d.ts.map +1 -0
- package/dist/internal/machine/clusterProxy.js +150 -0
- package/dist/internal/machine/clusterProxy.js.map +1 -0
- package/dist/internal/machine/clusterRead.d.ts +61 -0
- package/dist/internal/machine/clusterRead.d.ts.map +1 -0
- package/dist/internal/machine/clusterRead.js +108 -0
- package/dist/internal/machine/clusterRead.js.map +1 -0
- package/dist/internal/machine/clusterSqlStorage.d.ts +16 -0
- package/dist/internal/machine/clusterSqlStorage.d.ts.map +1 -0
- package/dist/internal/machine/clusterSqlStorage.js +138 -0
- package/dist/internal/machine/clusterSqlStorage.js.map +1 -0
- package/dist/internal/machine/clusterStorageCheck.d.ts +19 -0
- package/dist/internal/machine/clusterStorageCheck.d.ts.map +1 -0
- package/dist/internal/machine/clusterStorageCheck.js +186 -0
- package/dist/internal/machine/clusterStorageCheck.js.map +1 -0
- package/dist/internal/machine/clusterTarget.d.ts +74 -0
- package/dist/internal/machine/clusterTarget.d.ts.map +1 -0
- package/dist/internal/machine/clusterTarget.js +81 -0
- package/dist/internal/machine/clusterTarget.js.map +1 -0
- package/dist/internal/machine/clusterTimer.d.ts +21 -0
- package/dist/internal/machine/clusterTimer.d.ts.map +1 -0
- package/dist/internal/machine/clusterTimer.js +50 -0
- package/dist/internal/machine/clusterTimer.js.map +1 -0
- package/dist/internal/machine/clusterWake.d.ts +61 -0
- package/dist/internal/machine/clusterWake.d.ts.map +1 -0
- package/dist/internal/machine/clusterWake.js +81 -0
- package/dist/internal/machine/clusterWake.js.map +1 -0
- package/dist/internal/machine/clusterWork.d.ts +130 -0
- package/dist/internal/machine/clusterWork.d.ts.map +1 -0
- package/dist/internal/machine/clusterWork.js +191 -0
- package/dist/internal/machine/clusterWork.js.map +1 -0
- package/dist/internal/machine/command.d.ts +4 -4
- package/dist/internal/machine/command.d.ts.map +1 -1
- package/dist/internal/machine/commandRuntime.d.ts +8 -6
- package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
- package/dist/internal/machine/commandRuntime.js +1 -5
- package/dist/internal/machine/commandRuntime.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts +0 -13
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +0 -151
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/errors.d.ts +11 -2
- package/dist/internal/machine/errors.d.ts.map +1 -1
- package/dist/internal/machine/errors.js +11 -2
- package/dist/internal/machine/errors.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts +45 -3
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +328 -191
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/implementation.d.ts +6 -6
- package/dist/internal/machine/implementation.d.ts.map +1 -1
- package/dist/internal/machine/inspectionRuntime.d.ts +1 -1
- package/dist/internal/machine/inspectionRuntime.d.ts.map +1 -1
- package/dist/internal/machine/invocationChanges.d.ts +60 -0
- package/dist/internal/machine/invocationChanges.d.ts.map +1 -0
- package/dist/internal/machine/invocationChanges.js +54 -0
- package/dist/internal/machine/invocationChanges.js.map +1 -0
- package/dist/internal/machine/{activities.d.ts → invocationDefinitions.d.ts} +8 -8
- package/dist/internal/machine/invocationDefinitions.d.ts.map +1 -0
- package/dist/internal/machine/{activities.js → invocationDefinitions.js} +5 -5
- package/dist/internal/machine/invocationDefinitions.js.map +1 -0
- package/dist/internal/machine/invocationEvent.d.ts +16 -7
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -1
- package/dist/internal/machine/invocationEvent.js +26 -12
- package/dist/internal/machine/invocationEvent.js.map +1 -1
- package/dist/internal/machine/invocationOutcome.d.ts +89 -0
- package/dist/internal/machine/invocationOutcome.d.ts.map +1 -0
- package/dist/internal/machine/invocationOutcome.js +76 -0
- package/dist/internal/machine/invocationOutcome.js.map +1 -0
- package/dist/internal/machine/invocationResolution.d.ts +137 -0
- package/dist/internal/machine/invocationResolution.d.ts.map +1 -0
- package/dist/internal/machine/invocationResolution.js +150 -0
- package/dist/internal/machine/invocationResolution.js.map +1 -0
- package/dist/internal/machine/logicScope.d.ts +24 -0
- package/dist/internal/machine/logicScope.d.ts.map +1 -0
- package/dist/internal/machine/logicScope.js +33 -0
- package/dist/internal/machine/logicScope.js.map +1 -0
- package/dist/internal/machine/machine.d.ts +17 -23
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +24 -40
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/observation.d.ts +3 -0
- package/dist/internal/machine/observation.d.ts.map +1 -1
- package/dist/internal/machine/observation.js +56 -2
- package/dist/internal/machine/observation.js.map +1 -1
- package/dist/internal/machine/plannedSnapshot.d.ts.map +1 -1
- package/dist/internal/machine/plannedSnapshot.js +11 -20
- package/dist/internal/machine/plannedSnapshot.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +36 -23
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +15 -8
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts +17 -9
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +43 -503
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/protocol.d.ts +1 -1
- package/dist/internal/machine/protocol.d.ts.map +1 -1
- package/dist/internal/machine/protocol.js +48 -10
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/runtime.d.ts +20 -16
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +93 -88
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/runtimeCompiled.d.ts.map +1 -1
- package/dist/internal/machine/runtimeCompiled.js +359 -120
- package/dist/internal/machine/runtimeCompiled.js.map +1 -1
- package/dist/internal/machine/runtimeProtocol.d.ts +151 -82
- package/dist/internal/machine/runtimeProtocol.d.ts.map +1 -1
- package/dist/internal/machine/runtimeProtocol.js +236 -219
- package/dist/internal/machine/runtimeProtocol.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts +0 -1
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +0 -1
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/step.d.ts +486 -0
- package/dist/internal/machine/step.d.ts.map +1 -0
- package/dist/internal/machine/step.js +957 -0
- package/dist/internal/machine/step.js.map +1 -0
- package/dist/internal/machine/stepHost.d.ts +33 -0
- package/dist/internal/machine/stepHost.d.ts.map +1 -0
- package/dist/internal/machine/stepHost.js +501 -0
- package/dist/internal/machine/stepHost.js.map +1 -0
- package/dist/internal/machine/symbols.d.ts +2 -11
- package/dist/internal/machine/symbols.d.ts.map +1 -1
- package/dist/internal/machine/symbols.js +2 -2
- package/dist/internal/machine/symbols.js.map +1 -1
- package/dist/internal/machine/transition.d.ts +7 -7
- package/dist/internal/machine/transition.d.ts.map +1 -1
- package/dist/internal/testing/machine/check.d.ts.map +1 -1
- package/dist/internal/testing/machine/check.js +217 -25
- package/dist/internal/testing/machine/check.js.map +1 -1
- package/dist/internal/testing/machine/exploration.d.ts +19 -2
- package/dist/internal/testing/machine/exploration.d.ts.map +1 -1
- package/dist/internal/testing/machine/exploration.js +14 -3
- package/dist/internal/testing/machine/exploration.js.map +1 -1
- package/dist/internal/testing/machine/format.js.map +1 -1
- package/dist/internal/testing/machine/probe.d.ts.map +1 -1
- package/dist/internal/testing/machine/probe.js +1 -1
- package/dist/internal/testing/machine/probe.js.map +1 -1
- package/dist/internal/testing/machine/runtime.d.ts +2 -2
- package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
- package/dist/internal/testing/machine/runtime.js +10 -3
- package/dist/internal/testing/machine/runtime.js.map +1 -1
- package/dist/internal/testing/machine/trace.d.ts +38 -3
- package/dist/internal/testing/machine/trace.d.ts.map +1 -1
- package/dist/internal/testing/machine/trace.js +180 -33
- package/dist/internal/testing/machine/trace.js.map +1 -1
- package/dist/internal/testing/machine/transitionCoverage.d.ts +1 -1
- package/dist/internal/testing/machine/transitionCoverage.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +9 -1
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/internal/testing/machine/work.d.ts +47 -0
- package/dist/internal/testing/machine/work.d.ts.map +1 -0
- package/dist/internal/testing/machine/work.js +74 -0
- package/dist/internal/testing/machine/work.js.map +1 -0
- package/dist/testing/MachineTest.d.ts +253 -37
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +81 -9
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +1071 -41
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +441 -12
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachineProxy.d.ts +257 -0
- package/dist/unstable/cluster/ClusterMachineProxy.d.ts.map +1 -0
- package/dist/unstable/cluster/ClusterMachineProxy.js +73 -0
- package/dist/unstable/cluster/ClusterMachineProxy.js.map +1 -0
- package/dist/unstable/cluster/SqlMachineStorage.d.ts +125 -0
- package/dist/unstable/cluster/SqlMachineStorage.d.ts.map +1 -0
- package/dist/unstable/cluster/SqlMachineStorage.js +62 -0
- package/dist/unstable/cluster/SqlMachineStorage.js.map +1 -0
- package/dist/unstable/cluster/index.d.ts +13 -0
- package/dist/unstable/cluster/index.d.ts.map +1 -1
- package/dist/unstable/cluster/index.js +13 -0
- package/dist/unstable/cluster/index.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +21 -26
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/package.json +5 -3
- package/src/LocalMachine.ts +611 -0
- package/src/Machine.ts +1379 -1334
- package/src/index.ts +1 -0
- package/src/internal/machine/atom.ts +20 -49
- package/src/internal/machine/capability.ts +123 -0
- package/src/internal/machine/{invocationDefinition.ts → capturedInvocation.ts} +13 -13
- package/src/internal/machine/child.ts +25 -0
- package/src/internal/machine/childRegistry.ts +1 -4
- package/src/internal/machine/cluster.ts +420 -205
- package/src/internal/machine/clusterChild.ts +117 -0
- package/src/internal/machine/clusterFailure.ts +53 -0
- package/src/internal/machine/clusterInstance.ts +1779 -0
- package/src/internal/machine/clusterKeepAlive.ts +93 -0
- package/src/internal/machine/clusterProgress.ts +159 -0
- package/src/internal/machine/clusterProtocol.ts +46 -4
- package/src/internal/machine/clusterProxy.ts +233 -0
- package/src/internal/machine/clusterRead.ts +207 -0
- package/src/internal/machine/clusterSqlStorage.ts +181 -0
- package/src/internal/machine/clusterStorageCheck.ts +274 -0
- package/src/internal/machine/clusterTarget.ts +154 -0
- package/src/internal/machine/clusterTimer.ts +58 -0
- package/src/internal/machine/clusterWake.ts +100 -0
- package/src/internal/machine/clusterWork.ts +269 -0
- package/src/internal/machine/command.ts +4 -4
- package/src/internal/machine/commandRuntime.ts +12 -24
- package/src/internal/machine/configuration.ts +0 -181
- package/src/internal/machine/errors.ts +11 -2
- package/src/internal/machine/executionPlan.ts +493 -263
- package/src/internal/machine/implementation.ts +6 -6
- package/src/internal/machine/inspectionRuntime.ts +1 -1
- package/src/internal/machine/invocationChanges.ts +89 -0
- package/src/internal/machine/{activities.ts → invocationDefinitions.ts} +10 -10
- package/src/internal/machine/invocationEvent.ts +35 -12
- package/src/internal/machine/invocationOutcome.ts +145 -0
- package/src/internal/machine/invocationResolution.ts +307 -0
- package/src/internal/machine/logicScope.ts +47 -0
- package/src/internal/machine/machine.ts +35 -100
- package/src/internal/machine/observation.ts +67 -2
- package/src/internal/machine/plannedSnapshot.ts +17 -20
- package/src/internal/machine/planner.ts +75 -99
- package/src/internal/machine/process.ts +78 -722
- package/src/internal/machine/protocol.ts +70 -26
- package/src/internal/machine/runtime.ts +198 -195
- package/src/internal/machine/runtimeCompiled.ts +496 -171
- package/src/internal/machine/runtimeProtocol.ts +416 -305
- package/src/internal/machine/stateDefinition.ts +0 -5
- package/src/internal/machine/step.ts +1518 -0
- package/src/internal/machine/stepHost.ts +634 -0
- package/src/internal/machine/symbols.ts +3 -14
- package/src/internal/machine/transition.ts +11 -11
- package/src/internal/testing/machine/check.ts +240 -36
- package/src/internal/testing/machine/exploration.ts +42 -3
- package/src/internal/testing/machine/format.ts +1 -1
- package/src/internal/testing/machine/probe.ts +2 -1
- package/src/internal/testing/machine/runtime.ts +15 -5
- package/src/internal/testing/machine/trace.ts +261 -41
- package/src/internal/testing/machine/transitionCoverage.ts +1 -1
- package/src/internal/testing/machine/verification.ts +11 -5
- package/src/internal/testing/machine/work.ts +101 -0
- package/src/testing/MachineTest.ts +268 -44
- package/src/unstable/cluster/ClusterMachine.ts +1183 -59
- package/src/unstable/cluster/ClusterMachineProxy.ts +372 -0
- package/src/unstable/cluster/SqlMachineStorage.ts +136 -0
- package/src/unstable/cluster/index.ts +15 -0
- package/src/unstable/reactivity/AtomMachine.ts +27 -88
- package/dist/internal/machine/activities.d.ts.map +0 -1
- package/dist/internal/machine/activities.js.map +0 -1
- package/dist/internal/machine/invocation.d.ts +0 -33
- package/dist/internal/machine/invocation.d.ts.map +0 -1
- package/dist/internal/machine/invocation.js +0 -220
- package/dist/internal/machine/invocation.js.map +0 -1
- package/dist/internal/machine/invocationDefinition.d.ts.map +0 -1
- package/dist/internal/machine/invocationDefinition.js.map +0 -1
- package/dist/internal/machine/requirements.d.ts +0 -4
- package/dist/internal/machine/requirements.d.ts.map +0 -1
- package/dist/internal/machine/requirements.js +0 -2
- package/dist/internal/machine/requirements.js.map +0 -1
- package/dist/internal/machine/runtimeGeneric.d.ts +0 -3
- package/dist/internal/machine/runtimeGeneric.d.ts.map +0 -1
- package/dist/internal/machine/runtimeGeneric.js +0 -465
- package/dist/internal/machine/runtimeGeneric.js.map +0 -1
- package/src/internal/machine/invocation.ts +0 -376
- package/src/internal/machine/requirements.ts +0 -11
- package/src/internal/machine/runtimeGeneric.ts +0 -797
|
@@ -10,7 +10,7 @@ import { InfiniteTransitionError, StoppedError } from "./errors.js";
|
|
|
10
10
|
import { toImpl } from "./implementation.js";
|
|
11
11
|
import { isDataInitializer } from "./initialDeclaration.js";
|
|
12
12
|
import * as InvocationEvent from "./invocationEvent.js";
|
|
13
|
-
import { broadenTransitionBoundary, getEntryPaths, getExitPaths, getLeastCommonAncestor, getTargetNodePath, InitialEvent, MaxMacrostepIterations, normalizeTransition, planConfiguration, removeConflictingTransitions, resolveInitialConfiguration, resolveInitialTarget, sortEntryPaths, sortEvaluatedTransitions, sortExitPaths, validateDeclaredTransitionTarget } from "./planner.js";
|
|
13
|
+
import { broadenTransitionBoundary, getEntryPaths, getExitPaths, getLeastCommonAncestor, getTargetNodePath, InitialEvent, MaxMacrostepIterations, normalizeTransition, planConfiguration, planDecodedConfiguration, removeConflictingTransitions, resolveInitialConfiguration, resolveInitialTarget, sortEntryPaths, sortEvaluatedTransitions, sortExitPaths, validateDeclaredTransitionTarget } from "./planner.js";
|
|
14
14
|
import { decodeEmitSync, decodeEventSync, decodeInputSync, decodeStateValueSync } from "./protocol.js";
|
|
15
15
|
import { isCombinedTarget, isInitialTarget, isNoTarget, isSnapshot, isStateUpdate, isTarget, TargetSnapshotTypeId } from "./topology.js";
|
|
16
16
|
const planningMachineReferences = new WeakMap();
|
|
@@ -139,7 +139,7 @@ const compileIndexedExecutionDescriptor = (machine) => {
|
|
|
139
139
|
dispatchByLeaf
|
|
140
140
|
};
|
|
141
141
|
};
|
|
142
|
-
const
|
|
142
|
+
const copyIndexedState = (state) => ({
|
|
143
143
|
active: state.active.slice(),
|
|
144
144
|
activeLeaves: state.activeLeaves.slice(),
|
|
145
145
|
values: state.values.slice(),
|
|
@@ -147,11 +147,12 @@ const copyOwnedIndexedState = (state) => ({
|
|
|
147
147
|
outputs: state.outputs.slice(),
|
|
148
148
|
completedOrder: state.completedOrder.slice()
|
|
149
149
|
});
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
state
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
/** A state equal to `state` whose values the kernel may write, as only `values` is ever written. */
|
|
151
|
+
const withWritableIndexedValues = (state) => ({
|
|
152
|
+
...state,
|
|
153
|
+
values: state.values.slice()
|
|
154
|
+
});
|
|
155
|
+
const indexedStateFromActive = (descriptor, configuration) => {
|
|
155
156
|
const active = new Uint8Array(descriptor.nodes.length);
|
|
156
157
|
const values = new Array(descriptor.nodes.length);
|
|
157
158
|
const completed = new Uint8Array(descriptor.nodes.length);
|
|
@@ -257,6 +258,8 @@ const makeIndexedTransitionContext = (machine, descriptor, configuration, source
|
|
|
257
258
|
};
|
|
258
259
|
};
|
|
259
260
|
const emptyExecutionValues = Object.freeze([]);
|
|
261
|
+
/** Marks that a flat microstep writes no value. A decoded value may be `undefined`. */
|
|
262
|
+
const noIndexedValue = Symbol("effect/Machine/ExecutionPlan/NoValue");
|
|
260
263
|
const collectIndexedTransition = (machine, transition, context, evaluate) => {
|
|
261
264
|
let commands;
|
|
262
265
|
let raisedEvents;
|
|
@@ -332,7 +335,7 @@ const normalizeIndexedTargetStateSync = (machine, descriptor, current, target, a
|
|
|
332
335
|
values[activeLeafIndex] = decodeStateValueSync(machine, descriptor.nodes[activeLeafIndex], target.value);
|
|
333
336
|
return { ...current, values };
|
|
334
337
|
}
|
|
335
|
-
return
|
|
338
|
+
return indexedStateFromActive(descriptor, normalizeTargetConfigurationSync(machine, activeConfigurationFromIndexedState(descriptor, current), target));
|
|
336
339
|
};
|
|
337
340
|
const collectIndexedEvaluatedTransition = (machine, descriptor, state, selection) => {
|
|
338
341
|
const transitionResult = collectIndexedTransition(machine, selection.transition.transition, selection.context, selection.transition.evaluate);
|
|
@@ -375,7 +378,7 @@ const collectIndexedEvaluatedTransition = (machine, descriptor, state, selection
|
|
|
375
378
|
const initialRaisedEvents = (initialResolution?.raisedEvents ?? emptyExecutionValues);
|
|
376
379
|
let next = target === undefined
|
|
377
380
|
? update === undefined ? state : (() => {
|
|
378
|
-
const next =
|
|
381
|
+
const next = copyIndexedState(state);
|
|
379
382
|
next.values[descriptor.indexByPath.get(update.path)] = update.value;
|
|
380
383
|
return next;
|
|
381
384
|
})()
|
|
@@ -436,30 +439,119 @@ const collectIndexedEvaluatedTransition = (machine, descriptor, state, selection
|
|
|
436
439
|
choiceTransitions: initialResolution?.transitions ?? []
|
|
437
440
|
};
|
|
438
441
|
};
|
|
442
|
+
const retainIndexedTransition = (transition) => ({
|
|
443
|
+
source: transition.selection.sourcePath,
|
|
444
|
+
trigger: transition.selection.trigger,
|
|
445
|
+
reenter: transition.selection.transition.reenter,
|
|
446
|
+
branchIndex: transition.branchIndex,
|
|
447
|
+
branchKey: transition.branchKey,
|
|
448
|
+
target: transition.unresolvedTarget === undefined ? undefined : getTargetNodePath(transition.unresolvedTarget),
|
|
449
|
+
resolvedTarget: transition.target === undefined ? undefined : getTargetNodePath(transition.target),
|
|
450
|
+
updates: transition.update === undefined ? [] : [transition.update.path]
|
|
451
|
+
});
|
|
452
|
+
/**
|
|
453
|
+
* A retained microstep of the hierarchical kernel. It builds its retained
|
|
454
|
+
* transitions on first read, from evaluated transitions that hold only values
|
|
455
|
+
* no later plan writes.
|
|
456
|
+
*/
|
|
457
|
+
class RetainedHierarchicalMicrostep {
|
|
458
|
+
next;
|
|
459
|
+
event;
|
|
460
|
+
commands;
|
|
461
|
+
raisedEvents;
|
|
462
|
+
emittedEvents;
|
|
463
|
+
exitPaths;
|
|
464
|
+
entryPaths;
|
|
465
|
+
changed;
|
|
466
|
+
#evaluated;
|
|
467
|
+
#transitions;
|
|
468
|
+
constructor(next, event, evaluated, commands, raisedEvents, emittedEvents, exitPaths, entryPaths, changed) {
|
|
469
|
+
this.next = next;
|
|
470
|
+
this.event = event;
|
|
471
|
+
this.commands = commands;
|
|
472
|
+
this.raisedEvents = raisedEvents;
|
|
473
|
+
this.emittedEvents = emittedEvents;
|
|
474
|
+
this.exitPaths = exitPaths;
|
|
475
|
+
this.entryPaths = entryPaths;
|
|
476
|
+
this.changed = changed;
|
|
477
|
+
this.#evaluated = evaluated;
|
|
478
|
+
}
|
|
479
|
+
get transitions() {
|
|
480
|
+
if (this.#transitions === undefined) {
|
|
481
|
+
this.#transitions = this.#evaluated.map(retainIndexedTransition);
|
|
482
|
+
this.#evaluated = undefined;
|
|
483
|
+
}
|
|
484
|
+
return this.#transitions;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* A retained microstep of the flat kernel, which builds its one retained
|
|
489
|
+
* transition on first read.
|
|
490
|
+
*/
|
|
491
|
+
class RetainedFlatMicrostep {
|
|
492
|
+
next;
|
|
493
|
+
event;
|
|
494
|
+
commands;
|
|
495
|
+
raisedEvents;
|
|
496
|
+
emittedEvents;
|
|
497
|
+
exitPaths;
|
|
498
|
+
entryPaths;
|
|
499
|
+
changed;
|
|
500
|
+
#source;
|
|
501
|
+
#reenter;
|
|
502
|
+
#branchIndex;
|
|
503
|
+
#branchKey;
|
|
504
|
+
#target;
|
|
505
|
+
#update;
|
|
506
|
+
#transitions;
|
|
507
|
+
constructor(next, event, commands, raisedEvents, emittedEvents, exitPaths, entryPaths, changed, source, reenter, branchIndex, branchKey, target, update) {
|
|
508
|
+
this.next = next;
|
|
509
|
+
this.event = event;
|
|
510
|
+
this.commands = commands;
|
|
511
|
+
this.raisedEvents = raisedEvents;
|
|
512
|
+
this.emittedEvents = emittedEvents;
|
|
513
|
+
this.exitPaths = exitPaths;
|
|
514
|
+
this.entryPaths = entryPaths;
|
|
515
|
+
this.changed = changed;
|
|
516
|
+
this.#source = source;
|
|
517
|
+
this.#reenter = reenter;
|
|
518
|
+
this.#branchIndex = branchIndex;
|
|
519
|
+
this.#branchKey = branchKey;
|
|
520
|
+
this.#target = target;
|
|
521
|
+
this.#update = update;
|
|
522
|
+
}
|
|
523
|
+
get transitions() {
|
|
524
|
+
if (this.#transitions === undefined) {
|
|
525
|
+
const target = this.#target === undefined ? undefined : getTargetNodePath(this.#target);
|
|
526
|
+
this.#transitions = [{
|
|
527
|
+
source: this.#source,
|
|
528
|
+
trigger: { type: "event", event: this.event._tag },
|
|
529
|
+
reenter: this.#reenter,
|
|
530
|
+
branchIndex: this.#branchIndex,
|
|
531
|
+
branchKey: this.#branchKey,
|
|
532
|
+
target,
|
|
533
|
+
resolvedTarget: target,
|
|
534
|
+
updates: this.#update === undefined ? [] : [this.#update.path]
|
|
535
|
+
}];
|
|
536
|
+
}
|
|
537
|
+
return this.#transitions;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
439
540
|
const indexedMicrostep = (machine, descriptor, state, event, selections, retainTransitions) => {
|
|
440
|
-
const retain = (transition) => ({
|
|
441
|
-
source: transition.selection.sourcePath,
|
|
442
|
-
trigger: transition.selection.trigger,
|
|
443
|
-
reenter: transition.selection.transition.reenter,
|
|
444
|
-
branchIndex: transition.branchIndex,
|
|
445
|
-
branchKey: transition.branchKey,
|
|
446
|
-
target: transition.unresolvedTarget === undefined ? undefined : getTargetNodePath(transition.unresolvedTarget),
|
|
447
|
-
resolvedTarget: transition.target === undefined ? undefined : getTargetNodePath(transition.target),
|
|
448
|
-
updates: transition.update === undefined ? [] : [transition.update.path]
|
|
449
|
-
});
|
|
450
541
|
if (selections.length === 1) {
|
|
451
542
|
const transition = collectIndexedEvaluatedTransition(machine, descriptor, state, selections[0]);
|
|
452
|
-
return
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
543
|
+
return retainTransitions
|
|
544
|
+
? new RetainedHierarchicalMicrostep(transition.next, event, [transition], transition.commands, transition.raisedEvents, transition.emittedEvents, transition.exitPaths, transition.entryPaths, transition.changed)
|
|
545
|
+
: {
|
|
546
|
+
next: transition.next,
|
|
547
|
+
event,
|
|
548
|
+
commands: transition.commands,
|
|
549
|
+
raisedEvents: transition.raisedEvents,
|
|
550
|
+
emittedEvents: transition.emittedEvents,
|
|
551
|
+
exitPaths: transition.exitPaths,
|
|
552
|
+
entryPaths: transition.entryPaths,
|
|
553
|
+
changed: transition.changed
|
|
554
|
+
};
|
|
463
555
|
}
|
|
464
556
|
const activeSelections = selections.filter((selection) => !selections.some((other) => other.sourceIndex !== selection.sourceIndex &&
|
|
465
557
|
isDescendantOf(other.sourcePath, selection.sourcePath)));
|
|
@@ -491,19 +583,13 @@ const indexedMicrostep = (machine, descriptor, state, event, selections, retainT
|
|
|
491
583
|
const raisedEvents = transitions.flatMap((transition) => transition.raisedEvents);
|
|
492
584
|
const emittedEvents = transitions.flatMap((transition) => transition.emittedEvents);
|
|
493
585
|
const changed = transitions.some((transition) => transition.changed);
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
commands,
|
|
499
|
-
raisedEvents,
|
|
500
|
-
emittedEvents,
|
|
501
|
-
exitPaths: changed ? sortExitPaths(machine, transitions.flatMap((transition) => transition.exitPaths)) : [],
|
|
502
|
-
entryPaths: changed ? sortEntryPaths(machine, transitions.flatMap((transition) => transition.entryPaths)) : [],
|
|
503
|
-
changed
|
|
504
|
-
};
|
|
586
|
+
const exitPaths = changed ? sortExitPaths(machine, transitions.flatMap((transition) => transition.exitPaths)) : [];
|
|
587
|
+
const entryPaths = changed ? sortEntryPaths(machine, transitions.flatMap((transition) => transition.entryPaths)) : [];
|
|
588
|
+
return retainTransitions
|
|
589
|
+
? new RetainedHierarchicalMicrostep(next, event, transitions, commands, raisedEvents, emittedEvents, exitPaths, entryPaths, changed)
|
|
590
|
+
: { next, event, commands, raisedEvents, emittedEvents, exitPaths, entryPaths, changed };
|
|
505
591
|
};
|
|
506
|
-
const planIndexedFlatState = (machine, descriptor, configuration, decoded, retainMicrosteps, machineReferences) => {
|
|
592
|
+
const planIndexedFlatState = (machine, descriptor, configuration, decoded, retainMicrosteps, ownership, machineReferences) => {
|
|
507
593
|
let current = configuration;
|
|
508
594
|
let event = decoded;
|
|
509
595
|
let commands;
|
|
@@ -512,137 +598,164 @@ const planIndexedFlatState = (machine, descriptor, configuration, decoded, retai
|
|
|
512
598
|
let microsteps;
|
|
513
599
|
let raisedIndex = 0;
|
|
514
600
|
let iterations = 0;
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
601
|
+
// Whether `current` may be written in place, because nothing but this plan
|
|
602
|
+
// references it. A persistent caller's state, and the state of a retained
|
|
603
|
+
// microstep, are copied before they would be written.
|
|
604
|
+
let writable = ownership === "Owned";
|
|
605
|
+
// The value that this plan overwrote in an owned caller's state, so that a
|
|
606
|
+
// plan that throws leaves that state as it was. Only the active leaf is
|
|
607
|
+
// written, and the leaf of the caller's state stays active while `current`
|
|
608
|
+
// is that state, so one value is all a plan overwrites in it.
|
|
609
|
+
let restoreIndex = -1;
|
|
610
|
+
let restoreValue;
|
|
611
|
+
try {
|
|
612
|
+
while (true) {
|
|
613
|
+
iterations += 1;
|
|
614
|
+
if (iterations > MaxMacrostepIterations) {
|
|
615
|
+
throw new InfiniteTransitionError({
|
|
616
|
+
machineId: machine.id,
|
|
617
|
+
state: descriptor.nodes[current.activeLeaves[0]].path,
|
|
618
|
+
maxIterations: MaxMacrostepIterations
|
|
619
|
+
});
|
|
533
620
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
commands: commands ?? emptyExecutionValues,
|
|
538
|
-
emittedEvents: emittedEvents ?? emptyExecutionValues,
|
|
539
|
-
microsteps: microsteps ?? emptyExecutionValues,
|
|
540
|
-
done: true,
|
|
541
|
-
output: completed.outputs.get(root)
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
const sourcePath = descriptor.nodes[sourceIndex].path;
|
|
545
|
-
const transition = normalizeTransition(toImpl(machine).handlers[sourcePath]?.on?.[event._tag]);
|
|
546
|
-
if (transition !== undefined) {
|
|
547
|
-
const transitionResult = collectIndexedTransition(machine, transition.transition, {
|
|
548
|
-
...resolveMachineReferences(machine, machineReferences),
|
|
549
|
-
state: current.values[sourceIndex],
|
|
550
|
-
containingState: undefined,
|
|
551
|
-
ancestors: {},
|
|
552
|
-
event,
|
|
553
|
-
snapshot: snapshotFromIndexedState(descriptor, current)
|
|
554
|
-
}, transition.evaluate);
|
|
555
|
-
const update = isStateUpdate(transitionResult.state) ? transitionResult.state : undefined;
|
|
556
|
-
const target = update === undefined ? transitionResult.state : undefined;
|
|
557
|
-
if (update !== undefined) {
|
|
558
|
-
const node = descriptor.nodes[sourceIndex];
|
|
559
|
-
if (update.path !== sourcePath || node.schema === undefined) {
|
|
560
|
-
throw new Error(`Machine state update owner "${update.path}" must be the active valued state`);
|
|
561
|
-
}
|
|
562
|
-
updateOwnedIndexedValue(current, sourceIndex, decodeStateValueSync(machine, node, update.value));
|
|
621
|
+
const sourceIndex = current.activeLeaves[0];
|
|
622
|
+
if (sourceIndex === undefined) {
|
|
623
|
+
throw new Error("Machine expected an active indexed root state");
|
|
563
624
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
625
|
+
if (descriptor.nodes[sourceIndex].type === "final") {
|
|
626
|
+
const completed = completeConfigurationSync(machine, activeConfigurationFromIndexedState(descriptor, current), event).configuration;
|
|
627
|
+
const root = getRootPath(machine, completed);
|
|
628
|
+
if (!completed.outputs.has(root)) {
|
|
629
|
+
throw new Error("Machine reached a terminal indexed configuration without a completed root output");
|
|
630
|
+
}
|
|
631
|
+
return {
|
|
632
|
+
event: decoded,
|
|
633
|
+
next: indexedStateFromActive(descriptor, completed),
|
|
634
|
+
commands: commands ?? emptyExecutionValues,
|
|
635
|
+
emittedEvents: emittedEvents ?? emptyExecutionValues,
|
|
636
|
+
microsteps: microsteps ?? emptyExecutionValues,
|
|
637
|
+
done: true,
|
|
638
|
+
output: completed.outputs.get(root)
|
|
639
|
+
};
|
|
567
640
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
:
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
641
|
+
const sourcePath = descriptor.nodes[sourceIndex].path;
|
|
642
|
+
const transition = normalizeTransition(toImpl(machine).handlers[sourcePath]?.on?.[event._tag]);
|
|
643
|
+
if (transition !== undefined) {
|
|
644
|
+
const transitionResult = collectIndexedTransition(machine, transition.transition, {
|
|
645
|
+
...resolveMachineReferences(machine, machineReferences),
|
|
646
|
+
state: current.values[sourceIndex],
|
|
647
|
+
containingState: undefined,
|
|
648
|
+
ancestors: {},
|
|
649
|
+
event,
|
|
650
|
+
snapshot: snapshotFromIndexedState(descriptor, current)
|
|
651
|
+
}, transition.evaluate);
|
|
652
|
+
const update = isStateUpdate(transitionResult.state) ? transitionResult.state : undefined;
|
|
653
|
+
const target = update === undefined ? transitionResult.state : undefined;
|
|
654
|
+
// The new value of the source state, when this microstep keeps it active.
|
|
655
|
+
let value = noIndexedValue;
|
|
656
|
+
if (update !== undefined) {
|
|
657
|
+
const node = descriptor.nodes[sourceIndex];
|
|
658
|
+
if (update.path !== sourcePath || node.schema === undefined) {
|
|
659
|
+
throw new Error(`Machine state update owner "${update.path}" must be the active valued state`);
|
|
660
|
+
}
|
|
661
|
+
value = decodeStateValueSync(machine, node, update.value);
|
|
577
662
|
}
|
|
578
|
-
|
|
579
|
-
|
|
663
|
+
validateDeclaredTransitionTarget(sourcePath, { type: "event", event: event._tag }, transition.targets, target);
|
|
664
|
+
if (target !== undefined && !isTarget(target) && !isSnapshot(target)) {
|
|
665
|
+
throw new Error("Machine expected indexed transition target to be a snapshot or target builder result");
|
|
580
666
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
...(retainMicrosteps
|
|
591
|
-
? {
|
|
592
|
-
transitions: [{
|
|
593
|
-
source: sourcePath,
|
|
594
|
-
trigger: { type: "event", event: event._tag },
|
|
595
|
-
reenter: transition.reenter,
|
|
596
|
-
branchIndex: transitionResult.branchIndex,
|
|
597
|
-
branchKey: transitionResult.branchKey,
|
|
598
|
-
target: target === undefined ? undefined : getTargetNodePath(target),
|
|
599
|
-
resolvedTarget: target === undefined ? undefined : getTargetNodePath(target),
|
|
600
|
-
updates: update === undefined ? [] : [update.path]
|
|
601
|
-
}]
|
|
667
|
+
let next = current;
|
|
668
|
+
if (target !== undefined) {
|
|
669
|
+
const targetIndex = descriptor.indexByPath.get(String(target.path));
|
|
670
|
+
const isSimpleTarget = isTarget(target)
|
|
671
|
+
? target[TargetSnapshotTypeId] === undefined && target.values === undefined
|
|
672
|
+
: !("state" in target) && !("states" in target) && !("completed" in target) && !("history" in target);
|
|
673
|
+
if (targetIndex === sourceIndex && isSimpleTarget && current.completedOrder.length === 0 &&
|
|
674
|
+
descriptor.valued[sourceIndex]) {
|
|
675
|
+
value = decodeStateValueSync(machine, descriptor.nodes[sourceIndex], target.value);
|
|
602
676
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
677
|
+
else {
|
|
678
|
+
next = normalizeIndexedTargetStateSync(machine, descriptor, current, target, sourceIndex);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
if (value !== noIndexedValue) {
|
|
682
|
+
if (!writable) {
|
|
683
|
+
current = withWritableIndexedValues(current);
|
|
684
|
+
writable = true;
|
|
685
|
+
}
|
|
686
|
+
else if (current === configuration && restoreIndex === -1) {
|
|
687
|
+
restoreIndex = sourceIndex;
|
|
688
|
+
restoreValue = configuration.values[sourceIndex];
|
|
689
|
+
}
|
|
690
|
+
current.values[sourceIndex] = value;
|
|
691
|
+
next = current;
|
|
692
|
+
}
|
|
693
|
+
const changed = transition.reenter || !hasSameIndexedActive(current, next);
|
|
694
|
+
const nextIndex = next.activeLeaves[0];
|
|
695
|
+
if (nextIndex === undefined) {
|
|
696
|
+
throw new Error("Machine expected an active indexed transition target");
|
|
697
|
+
}
|
|
698
|
+
const exitPaths = changed ? [sourcePath] : emptyExecutionValues;
|
|
699
|
+
const entryPaths = changed ? [descriptor.nodes[nextIndex].path] : emptyExecutionValues;
|
|
700
|
+
const step = retainMicrosteps
|
|
701
|
+
? new RetainedFlatMicrostep(next, event, transitionResult.commands, transitionResult.raisedEvents, transitionResult.emittedEvents, exitPaths, entryPaths, changed, sourcePath, transition.reenter, transitionResult.branchIndex, transitionResult.branchKey, target, update)
|
|
702
|
+
: {
|
|
703
|
+
next,
|
|
704
|
+
event,
|
|
705
|
+
commands: transitionResult.commands,
|
|
706
|
+
raisedEvents: transitionResult.raisedEvents,
|
|
707
|
+
emittedEvents: transitionResult.emittedEvents,
|
|
708
|
+
exitPaths,
|
|
709
|
+
entryPaths,
|
|
710
|
+
changed
|
|
711
|
+
};
|
|
712
|
+
// A state that this microstep created is referenced by nothing else,
|
|
713
|
+
// unless the microstep is retained.
|
|
714
|
+
if (next !== current)
|
|
715
|
+
writable = true;
|
|
716
|
+
current = next;
|
|
717
|
+
if (retainMicrosteps)
|
|
718
|
+
writable = false;
|
|
719
|
+
(microsteps ??= []).push(step);
|
|
720
|
+
if (transitionResult.commands.length > 0) {
|
|
721
|
+
;
|
|
722
|
+
(commands ??= []).push(...transitionResult.commands);
|
|
723
|
+
}
|
|
724
|
+
if (transitionResult.raisedEvents.length > 0) {
|
|
725
|
+
;
|
|
726
|
+
(raisedEvents ??= []).push(...transitionResult.raisedEvents);
|
|
727
|
+
}
|
|
728
|
+
if (transitionResult.emittedEvents.length > 0) {
|
|
729
|
+
;
|
|
730
|
+
(emittedEvents ??= []).push(...transitionResult.emittedEvents);
|
|
731
|
+
}
|
|
616
732
|
}
|
|
617
|
-
if (
|
|
618
|
-
;
|
|
619
|
-
(raisedEvents ??= []).push(...transitionResult.raisedEvents);
|
|
733
|
+
if (descriptor.nodes[current.activeLeaves[0]].type === "final") {
|
|
734
|
+
continue;
|
|
620
735
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
736
|
+
const raised = raisedEvents?.[raisedIndex];
|
|
737
|
+
if (raised === undefined) {
|
|
738
|
+
return {
|
|
739
|
+
event: decoded,
|
|
740
|
+
next: current,
|
|
741
|
+
commands: commands ?? emptyExecutionValues,
|
|
742
|
+
emittedEvents: emittedEvents ?? emptyExecutionValues,
|
|
743
|
+
microsteps: microsteps ?? emptyExecutionValues,
|
|
744
|
+
done: false,
|
|
745
|
+
output: undefined
|
|
746
|
+
};
|
|
624
747
|
}
|
|
748
|
+
raisedIndex += 1;
|
|
749
|
+
event = raised;
|
|
625
750
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
return {
|
|
632
|
-
event: decoded,
|
|
633
|
-
next: current,
|
|
634
|
-
commands: commands ?? emptyExecutionValues,
|
|
635
|
-
emittedEvents: emittedEvents ?? emptyExecutionValues,
|
|
636
|
-
microsteps: microsteps ?? emptyExecutionValues,
|
|
637
|
-
done: false,
|
|
638
|
-
output: undefined
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
raisedIndex += 1;
|
|
642
|
-
event = raised;
|
|
751
|
+
}
|
|
752
|
+
catch (error) {
|
|
753
|
+
if (restoreIndex !== -1)
|
|
754
|
+
configuration.values[restoreIndex] = restoreValue;
|
|
755
|
+
throw error;
|
|
643
756
|
}
|
|
644
757
|
};
|
|
645
|
-
const planIndexedState = (machine, descriptor, configuration, input, retainMicrosteps, machineReferences) => {
|
|
758
|
+
const planIndexedState = (machine, descriptor, configuration, input, decode, retainMicrosteps, ownership, machineReferences) => {
|
|
646
759
|
if (InvocationEvent.isInvocationEvent(input)) {
|
|
647
760
|
// Invocation lifecycle transitions retain the generic planner as their
|
|
648
761
|
// semantic reference. Ordinary machine events and initialization stay on
|
|
@@ -653,11 +766,11 @@ const planIndexedState = (machine, descriptor, configuration, input, retainMicro
|
|
|
653
766
|
: withMachineReferences(activeConfigurationFromIndexedState(descriptor, configuration), machineReferences), input);
|
|
654
767
|
return {
|
|
655
768
|
event: planned.event,
|
|
656
|
-
next:
|
|
769
|
+
next: indexedStateFromActive(descriptor, planned.next),
|
|
657
770
|
commands: planned.commands,
|
|
658
771
|
emittedEvents: planned.emittedEvents,
|
|
659
772
|
microsteps: planned.microsteps.map((step) => ({
|
|
660
|
-
next:
|
|
773
|
+
next: indexedStateFromActive(descriptor, step.next),
|
|
661
774
|
event: step.event,
|
|
662
775
|
transitions: step.transitions,
|
|
663
776
|
commands: step.commands,
|
|
@@ -671,10 +784,12 @@ const planIndexedState = (machine, descriptor, configuration, input, retainMicro
|
|
|
671
784
|
output: planned.output
|
|
672
785
|
};
|
|
673
786
|
}
|
|
674
|
-
const decoded = decodeEventSync(machine, input);
|
|
787
|
+
const decoded = decode ? decodeEventSync(machine, input) : input;
|
|
675
788
|
if (descriptor.flat) {
|
|
676
|
-
return planIndexedFlatState(machine, descriptor, configuration, decoded, retainMicrosteps, machineReferences);
|
|
789
|
+
return planIndexedFlatState(machine, descriptor, configuration, decoded, retainMicrosteps, ownership, machineReferences);
|
|
677
790
|
}
|
|
791
|
+
// The hierarchical kernel never writes a state in place, so it plans every
|
|
792
|
+
// ownership alike.
|
|
678
793
|
if (descriptor.finalIndices.some((index) => configuration.active[index] === 1)) {
|
|
679
794
|
const active = activeConfigurationFromIndexedState(descriptor, configuration);
|
|
680
795
|
if (isActiveFinalConfiguration(machine, active)) {
|
|
@@ -685,7 +800,7 @@ const planIndexedState = (machine, descriptor, configuration, input, retainMicro
|
|
|
685
800
|
}
|
|
686
801
|
return {
|
|
687
802
|
event: decoded,
|
|
688
|
-
next:
|
|
803
|
+
next: indexedStateFromActive(descriptor, completed),
|
|
689
804
|
commands: [],
|
|
690
805
|
emittedEvents: [],
|
|
691
806
|
microsteps: [],
|
|
@@ -712,7 +827,7 @@ const planIndexedState = (machine, descriptor, configuration, input, retainMicro
|
|
|
712
827
|
const commands = [...first.commands];
|
|
713
828
|
const raisedEvents = [...first.raisedEvents];
|
|
714
829
|
const emittedEvents = [...first.emittedEvents];
|
|
715
|
-
const microsteps = [
|
|
830
|
+
const microsteps = [first];
|
|
716
831
|
let raisedIndex = 0;
|
|
717
832
|
let iterations = 0;
|
|
718
833
|
while (true) {
|
|
@@ -726,7 +841,7 @@ const planIndexedState = (machine, descriptor, configuration, input, retainMicro
|
|
|
726
841
|
}
|
|
727
842
|
if (descriptor.finalIndices.some((index) => current.active[index] === 1)) {
|
|
728
843
|
const completed = completeConfigurationSync(machine, activeConfigurationFromIndexedState(descriptor, current), currentEvent).configuration;
|
|
729
|
-
current =
|
|
844
|
+
current = indexedStateFromActive(descriptor, completed);
|
|
730
845
|
if (isActiveFinalConfiguration(machine, completed)) {
|
|
731
846
|
const root = getRootPath(machine, completed);
|
|
732
847
|
if (!completed.outputs.has(root)) {
|
|
@@ -765,23 +880,29 @@ const planIndexedState = (machine, descriptor, configuration, input, retainMicro
|
|
|
765
880
|
commands.push(...step.commands);
|
|
766
881
|
raisedEvents.push(...step.raisedEvents);
|
|
767
882
|
emittedEvents.push(...step.emittedEvents);
|
|
768
|
-
microsteps.push(
|
|
883
|
+
microsteps.push(step);
|
|
769
884
|
}
|
|
770
885
|
};
|
|
771
886
|
const executionPlanCache = new WeakMap();
|
|
887
|
+
const referenceExecutionPlanCache = new WeakMap();
|
|
772
888
|
const makeActiveExecutionPlan = (machine) => ({
|
|
773
889
|
fromConfiguration: (configuration) => configuration,
|
|
774
890
|
toConfiguration: (state) => state,
|
|
775
891
|
snapshot: (state) => snapshotFromConfiguration(machine, state),
|
|
776
|
-
|
|
892
|
+
// The reference planner never writes a configuration in place.
|
|
893
|
+
plan: (state, event, _ownership, _retainMicrosteps, machineReferences) => planConfiguration(machine, machineReferences === undefined
|
|
894
|
+
? state
|
|
895
|
+
: withMachineReferences(state, machineReferences), event),
|
|
896
|
+
planDecoded: (state, event, _ownership, _retainMicrosteps, machineReferences) => planDecodedConfiguration(machine, machineReferences === undefined
|
|
777
897
|
? state
|
|
778
898
|
: withMachineReferences(state, machineReferences), event)
|
|
779
899
|
});
|
|
780
900
|
const makeIndexedExecutionPlan = (machine, indexed) => ({
|
|
781
|
-
fromConfiguration: (configuration) =>
|
|
901
|
+
fromConfiguration: (configuration) => indexedStateFromActive(indexed, configuration),
|
|
782
902
|
toConfiguration: (state) => activeConfigurationFromIndexedState(indexed, state),
|
|
783
903
|
snapshot: (state) => snapshotFromIndexedState(indexed, state),
|
|
784
|
-
plan: (state, event, retainMicrosteps
|
|
904
|
+
plan: (state, event, ownership, retainMicrosteps, machineReferences) => planIndexedState(machine, indexed, state, event, true, retainMicrosteps, ownership, machineReferences),
|
|
905
|
+
planDecoded: (state, event, ownership, retainMicrosteps, machineReferences) => planIndexedState(machine, indexed, state, event, false, retainMicrosteps, ownership, machineReferences),
|
|
785
906
|
// Only captured data constructors can use indexed startup. Unknown initializer
|
|
786
907
|
// protocols retain generic startup so commands and emissions cannot be dropped.
|
|
787
908
|
...(Object.values(toImpl(machine).handlers).some((config) => config.initialize !== undefined && !isDataInitializer(config.initialize)) ?
|
|
@@ -807,7 +928,7 @@ const makeIndexedExecutionPlan = (machine, indexed) => ({
|
|
|
807
928
|
? normalized
|
|
808
929
|
: withMachineReferences(normalized, machineReferences);
|
|
809
930
|
const completed = completeConfigurationSync(machine, active, InitialEvent).configuration;
|
|
810
|
-
const configuration =
|
|
931
|
+
const configuration = indexedStateFromActive(indexed, completed);
|
|
811
932
|
const state = snapshotFromIndexedState(indexed, configuration);
|
|
812
933
|
const done = isActiveFinalConfiguration(machine, completed);
|
|
813
934
|
if (!done) {
|
|
@@ -835,25 +956,23 @@ const makeIndexedExecutionPlan = (machine, indexed) => ({
|
|
|
835
956
|
}
|
|
836
957
|
})
|
|
837
958
|
});
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
const selected = indexed.flat ? "indexed-flat" : "indexed-hierarchical";
|
|
850
|
-
if (strategy !== "auto" && strategy !== selected) {
|
|
851
|
-
throw new Error(`Machine compiled ${selected}, not the requested ${strategy} execution plan`);
|
|
959
|
+
const executionPlanStrategyCache = new WeakMap();
|
|
960
|
+
/**
|
|
961
|
+
* The reference execution plan of `machine`, which always plans on the generic
|
|
962
|
+
* planner without indexed compilation. Cached per machine.
|
|
963
|
+
*
|
|
964
|
+
* @internal
|
|
965
|
+
*/
|
|
966
|
+
export const referenceExecutionPlan = (machine) => {
|
|
967
|
+
const cached = referenceExecutionPlanCache.get(machine);
|
|
968
|
+
if (cached !== undefined) {
|
|
969
|
+
return cached;
|
|
852
970
|
}
|
|
853
|
-
|
|
971
|
+
const reference = makeActiveExecutionPlan(machine);
|
|
972
|
+
referenceExecutionPlanCache.set(machine, reference);
|
|
973
|
+
executionPlanStrategyCache.set(reference, "generic");
|
|
974
|
+
return reference;
|
|
854
975
|
};
|
|
855
|
-
/** @internal Test-only uncached strategy selection. */
|
|
856
|
-
export const selectExecutionPlanForTesting = (machine, strategy) => selectExecutionPlan(machine, strategy);
|
|
857
976
|
export const compileExecutionPlan = (machine) => {
|
|
858
977
|
const cached = executionPlanCache.get(machine);
|
|
859
978
|
if (cached !== undefined) {
|
|
@@ -861,9 +980,27 @@ export const compileExecutionPlan = (machine) => {
|
|
|
861
980
|
}
|
|
862
981
|
const indexed = compileIndexedExecutionDescriptor(machine);
|
|
863
982
|
const compiled = indexed === undefined
|
|
864
|
-
?
|
|
983
|
+
? referenceExecutionPlan(machine)
|
|
865
984
|
: makeIndexedExecutionPlan(machine, indexed);
|
|
985
|
+
if (indexed !== undefined) {
|
|
986
|
+
executionPlanStrategyCache.set(compiled, indexed.flat ? "indexed-flat" : "indexed-hierarchical");
|
|
987
|
+
}
|
|
866
988
|
executionPlanCache.set(machine, compiled);
|
|
867
989
|
return compiled;
|
|
868
990
|
};
|
|
991
|
+
/** @internal Test-only planner selection, delegating to the cached reference and compiled plans. */
|
|
992
|
+
export const selectExecutionPlanForTesting = (machine, strategy) => {
|
|
993
|
+
if (strategy === "generic") {
|
|
994
|
+
return { strategy, plan: referenceExecutionPlan(machine) };
|
|
995
|
+
}
|
|
996
|
+
const plan = compileExecutionPlan(machine);
|
|
997
|
+
const selected = executionPlanStrategyCache.get(plan) ?? "generic";
|
|
998
|
+
if (strategy !== "auto" && strategy !== selected) {
|
|
999
|
+
if (selected === "generic") {
|
|
1000
|
+
throw new Error(`Machine cannot compile the requested ${strategy} execution plan`);
|
|
1001
|
+
}
|
|
1002
|
+
throw new Error(`Machine compiled ${selected}, not the requested ${strategy} execution plan`);
|
|
1003
|
+
}
|
|
1004
|
+
return { strategy: selected, plan };
|
|
1005
|
+
};
|
|
869
1006
|
//# sourceMappingURL=executionPlan.js.map
|