Commit 868de9a1 authored by Robert Griesemer's avatar Robert Griesemer

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/+/198044Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent c7d7042e
...@@ -69,7 +69,7 @@ func (check *Checker) initOrder() { ...@@ -69,7 +69,7 @@ func (check *Checker) initOrder() {
// if n still depends on other nodes, we have a cycle // if n still depends on other nodes, we have a cycle
if n.ndeps > 0 { 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), // 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 // cycle will be nil. Don't report anything in that case since
// the cycle is reported when the algorithm gets to an object // the cycle is reported when the algorithm gets to an object
...@@ -130,17 +130,17 @@ func (check *Checker) initOrder() { ...@@ -130,17 +130,17 @@ func (check *Checker) initOrder() {
// findPath returns the (reversed) list of objects []Object{to, ... from} // findPath returns the (reversed) list of objects []Object{to, ... from}
// such that there is a path of object dependencies from 'from' to 'to'. // such that there is a path of object dependencies from 'from' to 'to'.
// If there is no such path, the result is nil. // If there is no such path, the result is nil.
func findPath(objMap map[Object]*declInfo, from, to Object, visited objSet) []Object { func findPath(objMap map[Object]*declInfo, from, to Object, seen map[Object]bool) []Object {
if visited[from] { if seen[from] {
return nil // node already seen return nil
} }
visited[from] = true seen[from] = true
for d := range objMap[from].deps { for d := range objMap[from].deps {
if d == to { if d == to {
return []Object{d} 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) return append(P, d)
} }
} }
......
...@@ -25,12 +25,9 @@ type declInfo struct { ...@@ -25,12 +25,9 @@ type declInfo struct {
alias bool // type alias declaration alias bool // type alias declaration
// The deps field tracks initialization expression dependencies. // 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 // hasInitializer reports whether the declared object has an initialization
// expression or function body. // expression or function body.
func (d *declInfo) hasInitializer() bool { func (d *declInfo) hasInitializer() bool {
...@@ -41,7 +38,7 @@ func (d *declInfo) hasInitializer() bool { ...@@ -41,7 +38,7 @@ func (d *declInfo) hasInitializer() bool {
func (d *declInfo) addDep(obj Object) { func (d *declInfo) addDep(obj Object) {
m := d.deps m := d.deps
if m == nil { if m == nil {
m = make(objSet) m = make(map[Object]bool)
d.deps = m d.deps = m
} }
m[obj] = true m[obj] = true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment