Skip to content

Commit

Permalink
Fix algorithm for gathering Go build requests with coverage. (Cherry-…
Browse files Browse the repository at this point in the history
…pick of #20030) (#20032)

The previous algorithm did not check if a package had already been
traversed, which leads to exponential blowup of the queue.

Go doesn't support dependency cycles, so the previous algorithm
would converge eventually, but before it did so the queue could get
to sizes that were infinite in practice. This happened in a real-world
case.

Co-authored-by: Benjy Weinberger <[email protected]>
  • Loading branch information
WorkerPants and benjyw authored Oct 16, 2023
1 parent a6b544d commit f960947
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/python/pants/backend/go/goals/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,17 @@ def _lift_build_requests_with_coverage(
result: list[BuildGoPackageRequest] = []

queue: deque[BuildGoPackageRequest] = deque()
seen: set[BuildGoPackageRequest] = set()
queue.extend(roots)
seen.update(roots)

while queue:
build_request = queue.popleft()
if build_request.with_coverage:
result.append(build_request)
queue.extend(build_request.direct_dependencies)
unseen = [dd for dd in build_request.direct_dependencies if dd not in seen]
queue.extend(unseen)
seen.update(unseen)

return result

Expand Down

0 comments on commit f960947

Please sign in to comment.