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 authored Jan 14, 2025
1 parent 6da1601 commit e473ae2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/cmd/compile/internal/types2/initorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,16 @@ func findPath(objMap map[Object]*declInfo, from, to Object, seen map[Object]bool
return nil
}
seen[from] = true

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

for d := range objMap[from].deps {
// 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 d == to {
return []Object{d}
}
Expand Down

0 comments on commit e473ae2

Please sign in to comment.