]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: move tparamIndex from unify.go into infer.go
authorRobert Griesemer <gri@golang.org>
Fri, 27 Jan 2023 01:21:51 +0000 (17:21 -0800)
committerGopher Robot <gobot@golang.org>
Fri, 27 Jan 2023 14:34:03 +0000 (14:34 +0000)
Minor code reorganization: the next version of unify.go doesn't
need this function anymore, so move it where it is still used.

Change-Id: I6744a2361b5dfe2564ec73787a7a110e85ac9f1d
Reviewed-on: https://go-review.googlesource.com/c/go/+/463230
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@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 24a71367c5bd723499d68ee0c5225b8473ce16f9..55ee916fdbffdf0b91fb680d44c23873c96d63f5 100644 (file)
@@ -775,3 +775,18 @@ func (w *cycleFinder) varList(list []*Var) {
                w.typ(v.typ)
        }
 }
+
+// If tpar is a type parameter in list, tparamIndex returns the type parameter index.
+// Otherwise, the result is < 0. tpar must not be nil.
+func tparamIndex(list []*TypeParam, tpar *TypeParam) int {
+       // Once a type parameter is bound its index is >= 0. However, there are some
+       // code paths (namely tracing and type hashing) by which it is possible to
+       // arrive here with a type parameter that has not been bound, hence the check
+       // for 0 <= i below.
+       // TODO(rfindley): investigate a better approach for guarding against using
+       // unbound type parameters.
+       if i := tpar.index; 0 <= i && i < len(list) && list[i] == tpar {
+               return i
+       }
+       return -1
+}
index bca7231bbb81020f2d15ffdb5d5ac117301e543c..836db5b76bbad70c3a5b81c5e39c416c207fa676 100644 (file)
@@ -156,21 +156,6 @@ func (u *unifier) index(typ Type) int {
        return -1
 }
 
-// If tpar is a type parameter in list, tparamIndex returns the type parameter index.
-// Otherwise, the result is < 0. tpar must not be nil.
-func tparamIndex(list []*TypeParam, tpar *TypeParam) int {
-       // Once a type parameter is bound its index is >= 0. However, there are some
-       // code paths (namely tracing and type hashing) by which it is possible to
-       // arrive here with a type parameter that has not been bound, hence the check
-       // for 0 <= i below.
-       // TODO(rfindley): investigate a better approach for guarding against using
-       // unbound type parameters.
-       if i := tpar.index; 0 <= i && i < len(list) && list[i] == tpar {
-               return i
-       }
-       return -1
-}
-
 // setIndex sets the type slot index for the i'th type parameter
 // (and all its joined parameters) to tj. The type parameter
 // must have a (possibly nil) type slot associated with it.
index 7b921c3b9436a16e3a633b206c03e5fe9720ca46..2e6fc7f16f84cfbfb4c2d2889c75e95be5b36b0f 100644 (file)
@@ -777,3 +777,18 @@ func (w *cycleFinder) varList(list []*Var) {
                w.typ(v.typ)
        }
 }
+
+// If tpar is a type parameter in list, tparamIndex returns the type parameter index.
+// Otherwise, the result is < 0. tpar must not be nil.
+func tparamIndex(list []*TypeParam, tpar *TypeParam) int {
+       // Once a type parameter is bound its index is >= 0. However, there are some
+       // code paths (namely tracing and type hashing) by which it is possible to
+       // arrive here with a type parameter that has not been bound, hence the check
+       // for 0 <= i below.
+       // TODO(rfindley): investigate a better approach for guarding against using
+       // unbound type parameters.
+       if i := tpar.index; 0 <= i && i < len(list) && list[i] == tpar {
+               return i
+       }
+       return -1
+}
index a83757f2a4bbcb1c945f1ced182b097c9f7b8a5c..d281420268b27a25d826aa8a9f2327b590301e30 100644 (file)
@@ -158,21 +158,6 @@ func (u *unifier) index(typ Type) int {
        return -1
 }
 
-// If tpar is a type parameter in list, tparamIndex returns the type parameter index.
-// Otherwise, the result is < 0. tpar must not be nil.
-func tparamIndex(list []*TypeParam, tpar *TypeParam) int {
-       // Once a type parameter is bound its index is >= 0. However, there are some
-       // code paths (namely tracing and type hashing) by which it is possible to
-       // arrive here with a type parameter that has not been bound, hence the check
-       // for 0 <= i below.
-       // TODO(rfindley): investigate a better approach for guarding against using
-       // unbound type parameters.
-       if i := tpar.index; 0 <= i && i < len(list) && list[i] == tpar {
-               return i
-       }
-       return -1
-}
-
 // setIndex sets the type slot index for the i'th type parameter
 // (and all its joined parameters) to tj. The type parameter
 // must have a (possibly nil) type slot associated with it.