Skip to content

Commit 2bf5ae0

Browse files
committed
go/types, types2: rename structuralType/String to coreType/String
This is a pure rename of the respective Go functions/methods with corresponding adjustments to error messages and tests. A couple of comments were manually rephrased. With this change, the implementation and error messages match the latest spec. No functionality change. Change-Id: Iaa92a08b64756356fb2c5abdaca5c943c9105c96 Reviewed-on: https://go-review.googlesource.com/c/go/+/384618 Trust: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent ea3c546 commit 2bf5ae0

39 files changed

+136
-134
lines changed

src/cmd/compile/internal/noder/expr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,13 @@ func (g *irgen) exprs(exprs []syntax.Expr) []ir.Node {
332332
}
333333

334334
func (g *irgen) compLit(typ types2.Type, lit *syntax.CompositeLit) ir.Node {
335-
if ptr, ok := types2.StructuralType(typ).(*types2.Pointer); ok {
335+
if ptr, ok := types2.CoreType(typ).(*types2.Pointer); ok {
336336
n := ir.NewAddrExpr(g.pos(lit), g.compLit(ptr.Elem(), lit))
337337
n.SetOp(ir.OPTRLIT)
338338
return typed(g.typ(typ), n)
339339
}
340340

341-
_, isStruct := types2.StructuralType(typ).(*types2.Struct)
341+
_, isStruct := types2.CoreType(typ).(*types2.Struct)
342342

343343
exprs := make([]ir.Node, len(lit.ElemList))
344344
for i, elem := range lit.ElemList {

src/cmd/compile/internal/noder/writer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,10 +1338,10 @@ func (w *writer) compLit(lit *syntax.CompositeLit) {
13381338
w.typ(tv.Type)
13391339

13401340
typ := tv.Type
1341-
if ptr, ok := types2.StructuralType(typ).(*types2.Pointer); ok {
1341+
if ptr, ok := types2.CoreType(typ).(*types2.Pointer); ok {
13421342
typ = ptr.Elem()
13431343
}
1344-
str, isStruct := types2.StructuralType(typ).(*types2.Struct)
1344+
str, isStruct := types2.CoreType(typ).(*types2.Struct)
13451345

13461346
w.len(len(lit.ElemList))
13471347
for i, elem := range lit.ElemList {

src/cmd/compile/internal/types2/builtins.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
8282
// of S and the respective parameter passing rules apply."
8383
S := x.typ
8484
var T Type
85-
if s, _ := structuralType(S).(*Slice); s != nil {
85+
if s, _ := coreType(S).(*Slice); s != nil {
8686
T = s.elem
8787
} else {
8888
var cause string
8989
switch {
9090
case x.isNil():
9191
cause = "have untyped nil"
9292
case isTypeParam(S):
93-
if u := structuralType(S); u != nil {
94-
cause = check.sprintf("%s has structural type %s", x, u)
93+
if u := coreType(S); u != nil {
94+
cause = check.sprintf("%s has core type %s", x, u)
9595
} else {
96-
cause = check.sprintf("%s has no structural type", x)
96+
cause = check.sprintf("%s has no core type", x)
9797
}
9898
default:
9999
cause = check.sprintf("have %s", x)
@@ -115,7 +115,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
115115
if x.mode == invalid {
116116
return
117117
}
118-
if t := structuralString(x.typ); t != nil && isString(t) {
118+
if t := coreString(x.typ); t != nil && isString(t) {
119119
if check.Types != nil {
120120
sig := makeSig(S, S, x.typ)
121121
sig.variadic = true
@@ -345,14 +345,14 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
345345

346346
case _Copy:
347347
// copy(x, y []T) int
348-
dst, _ := structuralType(x.typ).(*Slice)
348+
dst, _ := coreType(x.typ).(*Slice)
349349

350350
var y operand
351351
arg(&y, 1)
352352
if y.mode == invalid {
353353
return
354354
}
355-
src0 := structuralString(y.typ)
355+
src0 := coreString(y.typ)
356356
if src0 != nil && isString(src0) {
357357
src0 = NewSlice(universeByte)
358358
}
@@ -486,13 +486,13 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
486486
}
487487

488488
var min int // minimum number of arguments
489-
switch structuralType(T).(type) {
489+
switch coreType(T).(type) {
490490
case *Slice:
491491
min = 2
492492
case *Map, *Chan:
493493
min = 1
494494
case nil:
495-
check.errorf(arg0, invalidArg+"cannot make %s: no structural type", arg0)
495+
check.errorf(arg0, invalidArg+"cannot make %s: no core type", arg0)
496496
return
497497
default:
498498
check.errorf(arg0, invalidArg+"cannot make %s; type must be slice, map, or channel", arg0)

src/cmd/compile/internal/types2/call.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
168168
cgocall := x.mode == cgofunc
169169

170170
// a type parameter may be "called" if all types have the same signature
171-
sig, _ := structuralType(x.typ).(*Signature)
171+
sig, _ := coreType(x.typ).(*Signature)
172172
if sig == nil {
173173
check.errorf(x, invalidOp+"cannot call non-function %s", x)
174174
x.mode = invalid

src/cmd/compile/internal/types2/compilersupport.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ func AsSignature(t Type) *Signature {
1919
return u
2020
}
2121

22-
// If typ is a type parameter, structuralType returns the single underlying
22+
// If typ is a type parameter, CoreType returns the single underlying
2323
// type of all types in the corresponding type constraint if it exists, or
2424
// nil otherwise. If the type set contains only unrestricted and restricted
2525
// channel types (with identical element types), the single underlying type
2626
// is the restricted channel type if the restrictions are always the same.
27-
// If typ is not a type parameter, structuralType returns the underlying type.
28-
func StructuralType(t Type) Type {
29-
return structuralType(t)
27+
// If typ is not a type parameter, CoreType returns the underlying type.
28+
func CoreType(t Type) Type {
29+
return coreType(t)
3030
}

src/cmd/compile/internal/types2/expr.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ func (check *Checker) unary(x *operand, e *syntax.Operation) {
182182
return
183183

184184
case syntax.Recv:
185-
u := structuralType(x.typ)
185+
u := coreType(x.typ)
186186
if u == nil {
187-
check.errorf(x, invalidOp+"cannot receive from %s: no structural type", x)
187+
check.errorf(x, invalidOp+"cannot receive from %s: no core type", x)
188188
x.mode = invalid
189189
return
190190
}
@@ -1359,15 +1359,15 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin
13591359
case hint != nil:
13601360
// no composite literal type present - use hint (element type of enclosing type)
13611361
typ = hint
1362-
base, _ = deref(structuralType(typ)) // *T implies &T{}
1362+
base, _ = deref(coreType(typ)) // *T implies &T{}
13631363

13641364
default:
13651365
// TODO(gri) provide better error messages depending on context
13661366
check.error(e, "missing type in composite literal")
13671367
goto Error
13681368
}
13691369

1370-
switch utyp := structuralType(base).(type) {
1370+
switch utyp := coreType(base).(type) {
13711371
case *Struct:
13721372
// Prevent crash if the struct referred to is not yet set up.
13731373
// See analogous comment for *Array.

src/cmd/compile/internal/types2/index.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) {
213213

214214
valid := false
215215
length := int64(-1) // valid if >= 0
216-
switch u := structuralString(x.typ).(type) {
216+
switch u := coreString(x.typ).(type) {
217217
case nil:
218-
check.errorf(x, invalidOp+"cannot slice %s: %s has no structural type", x, x.typ)
218+
check.errorf(x, invalidOp+"cannot slice %s: %s has no core type", x, x.typ)
219219
x.mode = invalid
220220
return
221221

src/cmd/compile/internal/types2/infer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,11 @@ func (check *Checker) inferB(pos syntax.Pos, tparams []*TypeParam, targs []Type)
416416
}
417417
}
418418

419-
// If a constraint has a structural type, unify the corresponding type parameter with it.
419+
// If a constraint has a core type, unify the corresponding type parameter with it.
420420
for _, tpar := range tparams {
421-
sbound := structuralType(tpar)
421+
sbound := coreType(tpar)
422422
if sbound != nil {
423-
// If the structural type is the underlying type of a single
423+
// If the core type is the underlying type of a single
424424
// defined type in the constraint, use that defined type instead.
425425
if named, _ := tpar.singleType().(*Named); named != nil {
426426
sbound = named
@@ -435,7 +435,7 @@ func (check *Checker) inferB(pos syntax.Pos, tparams []*TypeParam, targs []Type)
435435
}
436436

437437
// u.x.types() now contains the incoming type arguments plus any additional type
438-
// arguments which were inferred from structural types. The newly inferred non-
438+
// arguments which were inferred from core types. The newly inferred non-
439439
// nil entries may still contain references to other type parameters.
440440
// For instance, for [A any, B interface{ []C }, C interface{ *A }], if A == int
441441
// was given, unification produced the type list [int, []C, *A]. We eliminate the
@@ -504,8 +504,8 @@ func (check *Checker) inferB(pos syntax.Pos, tparams []*TypeParam, targs []Type)
504504
}
505505

506506
// Once nothing changes anymore, we may still have type parameters left;
507-
// e.g., a structural constraint *P may match a type parameter Q but we
508-
// don't have any type arguments to fill in for *P or Q (issue #45548).
507+
// e.g., a constraint with core type *P may match a type parameter Q but
508+
// we don't have any type arguments to fill in for *P or Q (issue #45548).
509509
// Don't let such inferences escape, instead nil them out.
510510
for i, typ := range types {
511511
if typ != nil && isParameterized(tparams, typ) {

src/cmd/compile/internal/types2/lookup.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ func LookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (o
6666

6767
obj, index, indirect = lookupFieldOrMethod(T, addressable, pkg, name, false)
6868

69-
// If we didn't find anything and if we have a type parameter with a structural constraint,
70-
// see if there is a matching field (but not a method, those need to be declared explicitly
71-
// in the constraint). If the structural constraint is a named pointer type (see above), we
72-
// are ok here because only fields are accepted as results.
69+
// If we didn't find anything and if we have a type parameter with a core type,
70+
// see if there is a matching field (but not a method, those need to be declared
71+
// explicitly in the constraint). If the constraint is a named pointer type (see
72+
// above), we are ok here because only fields are accepted as results.
7373
if obj == nil && isTypeParam(T) {
74-
if t := structuralType(T); t != nil {
74+
if t := coreType(T); t != nil {
7575
obj, index, indirect = lookupFieldOrMethod(t, addressable, pkg, name, false)
7676
if _, ok := obj.(*Var); !ok {
7777
obj, index, indirect = nil, nil, false // accept fields (variables) only

src/cmd/compile/internal/types2/predicates.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func isBasic(t Type, info BasicInfo) bool {
3131
// The allX predicates below report whether t is an X.
3232
// If t is a type parameter the result is true if isX is true
3333
// for all specified types of the type parameter's type set.
34-
// allX is an optimized version of isX(structuralType(t)) (which
34+
// allX is an optimized version of isX(coreType(t)) (which
3535
// is the same as underIs(t, isX)).
3636

3737
func allBoolean(t Type) bool { return allBasic(t, IsBoolean) }
@@ -45,7 +45,7 @@ func allNumericOrString(t Type) bool { return allBasic(t, IsNumeric|IsString) }
4545
// allBasic reports whether under(t) is a basic type with the specified info.
4646
// If t is a type parameter, the result is true if isBasic(t, info) is true
4747
// for all specific types of the type parameter's type set.
48-
// allBasic(t, info) is an optimized version of isBasic(structuralType(t), info).
48+
// allBasic(t, info) is an optimized version of isBasic(coreType(t), info).
4949
func allBasic(t Type, info BasicInfo) bool {
5050
if tpar, _ := t.(*TypeParam); tpar != nil {
5151
return tpar.is(func(t *term) bool { return t != nil && isBasic(t.typ, info) })

0 commit comments

Comments
 (0)