]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: remove objSet type in favor of explicit map type (cleanup)
authorRobert Griesemer <gri@golang.org>
Tue, 1 Oct 2019 19:34:06 +0000 (12:34 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 8 Oct 2019 17:30:14 +0000 (17:30 +0000)
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>
src/go/types/initorder.go
src/go/types/resolver.go

index 966dccb8289f636eaa5bc3d26171c4a792561b8a..9d5e9165ad8f3177a87bd02d0691c3bd8dc4a20e 100644 (file)
@@ -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)
                }
        }
index 20730340edd2ec14e301ef9a1d986c2fe850bc6d..d66a5428ff7a1ff896c547c9d759442e1c8ac83a 100644 (file)
@@ -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