Skip to content

Commit

Permalink
types2: ensure that the reportCycle has a deterministic output
Browse files Browse the repository at this point in the history
  • Loading branch information
wingrez committed Jan 14, 2025
1 parent 6da1601 commit 8c49d8f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/cmd/compile/internal/types2/initorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,15 @@ func findPath(objMap map[Object]*declInfo, from, to Object, seen map[Object]bool
}
seen[from] = true

for d := range objMap[from].deps {
if d == to {
return []Object{d}
}
if _, found := objMap[from].deps[to]; found {
return []Object{to}
}

// Sort in order to return a deterministic path, thereby guaranteeing consistent output in the `reportCycle`.
deps := slices.SortedFunc(maps.Keys(objMap[from].deps), func(o1 Object, o2 Object) int {
return int(o1.order()) - int(o2.order())
})
for _, d := range deps {
if P := findPath(objMap, d, to, seen); P != nil {
return append(P, d)
}
Expand Down

0 comments on commit 8c49d8f

Please sign in to comment.