]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: move some functions into different files (cleanup)
authorRobert Findley <rfindley@google.com>
Tue, 16 Nov 2021 03:27:19 +0000 (22:27 -0500)
committerRobert Findley <rfindley@google.com>
Tue, 16 Nov 2021 14:33:48 +0000 (14:33 +0000)
This is a clean port of CL 362995 from types2 to go/types.

Change-Id: Iefc37b28178795ea944e0bc0ff91982251de2944
Reviewed-on: https://go-review.googlesource.com/c/go/+/363989
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/go/types/builtins.go
src/go/types/type.go

index 8d293a9af3328c6b92820d392bd814222f62918f..9b50403d7f85865bc9d14358e38c9b0c462c6b44 100644 (file)
@@ -776,46 +776,6 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
        return true
 }
 
-// If typ is a type parameter, structuralType returns the single underlying
-// type of all types in the corresponding type constraint if it exists, or
-// nil otherwise. If typ is not a type parameter, structuralType returns
-// the underlying type.
-func structuralType(typ Type) Type {
-       var su Type
-       if underIs(typ, func(u Type) bool {
-               if su != nil && !Identical(su, u) {
-                       return false
-               }
-               // su == nil || Identical(su, u)
-               su = u
-               return true
-       }) {
-               return su
-       }
-       return nil
-}
-
-// structuralString is like structuralType but also considers []byte
-// and string as "identical". In this case, if successful, the result
-// is always []byte.
-func structuralString(typ Type) Type {
-       var su Type
-       if underIs(typ, func(u Type) bool {
-               if isString(u) {
-                       u = NewSlice(universeByte)
-               }
-               if su != nil && !Identical(su, u) {
-                       return false
-               }
-               // su == nil || Identical(su, u)
-               su = u
-               return true
-       }) {
-               return su
-       }
-       return nil
-}
-
 // hasVarSize reports if the size of type t is variable due to type parameters.
 func hasVarSize(t Type) bool {
        switch t := under(t).(type) {
index b1e2bda4cd6b3f078ac6ad8c1be7d101c385eba6..26a605444d0428198508ca48ba8aad8b0d90e389 100644 (file)
@@ -27,10 +27,47 @@ func under(t Type) Type {
        return t
 }
 
-// If the argument to asNamed, or asTypeParam is of the respective type
-// (possibly after resolving a *Named type), these methods return that type.
-// Otherwise the result is nil.
+// If typ is a type parameter, structuralType returns the single underlying
+// type of all types in the corresponding type constraint if it exists,
+// or nil otherwise. If typ is not a type parameter, structuralType returns
+// the underlying type.
+func structuralType(typ Type) Type {
+       var su Type
+       if underIs(typ, func(u Type) bool {
+               if su != nil && !Identical(su, u) {
+                       return false
+               }
+               // su == nil || Identical(su, u)
+               su = u
+               return true
+       }) {
+               return su
+       }
+       return nil
+}
+
+// structuralString is like structuralType but also considers []byte
+// and string as "identical". In this case, if successful, the result
+// is always []byte.
+func structuralString(typ Type) Type {
+       var su Type
+       if underIs(typ, func(u Type) bool {
+               if isString(u) {
+                       u = NewSlice(universeByte)
+               }
+               if su != nil && !Identical(su, u) {
+                       return false
+               }
+               // su == nil || Identical(su, u)
+               su = u
+               return true
+       }) {
+               return su
+       }
+       return nil
+}
 
+// If t is a defined type, asNamed returns that type (possibly after resolving it), otherwise it returns nil.
 func asNamed(t Type) *Named {
        e, _ := t.(*Named)
        if e != nil {
@@ -39,6 +76,7 @@ func asNamed(t Type) *Named {
        return e
 }
 
+// If t is a type parameter, asTypeParam returns that type, otherwise it returns nil.
 func asTypeParam(t Type) *TypeParam {
        u, _ := under(t).(*TypeParam)
        return u