]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types: rename structure to structuralType
authorRobert Findley <rfindley@google.com>
Tue, 16 Nov 2021 03:23:24 +0000 (22:23 -0500)
committerRobert Findley <rfindley@google.com>
Tue, 16 Nov 2021 14:33:39 +0000 (14:33 +0000)
This is a clean port of CL 362994 from types2 to go/types.

Change-Id: I51b38c35ec3306274ef0355516e2d5557e7d8b46
Reviewed-on: https://go-review.googlesource.com/c/go/+/363988
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/call.go
src/go/types/expr.go
src/go/types/index.go
src/go/types/infer.go
src/go/types/predicates.go
src/go/types/stmt.go

index c2d36e97114496260b1df211bb51bacf6c44e798..8d293a9af3328c6b92820d392bd814222f62918f 100644 (file)
@@ -83,7 +83,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                // of S and the respective parameter passing rules apply."
                S := x.typ
                var T Type
-               if s, _ := structure(S).(*Slice); s != nil {
+               if s, _ := structuralType(S).(*Slice); s != nil {
                        T = s.elem
                } else {
                        check.invalidArg(x, _InvalidAppend, "%s is not a slice", x)
@@ -332,14 +332,14 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
        case _Copy:
                // copy(x, y []T) int
-               dst, _ := structure(x.typ).(*Slice)
+               dst, _ := structuralType(x.typ).(*Slice)
 
                var y operand
                arg(&y, 1)
                if y.mode == invalid {
                        return
                }
-               src, _ := structureString(y.typ).(*Slice)
+               src, _ := structuralString(y.typ).(*Slice)
 
                if dst == nil || src == nil {
                        check.invalidArg(x, _InvalidCopy, "copy expects slice arguments; found %s and %s", x, &y)
@@ -473,7 +473,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                var min int // minimum number of arguments
-               switch structure(T).(type) {
+               switch structuralType(T).(type) {
                case *Slice:
                        min = 2
                case *Map, *Chan:
@@ -776,11 +776,11 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
        return true
 }
 
-// If typ is a type parameter, structure 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, structure returns
+// 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 structure(typ Type) Type {
+func structuralType(typ Type) Type {
        var su Type
        if underIs(typ, func(u Type) bool {
                if su != nil && !Identical(su, u) {
@@ -795,10 +795,10 @@ func structure(typ Type) Type {
        return nil
 }
 
-// structureString is like structure but also considers []byte and
-// string as "identical". In this case, if successful, the result
+// structuralString is like structuralType but also considers []byte
+// and string as "identical". In this case, if successful, the result
 // is always []byte.
-func structureString(typ Type) Type {
+func structuralString(typ Type) Type {
        var su Type
        if underIs(typ, func(u Type) bool {
                if isString(u) {
index 927c9f2a44cf02a1d2b6e8cf9385f1e9d8a969c5..dfd7142094e023d8025a16a8efe52caaf2ca6d0a 100644 (file)
@@ -175,7 +175,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
        cgocall := x.mode == cgofunc
 
        // a type parameter may be "called" if all types have the same signature
-       sig, _ := structure(x.typ).(*Signature)
+       sig, _ := structuralType(x.typ).(*Signature)
        if sig == nil {
                check.invalidOp(x, _InvalidCall, "cannot call non-function %s", x)
                x.mode = invalid
index 9d9eddfb95a7e79823b7a67701c1c9d1795b26b1..0edaf63db015d1612fc0318a9177e42b8cebf3f0 100644 (file)
@@ -1228,7 +1228,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
                        goto Error
                }
 
-               switch utyp := structure(base).(type) {
+               switch utyp := structuralType(base).(type) {
                case *Struct:
                        // Prevent crash if the struct referred to is not yet set up.
                        // See analogous comment for *Array.
index cd19f50627f44c9c77df217149159a2c946946ea..534b445e9e107792b60277fc62d786085e9efdb7 100644 (file)
@@ -211,7 +211,7 @@ func (check *Checker) sliceExpr(x *operand, e *ast.SliceExpr) {
 
        valid := false
        length := int64(-1) // valid if >= 0
-       switch u := structure(x.typ).(type) {
+       switch u := structuralType(x.typ).(type) {
        case nil:
                check.errorf(x, _NonSliceableOperand, "cannot slice %s: type set has no single underlying type", x)
                x.mode = invalid
index f4f9bfac8fa13936a534da8f4164282cd61f3e2c..909042219c2912d5a0d97e5f96c677b0f35a3a45 100644 (file)
@@ -377,7 +377,7 @@ func (check *Checker) inferB(tparams []*TypeParam, targs []Type) (types []Type,
 
        // If a constraint has a structural type, unify the corresponding type parameter with it.
        for _, tpar := range tparams {
-               sbound := structure(tpar)
+               sbound := structuralType(tpar)
                if sbound != nil {
                        // If the structural type is the underlying type of a single
                        // defined type in the constraint, use that defined type instead.
index e7f9d3b1db150c9cd8a8e03c14f669437a233c50..2d9b9c4c079cba66326a9411b786e5e318e75f2f 100644 (file)
@@ -33,7 +33,7 @@ func isBasic(t Type, info BasicInfo) bool {
 // The allX predicates below report whether t is an X.
 // If t is a type parameter the result is true if isX is true
 // for all specified types of the type parameter's type set.
-// allX is an optimized version of isX(structure(t)) (which
+// allX is an optimized version of isX(structuralType(t)) (which
 // is the same as underIs(t, isX)).
 
 func allBoolean(typ Type) bool         { return allBasic(typ, IsBoolean) }
@@ -47,7 +47,7 @@ func allNumericOrString(typ Type) bool { return allBasic(typ, IsNumeric|IsString
 // allBasic reports whether under(t) is a basic type with the specified info.
 // If t is a type parameter, the result is true if isBasic(t, info) is true
 // for all specific types of the type parameter's type set.
-// allBasic(t, info) is an optimized version of isBasic(structure(t), info).
+// allBasic(t, info) is an optimized version of isBasic(structuralType(t), info).
 func allBasic(t Type, info BasicInfo) bool {
        switch u := under(t).(type) {
        case *Basic:
index 2a3fb5f6f516a0dd09aa604cb9dddb9601b81c8f..3d4a20f80831c0f701f20e1cbb48800fe370e13a 100644 (file)
@@ -834,7 +834,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
                if x.mode != invalid {
                        // Ranging over a type parameter is permitted if it has a single underlying type.
                        var cause string
-                       u := structure(x.typ)
+                       u := structuralType(x.typ)
                        switch t := u.(type) {
                        case nil:
                                cause = "type set has no single underlying type"