// if n still depends on other nodes, we have a cycle
if n.ndeps > 0 {
- cycle := findPath(check.objMap, n.obj, n.obj, make(objSet))
+ cycle := findPath(check.objMap, n.obj, n.obj, make(map[Object]bool))
// If n.obj is not part of the cycle (e.g., n.obj->b->c->d->c),
// cycle will be nil. Don't report anything in that case since
// the cycle is reported when the algorithm gets to an object
// findPath returns the (reversed) list of objects []Object{to, ... from}
// such that there is a path of object dependencies from 'from' to 'to'.
// If there is no such path, the result is nil.
-func findPath(objMap map[Object]*declInfo, from, to Object, visited objSet) []Object {
- if visited[from] {
- return nil // node already seen
+func findPath(objMap map[Object]*declInfo, from, to Object, seen map[Object]bool) []Object {
+ if seen[from] {
+ return nil
}
- visited[from] = true
+ seen[from] = true
for d := range objMap[from].deps {
if d == to {
return []Object{d}
}
- if P := findPath(objMap, d, to, visited); P != nil {
+ if P := findPath(objMap, d, to, seen); P != nil {
return append(P, d)
}
}
alias bool // type alias declaration
// The deps field tracks initialization expression dependencies.
- deps objSet // lazily initialized
+ deps map[Object]bool // lazily initialized
}
-// An objSet is simply a set of objects.
-type objSet map[Object]bool
-
// hasInitializer reports whether the declared object has an initialization
// expression or function body.
func (d *declInfo) hasInitializer() bool {
func (d *declInfo) addDep(obj Object) {
m := d.deps
if m == nil {
- m = make(objSet)
+ m = make(map[Object]bool)
d.deps = m
}
m[obj] = true