cmd/compile/internal/types2: rename structure to structuralType

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>
This commit is contained in:
Robert Griesemer 2021-11-10 08:12:21 -08:00
parent 0aa194f758
commit 8a3be15077
7 changed files with 19 additions and 19 deletions

View 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) {

View 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

View 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.

View 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

View 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.

View 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:

View 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"