From 67c15568156eb0c5607edc51a2b5d69876ba236d Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Mon, 15 Nov 2021 22:23:24 -0500 Subject: [PATCH] go/types: rename structure to structuralType 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 Reviewed-by: Robert Griesemer Run-TryBot: Robert Findley TryBot-Result: Go Bot --- src/go/types/builtins.go | 22 +++++++++++----------- src/go/types/call.go | 2 +- src/go/types/expr.go | 2 +- src/go/types/index.go | 2 +- src/go/types/infer.go | 2 +- src/go/types/predicates.go | 4 ++-- src/go/types/stmt.go | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/go/types/builtins.go b/src/go/types/builtins.go index c2d36e9711..8d293a9af3 100644 --- a/src/go/types/builtins.go +++ b/src/go/types/builtins.go @@ -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) { diff --git a/src/go/types/call.go b/src/go/types/call.go index 927c9f2a44..dfd7142094 100644 --- a/src/go/types/call.go +++ b/src/go/types/call.go @@ -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 diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 9d9eddfb95..0edaf63db0 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -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. diff --git a/src/go/types/index.go b/src/go/types/index.go index cd19f50627..534b445e9e 100644 --- a/src/go/types/index.go +++ b/src/go/types/index.go @@ -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 diff --git a/src/go/types/infer.go b/src/go/types/infer.go index f4f9bfac8f..909042219c 100644 --- a/src/go/types/infer.go +++ b/src/go/types/infer.go @@ -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. diff --git a/src/go/types/predicates.go b/src/go/types/predicates.go index e7f9d3b1db..2d9b9c4c07 100644 --- a/src/go/types/predicates.go +++ b/src/go/types/predicates.go @@ -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: diff --git a/src/go/types/stmt.go b/src/go/types/stmt.go index 2a3fb5f6f5..3d4a20f808 100644 --- a/src/go/types/stmt.go +++ b/src/go/types/stmt.go @@ -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" -- 2.50.0