]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: factor out some code, fix/add comments (cleanups)
authorRobert Griesemer <gri@golang.org>
Mon, 27 Sep 2021 03:45:54 +0000 (20:45 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 27 Sep 2021 18:44:47 +0000 (18:44 +0000)
Change-Id: Id6a2e3eadc9099abbdd21b6880e1ff3ac9cfb599
Reviewed-on: https://go-review.googlesource.com/c/go/+/352312
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/infer.go
src/cmd/compile/internal/types2/unify.go
src/go/types/infer.go
src/go/types/unify.go

index 914ee9ea5d907ffe42a0daf2c6fd5ab9349d07aa..ad8c6ac41233db2727986e6a5b43c42245c09f2d 100644 (file)
@@ -334,7 +334,7 @@ func (w *tpWalker) isParameterized(typ Type) (res bool) {
 
        case *TypeParam:
                // t must be one of w.tparams
-               return t.index < len(w.tparams) && w.tparams[t.index] == t
+               return tparamIndex(w.tparams, t) >= 0
 
        default:
                unreachable()
index bb69f0d27bc13baa4e83f0ffbba5658dcd6bc7c2..a252c5e1a56973e4cfeb8549d0eb92dd1fdc8863 100644 (file)
@@ -108,7 +108,7 @@ func (d *tparamsList) init(tparams []*TypeParam) {
 
 // join unifies the i'th type parameter of x with the j'th type parameter of y.
 // If both type parameters already have a type associated with them and they are
-// not joined, join fails and return false.
+// not joined, join fails and returns false.
 func (u *unifier) join(i, j int) bool {
        ti := u.x.indices[i]
        tj := u.y.indices[j]
@@ -132,6 +132,7 @@ func (u *unifier) join(i, j int) bool {
                break
        case ti > 0 && tj > 0:
                // Both type parameters have (possibly different) inferred types. Cannot join.
+               // TODO(gri) Should we check if types are identical? Investigate.
                return false
        case ti > 0:
                // Only the type parameter for x has an inferred type. Use x slot for y.
@@ -226,7 +227,7 @@ func (u *unifier) nifyEq(x, y Type, p *ifacePair) bool {
 }
 
 // nify implements the core unification algorithm which is an
-// adapted version of Checker.identical0. For changes to that
+// adapted version of Checker.identical. For changes to that
 // code the corresponding changes should be made here.
 // Must not be called directly from outside the unifier.
 func (u *unifier) nify(x, y Type, p *ifacePair) bool {
@@ -427,6 +428,7 @@ func (u *unifier) nify(x, y Type, p *ifacePair) bool {
                }
 
        case *Named:
+               // TODO(gri) This code differs now from the parallel code in Checker.identical. Investigate.
                if y, ok := y.(*Named); ok {
                        xargs := x.targs.list()
                        yargs := y.targs.list()
index 1c4915571d497e8ad344b4d1db69e4d3be4c72bc..0be01d31e8f1f98b25f4a656cceaa3d6bb847eb4 100644 (file)
@@ -329,7 +329,7 @@ func (w *tpWalker) isParameterized(typ Type) (res bool) {
 
        case *TypeParam:
                // t must be one of w.tparams
-               return t.index < len(w.tparams) && w.tparams[t.index] == t
+               return tparamIndex(w.tparams, t) >= 0
 
        default:
                unreachable()
index 6d10f71a9010ff5459a3ff300ded5931d953f038..ce78fc8241ca3cb65144dc3fa9298092b379d15e 100644 (file)
@@ -109,7 +109,7 @@ func (d *tparamsList) init(tparams []*TypeParam) {
 
 // join unifies the i'th type parameter of x with the j'th type parameter of y.
 // If both type parameters already have a type associated with them and they are
-// not joined, join fails and return false.
+// not joined, join fails and returns false.
 func (u *unifier) join(i, j int) bool {
        ti := u.x.indices[i]
        tj := u.y.indices[j]
@@ -133,6 +133,7 @@ func (u *unifier) join(i, j int) bool {
                break
        case ti > 0 && tj > 0:
                // Both type parameters have (possibly different) inferred types. Cannot join.
+               // TODO(gri) Should we check if types are identical? Investigate.
                return false
        case ti > 0:
                // Only the type parameter for x has an inferred type. Use x slot for y.
@@ -223,7 +224,7 @@ func (u *unifier) nifyEq(x, y Type, p *ifacePair) bool {
 }
 
 // nify implements the core unification algorithm which is an
-// adapted version of Checker.identical0. For changes to that
+// adapted version of Checker.identical. For changes to that
 // code the corresponding changes should be made here.
 // Must not be called directly from outside the unifier.
 func (u *unifier) nify(x, y Type, p *ifacePair) bool {
@@ -424,6 +425,7 @@ func (u *unifier) nify(x, y Type, p *ifacePair) bool {
                }
 
        case *Named:
+               // TODO(gri) This code differs now from the parallel code in Checker.identical. Investigate.
                if y, ok := y.(*Named); ok {
                        xargs := x.targs.list()
                        yargs := y.targs.list()