From 868de9a11179190f9830ece27de5a8eb63b2f3de Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 1 Oct 2019 12:34:06 -0700 Subject: [PATCH] go/types: remove objSet type in favor of explicit map type (cleanup) Avoid confusion between (now gone) objSet and objset types. Also: rename visited -> seen in initorder.go. No functional changes. Change-Id: Ib0aa25e006eee55a79a739194d0d26190354a9f2 Reviewed-on: https://go-review.googlesource.com/c/go/+/198044 Reviewed-by: Matthew Dempsky --- src/go/types/initorder.go | 12 ++++++------ src/go/types/resolver.go | 7 ++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/go/types/initorder.go b/src/go/types/initorder.go index 966dccb828..9d5e9165ad 100644 --- a/src/go/types/initorder.go +++ b/src/go/types/initorder.go @@ -69,7 +69,7 @@ func (check *Checker) initOrder() { // 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 @@ -130,17 +130,17 @@ func (check *Checker) initOrder() { // 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) } } diff --git a/src/go/types/resolver.go b/src/go/types/resolver.go index 20730340ed..d66a5428ff 100644 --- a/src/go/types/resolver.go +++ b/src/go/types/resolver.go @@ -25,12 +25,9 @@ type declInfo struct { 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 { @@ -41,7 +38,7 @@ 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 -- 2.50.0