Skip to content

Commit cbeae8a

Browse files
Revert some of the debug snapshotting stuff to prep for a better approach.
Reverts 2 commits: - Revert "Step 2/2: Introduce diagnostics for workflow outputs." This reverts commit 29bae34. - Revert "Step 1/2: Introduce debug snapshots for emitting diagnostic information about the workflow tree." This reverts commit 1cee014.
1 parent 6021294 commit cbeae8a

File tree

19 files changed

+99
-742
lines changed

19 files changed

+99
-742
lines changed

kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/mainactivity/MainActivity.kt

+1-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import com.squareup.sample.panel.PanelContainer
2424
import com.squareup.workflow.ui.ViewRegistry
2525
import com.squareup.workflow.ui.WorkflowRunner
2626
import com.squareup.workflow.ui.setContentWorkflow
27-
import io.reactivex.disposables.CompositeDisposable
2827
import io.reactivex.disposables.Disposables
2928
import timber.log.Timber
3029

@@ -53,10 +52,7 @@ class MainActivity : AppCompatActivity() {
5352
finish()
5453
}
5554

56-
loggingSub = CompositeDisposable(
57-
workflowRunner.renderings.subscribe { Timber.d("rendering: %s", it) },
58-
workflowRunner.debugInfo.subscribe { Timber.v("debug snapshot: %s", it) }
59-
)
55+
loggingSub = workflowRunner.renderings.subscribe { Timber.d("rendering: %s", it) }
6056
}
6157

6258
override fun onSaveInstanceState(outState: Bundle) {

kotlin/workflow-runtime/src/main/java/com/squareup/workflow/LaunchWorkflow.kt

+2-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.squareup.workflow
1717

18-
import com.squareup.workflow.debugging.WorkflowDebugInfo
1918
import com.squareup.workflow.internal.RealWorkflowLoop
2019
import com.squareup.workflow.internal.WorkflowLoop
2120
import com.squareup.workflow.internal.unwrapCancellationCause
@@ -152,15 +151,10 @@ internal fun <PropsT, StateT, OutputT : Any, RenderingT, RunnerT> launchWorkflow
152151
): RunnerT {
153152
val renderingsAndSnapshots = ConflatedBroadcastChannel<RenderingAndSnapshot<RenderingT>>()
154153
val outputs = BroadcastChannel<OutputT>(capacity = 1)
155-
val debugSnapshots = ConflatedBroadcastChannel<WorkflowDebugInfo>()
156154
val workflowScope = scope + Job(parent = scope.coroutineContext[Job])
157155

158156
// Give the caller a chance to start collecting outputs.
159-
val session = WorkflowSession(
160-
renderingsAndSnapshots.asFlow(),
161-
outputs.asFlow(),
162-
debugSnapshots.asFlow()
163-
)
157+
val session = WorkflowSession(renderingsAndSnapshots.asFlow(), outputs.asFlow())
164158
val result = beforeStart(workflowScope, session)
165159

166160
val workflowJob = workflowScope.launch {
@@ -171,8 +165,7 @@ internal fun <PropsT, StateT, OutputT : Any, RenderingT, RunnerT> launchWorkflow
171165
initialSnapshot = initialSnapshot,
172166
initialState = initialState,
173167
onRendering = renderingsAndSnapshots::send,
174-
onOutput = outputs::send,
175-
onDebugSnapshot = debugSnapshots::send
168+
onOutput = outputs::send
176169
)
177170
}
178171

@@ -183,7 +176,6 @@ internal fun <PropsT, StateT, OutputT : Any, RenderingT, RunnerT> launchWorkflow
183176
val realCause = cause?.unwrapCancellationCause()
184177
renderingsAndSnapshots.close(realCause)
185178
outputs.close(realCause)
186-
debugSnapshots.close(realCause)
187179

188180
// If the cancellation came from inside the workflow loop, the outer runtime scope needs to be
189181
// explicitly cancelled. See https://github.com/square/workflow/issues/464.

kotlin/workflow-runtime/src/main/java/com/squareup/workflow/WorkflowSession.kt

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@
1515
*/
1616
package com.squareup.workflow
1717

18-
import com.squareup.workflow.debugging.WorkflowDebugInfo
1918
import kotlinx.coroutines.flow.Flow
2019

2120
/**
2221
* A tuple of [Flow]s representing all the emissions from the workflow runtime.
2322
*
2423
* Passed to the function taken by [launchWorkflowIn].
25-
*
26-
* @param debugInfo A stream of [diagnostic information][WorkflowDebugInfo] about the runtime.
2724
*/
2825
class WorkflowSession<out OutputT : Any, out RenderingT>(
2926
val renderingsAndSnapshots: Flow<RenderingAndSnapshot<RenderingT>>,
30-
val outputs: Flow<OutputT>,
31-
val debugInfo: Flow<WorkflowDebugInfo>
27+
val outputs: Flow<OutputT>
3228
)

kotlin/workflow-runtime/src/main/java/com/squareup/workflow/debugging/WorkflowDebugInfo.kt

-28
This file was deleted.

kotlin/workflow-runtime/src/main/java/com/squareup/workflow/internal/Behavior.kt

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package com.squareup.workflow.internal
1818
import com.squareup.workflow.Worker
1919
import com.squareup.workflow.Workflow
2020
import com.squareup.workflow.WorkflowAction
21-
import com.squareup.workflow.debugging.WorkflowHierarchyDebugSnapshot.Child
2221
import kotlinx.coroutines.Deferred
2322

2423
/**
@@ -30,7 +29,6 @@ import kotlinx.coroutines.Deferred
3029
*/
3130
data class Behavior<StateT, out OutputT : Any> internal constructor(
3231
val childCases: List<WorkflowOutputCase<*, *, StateT, OutputT>>,
33-
val childDebugSnapshots: List<Child>,
3432
val workerCases: List<WorkerCase<*, StateT, OutputT>>,
3533
val nextActionFromEvent: Deferred<WorkflowAction<StateT, OutputT>>
3634
) {

kotlin/workflow-runtime/src/main/java/com/squareup/workflow/internal/OutputEnvelope.kt

-27
This file was deleted.

kotlin/workflow-runtime/src/main/java/com/squareup/workflow/internal/RealRenderContext.kt

+2-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import com.squareup.workflow.Sink
2323
import com.squareup.workflow.Worker
2424
import com.squareup.workflow.Workflow
2525
import com.squareup.workflow.WorkflowAction
26-
import com.squareup.workflow.debugging.WorkflowHierarchyDebugSnapshot.Child
2726
import com.squareup.workflow.internal.Behavior.WorkerCase
2827
import com.squareup.workflow.internal.Behavior.WorkflowOutputCase
2928
import kotlinx.coroutines.CompletableDeferred
@@ -43,13 +42,12 @@ class RealRenderContext<StateT, OutputT : Any>(
4342
child: Workflow<ChildPropsT, ChildOutputT, ChildRenderingT>,
4443
id: WorkflowId<ChildPropsT, ChildOutputT, ChildRenderingT>,
4544
props: ChildPropsT
46-
): RenderingEnvelope<ChildRenderingT>
45+
): ChildRenderingT
4746
}
4847

4948
private val nextUpdateFromEvent = CompletableDeferred<WorkflowAction<StateT, OutputT>>()
5049
private val workerCases = mutableListOf<WorkerCase<*, StateT, OutputT>>()
5150
private val childCases = mutableListOf<WorkflowOutputCase<*, *, StateT, OutputT>>()
52-
private val childDebugSnapshots = mutableListOf<Child>()
5351

5452
/** Used to prevent modifications to this object after [buildBehavior] is called. */
5553
private var frozen = false
@@ -95,11 +93,7 @@ class RealRenderContext<StateT, OutputT : Any>(
9593
val case: WorkflowOutputCase<ChildPropsT, ChildOutputT, StateT, OutputT> =
9694
WorkflowOutputCase(child, id, props, handler)
9795
childCases += case
98-
val (rendering, debugSnapshot) = renderer.render(case, child, id, props)
99-
// Hold onto the description of this child's state for later, so we can include it in the
100-
// parent's debug snapshot tree.
101-
childDebugSnapshots += Child(key, debugSnapshot)
102-
return rendering
96+
return renderer.render(case, child, id, props)
10397
}
10498

10599
override fun <T> runningWorker(
@@ -119,7 +113,6 @@ class RealRenderContext<StateT, OutputT : Any>(
119113
frozen = true
120114
return Behavior(
121115
childCases = childCases.toList(),
122-
childDebugSnapshots = childDebugSnapshots.toList(),
123116
workerCases = workerCases.toList(),
124117
nextActionFromEvent = nextUpdateFromEvent
125118
)

kotlin/workflow-runtime/src/main/java/com/squareup/workflow/internal/RenderingEnvelope.kt

-28
This file was deleted.

kotlin/workflow-runtime/src/main/java/com/squareup/workflow/internal/SubtreeManager.kt

+5-29
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import com.squareup.workflow.Snapshot
1919
import com.squareup.workflow.StatefulWorkflow
2020
import com.squareup.workflow.Workflow
2121
import com.squareup.workflow.WorkflowAction
22-
import com.squareup.workflow.WorkflowAction.Companion.noAction
23-
import com.squareup.workflow.debugging.WorkflowUpdateDebugInfo.Kind
24-
import com.squareup.workflow.debugging.WorkflowUpdateDebugInfo.Source
2522
import com.squareup.workflow.internal.Behavior.WorkflowOutputCase
2623
import com.squareup.workflow.parse
2724
import com.squareup.workflow.readByteStringWithLength
@@ -62,7 +59,7 @@ internal class SubtreeManager<StateT, OutputT : Any>(
6259
child: Workflow<ChildPropsT, ChildOutputT, ChildRenderingT>,
6360
id: WorkflowId<ChildPropsT, ChildOutputT, ChildRenderingT>,
6461
props: ChildPropsT
65-
): RenderingEnvelope<ChildRenderingT> {
62+
): ChildRenderingT {
6663
// @formatter:on
6764
// Start tracking this case so we can be ready to render it.
6865
@Suppress("UNCHECKED_CAST")
@@ -83,36 +80,15 @@ internal class SubtreeManager<StateT, OutputT : Any>(
8380
/**
8481
* Uses [selector] to invoke [WorkflowNode.tick] for every running child workflow this instance
8582
* is managing.
86-
*
87-
* If one of this workflow's children emits an output, [handler] will be called with the action
88-
* assigned to that workflow and a [Source.Subtree] describing the child that triggered the
89-
* update.
90-
*
91-
* Note that if [handler] is called with [Kind.Passthrough], the workflow action that gets
92-
* passed in will always be [noAction]. This is the only logical value because
93-
* [Kind.Passthrough] specifically means that this workflow did not actually get updated
94-
* itself, but one of its descendants did and this one is just part of the path down the tree.
9583
*/
9684
fun <T : Any> tickChildren(
97-
selector: SelectBuilder<OutputEnvelope<T>>,
98-
handler: (WorkflowAction<StateT, OutputT>, Kind) -> OutputEnvelope<T>
85+
selector: SelectBuilder<T?>,
86+
handler: (WorkflowAction<StateT, OutputT>) -> T?
9987
) {
10088
for ((case, host) in hostLifetimeTracker.lifetimes) {
10189
host.tick(selector) { output ->
102-
return@tick if (output.output != null) {
103-
val componentUpdate = case.acceptChildOutput(output.output)
104-
// This workflow's child emitted a non-null output: the WorkflowNode will execute the
105-
// WorkflowAction, and we need to pass DidUpdate to indicate that this workflow actually
106-
// got updated.
107-
handler(
108-
componentUpdate,
109-
Kind.Updated(Source.Subtree(case.id.name, output.output, output.debugInfo))
110-
)
111-
} else {
112-
// The child didn't actually emit an output, which means this workflow has nothing to do,
113-
// which means we will only report our child updating.
114-
handler(noAction(), Kind.Passthrough(case.id.name, output.debugInfo))
115-
}
90+
val componentUpdate = case.acceptChildOutput(output)
91+
return@tick handler(componentUpdate)
11692
}
11793
}
11894
}

kotlin/workflow-runtime/src/main/java/com/squareup/workflow/internal/WorkflowLoop.kt

+5-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package com.squareup.workflow.internal
1818
import com.squareup.workflow.RenderingAndSnapshot
1919
import com.squareup.workflow.Snapshot
2020
import com.squareup.workflow.StatefulWorkflow
21-
import com.squareup.workflow.debugging.WorkflowDebugInfo
2221
import kotlinx.coroutines.ExperimentalCoroutinesApi
2322
import kotlinx.coroutines.FlowPreview
2423
import kotlinx.coroutines.channels.consume
@@ -44,8 +43,7 @@ internal interface WorkflowLoop {
4443
initialSnapshot: Snapshot?,
4544
initialState: StateT? = null,
4645
onRendering: suspend (RenderingAndSnapshot<RenderingT>) -> Unit,
47-
onOutput: suspend (OutputT) -> Unit,
48-
onDebugSnapshot: suspend (WorkflowDebugInfo) -> Unit
46+
onOutput: suspend (OutputT) -> Unit
4947
): Nothing
5048
}
5149

@@ -58,12 +56,11 @@ internal object RealWorkflowLoop : WorkflowLoop {
5856
initialSnapshot: Snapshot?,
5957
initialState: StateT?,
6058
onRendering: suspend (RenderingAndSnapshot<RenderingT>) -> Unit,
61-
onOutput: suspend (OutputT) -> Unit,
62-
onDebugSnapshot: suspend (WorkflowDebugInfo) -> Unit
59+
onOutput: suspend (OutputT) -> Unit
6360
): Nothing = coroutineScope {
6461
val inputsChannel = props.produceIn(this)
6562
inputsChannel.consume {
66-
var output: OutputEnvelope<OutputT>? = null
63+
var output: OutputT? = null
6764
var input: PropsT = inputsChannel.receive()
6865
var inputsClosed = false
6966
val rootNode = WorkflowNode(
@@ -79,12 +76,11 @@ internal object RealWorkflowLoop : WorkflowLoop {
7976
while (true) {
8077
coroutineContext.ensureActive()
8178

82-
val (rendering, debugSnapshot) = rootNode.render(workflow, input)
79+
val rendering = rootNode.render(workflow, input)
8380
val snapshot = rootNode.snapshot(workflow)
8481

8582
onRendering(RenderingAndSnapshot(rendering, snapshot))
86-
onDebugSnapshot(WorkflowDebugInfo(debugSnapshot, output?.debugInfo))
87-
output?.output?.let { onOutput(it) }
83+
output?.let { onOutput(it) }
8884

8985
// Tick _might_ return an output, but if it returns null, it means the state or a child
9086
// probably changed, so we should re-render/snapshot and emit again.

0 commit comments

Comments
 (0)