]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: rename structure to structuralType
authorRobert Griesemer <gri@golang.org>
Wed, 10 Nov 2021 16:12:21 +0000 (08:12 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 10 Nov 2021 17:15:54 +0000 (17:15 +0000)
And rename structureString to structuralString.

Now that we have an updated definition for structural types in
the (forthcoming) spec, name the corresponding function accordingly.

No semantic changes.

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

src/cmd/compile/internal/types2/builtins.go
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/index.go
src/cmd/compile/internal/types2/infer.go
src/cmd/compile/internal/types2/predicates.go
src/cmd/compile/internal/types2/stmt.go

index 916aed40b32f094fb20ba4c382919cfcc7a9eefa..4c659d65cd6d21fafa83b19499b9e0de5914d207 100644 (file)
@@ -82,7 +82,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                // 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.errorf(x, invalidArg+"%s is not a slice", x)
@@ -327,14 +327,14 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
        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.errorf(x, invalidArg+"copy expects slice arguments; found %s and %s", x, &y)
@@ -464,7 +464,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                var min int // minimum number of arguments
-               switch structure(T).(type) {
+               switch structuralType(T).(type) {
                case *Slice:
                        min = 2
                case *Map, *Chan:
@@ -774,14 +774,14 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 // or nil otherwise. If typ is not a type parameter, Structure returns
 // the underlying type.
 func Structure(typ Type) Type {
-       return structure(typ)
+       return structuralType(typ)
 }
 
-// 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) {
@@ -796,10 +796,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 3a571285c1d64fbdbb11cf4133eb142170af9e76..0540feaa78f1062cbed74cec46d8cb0d1b8669b3 100644 (file)
@@ -170,7 +170,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.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.errorf(x, invalidOp+"cannot call non-function %s", x)
                x.mode = invalid
index 8125fba7170d0d53701c8b4631de4a8f81a1b49d..169417016f880ebc12cd7f94ea5e549940fd1e1a 100644 (file)
@@ -1258,7 +1258,7 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin
                        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 f09667453616644141f816106b6cc685f5d17057..10e85ef6e1d816d821b72f2003dc636be11d2cf1 100644 (file)
@@ -210,7 +210,7 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.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, invalidOp+"cannot slice %s: type set has no single underlying type", x)
                x.mode = invalid
index 24c461f1c368af3bcb61aacdec9fed35f83d1902..4f85a5894cc0726feffeaa4d93ceb81d56257203 100644 (file)
@@ -378,7 +378,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 8d676ed8f686f2e7985fed4606fac7f9d784d06d..f1fd33c5def0938f4098e720b6bf5f03f6d2410b 100644 (file)
@@ -31,7 +31,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(t Type) bool         { return allBasic(t, IsBoolean) }
@@ -45,7 +45,7 @@ func allNumericOrString(t Type) bool { return allBasic(t, 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 eaf420aca77ebeac4deec66786de82fb3e522b06..39b24398d76b91d4db15f41cfdb1794bacab271b 100644 (file)
@@ -836,7 +836,7 @@ func (check *Checker) rangeStmt(inner stmtContext, s *syntax.ForStmt, rclause *s
        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"