Skip to content

Commit 0c14000

Browse files
Mark Freemangopherbot
authored andcommitted
go/types, types2: remove under(Type) in favor of Type.Underlying()
As of CL 695977, under(Type) simply delegates to Type.Underlying(). This is just a cleanup. Change-Id: I48d5fddc38560dfe485184faa6a5ff713bea74a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/712400 Commit-Queue: Robert Griesemer <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 1099436 commit 0c14000

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+171
-189
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
9191
// x.typ is typed
9292

9393
// A generic (non-instantiated) function value cannot be assigned to a variable.
94-
if sig, _ := under(x.typ).(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
94+
if sig, _ := x.typ.Underlying().(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
9595
check.errorf(x, WrongTypeArgCount, "cannot use generic function %s without instantiation in %s", x, context)
9696
x.mode = invalid
9797
return
@@ -261,7 +261,7 @@ func (check *Checker) assignVar(lhs, rhs syntax.Expr, x *operand, context string
261261
var target *target
262262
// avoid calling ExprString if not needed
263263
if T != nil {
264-
if _, ok := under(T).(*Signature); ok {
264+
if _, ok := T.Underlying().(*Signature); ok {
265265
target = newTarget(T, ExprString(lhs))
266266
}
267267
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
144144
// len(x)
145145
mode := invalid
146146
var val constant.Value
147-
switch t := arrayPtrDeref(under(x.typ)).(type) {
147+
switch t := arrayPtrDeref(x.typ.Underlying()).(type) {
148148
case *Basic:
149149
if isString(t) && id == _Len {
150150
if x.mode == constant_ {
@@ -203,7 +203,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
203203

204204
if mode == invalid {
205205
// avoid error if underlying type is invalid
206-
if isValid(under(x.typ)) {
206+
if isValid(x.typ.Underlying()) {
207207
code := InvalidCap
208208
if id == _Len {
209209
code = InvalidLen
@@ -322,7 +322,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
322322
// (applyTypeFunc never calls f with a type parameter)
323323
f := func(typ Type) Type {
324324
assert(!isTypeParam(typ))
325-
if t, _ := under(typ).(*Basic); t != nil {
325+
if t, _ := typ.Underlying().(*Basic); t != nil {
326326
switch t.kind {
327327
case Float32:
328328
return Typ[Complex64]
@@ -472,7 +472,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
472472
// (applyTypeFunc never calls f with a type parameter)
473473
f := func(typ Type) Type {
474474
assert(!isTypeParam(typ))
475-
if t, _ := under(typ).(*Basic); t != nil {
475+
if t, _ := typ.Underlying().(*Basic); t != nil {
476476
switch t.kind {
477477
case Complex64:
478478
return Typ[Float32]
@@ -1020,7 +1020,7 @@ func hasVarSize(t Type, seen map[*Named]bool) (varSized bool) {
10201020
}()
10211021
}
10221022

1023-
switch u := under(t).(type) {
1023+
switch u := t.Underlying().(type) {
10241024
case *Array:
10251025
return hasVarSize(u.elem, seen)
10261026
case *Struct:
@@ -1112,7 +1112,7 @@ func makeSig(res Type, args ...Type) *Signature {
11121112
// otherwise it returns typ.
11131113
func arrayPtrDeref(typ Type) Type {
11141114
if p, ok := Unalias(typ).(*Pointer); ok {
1115-
if a, _ := under(p.base).(*Array); a != nil {
1115+
if a, _ := p.base.Underlying().(*Array); a != nil {
11161116
return a
11171117
}
11181118
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
205205
case 1:
206206
check.expr(nil, x, call.ArgList[0])
207207
if x.mode != invalid {
208-
if t, _ := under(T).(*Interface); t != nil && !isTypeParam(T) {
208+
if t, _ := T.Underlying().(*Interface); t != nil && !isTypeParam(T) {
209209
if !t.IsMethodSet() {
210210
check.errorf(call, MisplacedConstraintIface, "cannot use interface %s in conversion (contains specific type constraints or is comparable)", T)
211211
break
@@ -812,7 +812,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, def *TypeName
812812
obj, index, indirect = lookupFieldOrMethod(x.typ, x.mode == variable, check.pkg, sel, false)
813813
if obj == nil {
814814
// Don't report another error if the underlying type was invalid (go.dev/issue/49541).
815-
if !isValid(under(x.typ)) {
815+
if !isValid(x.typ.Underlying()) {
816816
goto Error
817817
}
818818

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (check *Checker) overflow(x *operand, opPos syntax.Pos) {
3333
// x.typ cannot be a type parameter (type
3434
// parameters cannot be constant types).
3535
if isTyped(x.typ) {
36-
check.representable(x, under(x.typ).(*Basic))
36+
check.representable(x, x.typ.Underlying().(*Basic))
3737
return
3838
}
3939

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (check *Checker) conversion(x *operand, T Type) {
1818
constArg := x.mode == constant_
1919

2020
constConvertibleTo := func(T Type, val *constant.Value) bool {
21-
switch t, _ := under(T).(*Basic); {
21+
switch t, _ := T.Underlying().(*Basic); {
2222
case t == nil:
2323
// nothing to do
2424
case representableConst(x.val, check, t, val):
@@ -142,8 +142,8 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
142142
origT := T
143143
V := Unalias(x.typ)
144144
T = Unalias(T)
145-
Vu := under(V)
146-
Tu := under(T)
145+
Vu := V.Underlying()
146+
Tu := T.Underlying()
147147
Vp, _ := V.(*TypeParam)
148148
Tp, _ := T.(*TypeParam)
149149

@@ -158,7 +158,7 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
158158
// and their pointer base types are not type parameters"
159159
if V, ok := V.(*Pointer); ok {
160160
if T, ok := T.(*Pointer); ok {
161-
if IdenticalIgnoreTags(under(V.base), under(T.base)) && !isTypeParam(V.base) && !isTypeParam(T.base) {
161+
if IdenticalIgnoreTags(V.base.Underlying(), T.base.Underlying()) && !isTypeParam(V.base) && !isTypeParam(T.base) {
162162
return true
163163
}
164164
}
@@ -211,7 +211,7 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
211211
return false
212212
}
213213
case *Pointer:
214-
if a, _ := under(a.Elem()).(*Array); a != nil {
214+
if a, _ := a.Elem().Underlying().(*Array); a != nil {
215215
if Identical(s.Elem(), a.Elem()) {
216216
if check == nil || check.allowVersion(go1_17) {
217217
return true
@@ -292,23 +292,23 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
292292
}
293293

294294
func isUintptr(typ Type) bool {
295-
t, _ := under(typ).(*Basic)
295+
t, _ := typ.Underlying().(*Basic)
296296
return t != nil && t.kind == Uintptr
297297
}
298298

299299
func isUnsafePointer(typ Type) bool {
300-
t, _ := under(typ).(*Basic)
300+
t, _ := typ.Underlying().(*Basic)
301301
return t != nil && t.kind == UnsafePointer
302302
}
303303

304304
func isPointer(typ Type) bool {
305-
_, ok := under(typ).(*Pointer)
305+
_, ok := typ.Underlying().(*Pointer)
306306
return ok
307307
}
308308

309309
func isBytesOrRunes(typ Type) bool {
310-
if s, _ := under(typ).(*Slice); s != nil {
311-
t, _ := under(s.elem).(*Basic)
310+
if s, _ := typ.Underlying().(*Slice); s != nil {
311+
t, _ := s.elem.Underlying().(*Basic)
312312
return t != nil && (t.kind == Byte || t.kind == Rune)
313313
}
314314
return false

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func (check *Checker) constDecl(obj *Const, typ, init syntax.Expr, inherited boo
391391
if !isConstType(t) {
392392
// don't report an error if the type is an invalid C (defined) type
393393
// (go.dev/issue/22090)
394-
if isValid(under(t)) {
394+
if isValid(t.Underlying()) {
395395
check.errorf(typ, InvalidConstType, "invalid constant type %s", t)
396396
}
397397
obj.typ = Typ[Invalid]

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func (check *Checker) updateExprType(x syntax.Expr, typ Type, final bool) {
361361
// If the new type is not final and still untyped, just
362362
// update the recorded type.
363363
if !final && isUntyped(typ) {
364-
old.typ = under(typ).(*Basic)
364+
old.typ = typ.Underlying().(*Basic)
365365
check.untyped[x] = old
366366
return
367367
}
@@ -431,7 +431,7 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const
431431
return nil, nil, InvalidUntypedConversion
432432
}
433433

434-
switch u := under(target).(type) {
434+
switch u := target.Underlying().(type) {
435435
case *Basic:
436436
if x.mode == constant_ {
437437
v, code := check.representation(x, u)
@@ -616,7 +616,7 @@ Error:
616616
// incomparableCause returns a more specific cause why typ is not comparable.
617617
// If there is no more specific cause, the result is "".
618618
func (check *Checker) incomparableCause(typ Type) string {
619-
switch under(typ).(type) {
619+
switch typ.Underlying().(type) {
620620
case *Slice, *Signature, *Map:
621621
return compositeKind(typ) + " can only be compared to nil"
622622
}
@@ -963,7 +963,7 @@ type target struct {
963963
// The result is nil if typ is not a signature.
964964
func newTarget(typ Type, desc string) *target {
965965
if typ != nil {
966-
if sig, _ := under(typ).(*Signature); sig != nil {
966+
if sig, _ := typ.Underlying().(*Signature); sig != nil {
967967
return &target{sig, desc}
968968
}
969969
}
@@ -1112,7 +1112,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
11121112
check.errorf(x, InvalidAssert, invalidOp+"cannot use type assertion on type parameter value %s", x)
11131113
goto Error
11141114
}
1115-
if _, ok := under(x.typ).(*Interface); !ok {
1115+
if _, ok := x.typ.Underlying().(*Interface); !ok {
11161116
check.errorf(x, InvalidAssert, invalidOp+"%s is not an interface", x)
11171117
goto Error
11181118
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (s *gcSizes) Alignof(T Type) (result int64) {
1616

1717
// For arrays and structs, alignment is defined in terms
1818
// of alignment of the elements and fields, respectively.
19-
switch t := under(T).(type) {
19+
switch t := T.Underlying().(type) {
2020
case *Array:
2121
// spec: "For a variable x of array type: unsafe.Alignof(x)
2222
// is the same as unsafe.Alignof(x[0]), but at least 1."
@@ -96,7 +96,7 @@ func (s *gcSizes) Offsetsof(fields []*Var) []int64 {
9696
}
9797

9898
func (s *gcSizes) Sizeof(T Type) int64 {
99-
switch t := under(T).(type) {
99+
switch t := T.Underlying().(type) {
100100
case *Basic:
101101
assert(isTyped(T))
102102
k := t.kind

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
3535
return false
3636

3737
case value:
38-
if sig, _ := under(x.typ).(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
38+
if sig, _ := x.typ.Underlying().(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
3939
// function instantiation
4040
return true
4141
}
@@ -50,7 +50,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
5050
// ordinary index expression
5151
valid := false
5252
length := int64(-1) // valid if >= 0
53-
switch typ := under(x.typ).(type) {
53+
switch typ := x.typ.Underlying().(type) {
5454
case *Basic:
5555
if isString(typ) {
5656
valid = true
@@ -73,7 +73,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
7373
x.typ = typ.elem
7474

7575
case *Pointer:
76-
if typ, _ := under(typ.base).(*Array); typ != nil {
76+
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
7777
valid = true
7878
length = typ.len
7979
x.mode = variable
@@ -124,7 +124,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
124124
mode = value
125125
}
126126
case *Pointer:
127-
if t, _ := under(t.base).(*Array); t != nil {
127+
if t, _ := t.base.Underlying().(*Array); t != nil {
128128
l = t.len
129129
e = t.elem
130130
}
@@ -247,7 +247,7 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) {
247247
// but don't go from untyped string to string.
248248
cu = Typ[String]
249249
if !isTypeParam(x.typ) {
250-
cu = under(x.typ) // untyped string remains untyped
250+
cu = x.typ.Underlying() // untyped string remains untyped
251251
}
252252
}
253253

@@ -292,7 +292,7 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) {
292292
x.typ = &Slice{elem: u.elem}
293293

294294
case *Pointer:
295-
if u, _ := under(u.base).(*Array); u != nil {
295+
if u, _ := u.base.Underlying().(*Array); u != nil {
296296
valid = true
297297
length = u.len
298298
x.typ = &Slice{elem: u.elem}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ func coreTerm(tpar *TypeParam) (*term, bool) {
668668
if n == 1 {
669669
if debug {
670670
u, _ := commonUnder(tpar, nil)
671-
assert(under(single.typ) == u)
671+
assert(single.typ.Underlying() == u)
672672
}
673673
return single, true
674674
}

0 commit comments

Comments
 (0)