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 <mdempsky@google.com>
diff --git a/src/go/types/initorder.go b/src/go/types/initorder.go
index 966dccb..9d5e916 100644
--- a/src/go/types/initorder.go
+++ b/src/go/types/initorder.go
@@ -69,7 +69,7 @@
// 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 @@
// 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 2073034..d66a542 100644
--- a/src/go/types/resolver.go
+++ b/src/go/types/resolver.go
@@ -25,12 +25,9 @@
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) addDep(obj Object) {
m := d.deps
if m == nil {
- m = make(objSet)
+ m = make(map[Object]bool)
d.deps = m
}
m[obj] = true