Skip to content

Commit c8ca678

Browse files
committed
dap: filter inputs for a step to prevent overeager evaluation
When the debug thread was updated to always solve inputs from the operation that it was tied to it became a bit overeager to evaluate them. The intention of the steps is to have a single direct parent and then potentially multiple "function calls" that can be evaluated with step into and step out to leave. With the change, that logic stayed in, but the inputs were always being evaluated before they were stepped into or over. Now, when we construct the steps, we also attach a list of inputs that we should defer evaluation on to ensure we don't execute inputs that haven't been executed yet. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
1 parent 75c53e3 commit c8ca678

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

dap/thread.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dap
22

33
import (
44
"context"
5+
"maps"
56
"path"
67
"path/filepath"
78
"slices"
@@ -127,6 +128,10 @@ type step struct {
127128
// breakpoint resolution.
128129
dgst digest.Digest
129130

131+
// filtered holds the inputs that should be filtered out of the
132+
// solved inputs.
133+
filtered map[int]bool
134+
130135
// in holds the next target when step in is used.
131136
in *step
132137

@@ -221,7 +226,17 @@ func (t *thread) createBranch(dgst digest.Digest, exitpoint *step) (entrypoint *
221226
// Create the routine associated with this input.
222227
// Associate it with the entrypoint in step.
223228
head.in = t.createBranch(digest.Digest(inp.Digest), entrypoint)
229+
224230
entrypoint = &head
231+
232+
// Filter this input from the target so it doesn't get solved
233+
// when moving to this step.
234+
if entrypoint.filtered != nil {
235+
entrypoint.filtered = maps.Clone(entrypoint.filtered)
236+
} else {
237+
entrypoint.filtered = make(map[int]bool)
238+
}
239+
entrypoint.filtered[i] = true
225240
}
226241

227242
// If we have no direct parent, return the current entrypoint
@@ -232,11 +247,12 @@ func (t *thread) createBranch(dgst digest.Digest, exitpoint *step) (entrypoint *
232247

233248
// Create a new step that refers to the direct parent.
234249
head := &step{
235-
dgst: digest.Digest(op.Inputs[entrypoint.parent].Digest),
236-
in: entrypoint,
237-
next: entrypoint,
238-
out: entrypoint.out,
239-
parent: -1,
250+
dgst: digest.Digest(op.Inputs[entrypoint.parent].Digest),
251+
filtered: entrypoint.filtered,
252+
in: entrypoint,
253+
next: entrypoint,
254+
out: entrypoint.out,
255+
parent: -1,
240256
}
241257
head.frame = t.getStackFrame(head.dgst, entrypoint)
242258
entrypoint = head
@@ -561,6 +577,10 @@ func (t *thread) solveInputs(ctx context.Context, target *step) (string, map[str
561577
var root string
562578
refs := make(map[string]gateway.Reference)
563579
for i, input := range op.Inputs {
580+
if target.filtered[i] {
581+
continue
582+
}
583+
564584
k := t.determineInputName(op, i, input)
565585
if _, ok := refs[k]; ok || k == "" {
566586
continue

0 commit comments

Comments
 (0)