Skip to content

Commit 17910ed

Browse files
committed
refect: rename Ptr Kind to Pointer (but keep Ptr)
reflect.Ptr didn't match reflect.UnsafePointer or unsafe.Pointer so rename it to reflect.Pointer. Keep reflect.Ptr for compatibility. Likewise with PtrTo. Change to use it in std will come in a subsequent CL. Fixes #47651 Change-Id: I5d4abe2b2fe10948bd68bb12c557165bedffbcba Reviewed-on: https://go-review.googlesource.com/c/go/+/341333 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Brad Fitzpatrick <[email protected]> Reviewed-by: Joe Tsai <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 9f69a44 commit 17910ed

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

src/internal/reflectlite/type.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,15 @@ const (
100100
Func
101101
Interface
102102
Map
103-
Ptr
103+
Pointer
104104
Slice
105105
String
106106
Struct
107107
UnsafePointer
108108
)
109109

110+
const Ptr = Pointer
111+
110112
// tflag is used by an rtype to signal what extra type information is
111113
// available in the memory directly following the rtype value.
112114
//

src/internal/reflectlite/value.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (f flag) ro() flag {
8787
}
8888

8989
// pointer returns the underlying pointer represented by v.
90-
// v.Kind() must be Ptr, Map, Chan, Func, or UnsafePointer
90+
// v.Kind() must be Pointer, Map, Chan, Func, or UnsafePointer
9191
func (v Value) pointer() unsafe.Pointer {
9292
if v.typ.size != goarch.PtrSize || !v.typ.pointers() {
9393
panic("can't call pointer on a non-pointer Value")
@@ -220,7 +220,7 @@ func (v Value) CanSet() bool {
220220

221221
// Elem returns the value that the interface v contains
222222
// or that the pointer v points to.
223-
// It panics if v's Kind is not Interface or Ptr.
223+
// It panics if v's Kind is not Interface or Pointer.
224224
// It returns the zero Value if v is nil.
225225
func (v Value) Elem() Value {
226226
k := v.kind()
@@ -239,7 +239,7 @@ func (v Value) Elem() Value {
239239
x.flag |= v.flag.ro()
240240
}
241241
return x
242-
case Ptr:
242+
case Pointer:
243243
ptr := v.ptr
244244
if v.flag&flagIndir != 0 {
245245
ptr = *(*unsafe.Pointer)(ptr)
@@ -288,7 +288,7 @@ func valueInterface(v Value) interface{} {
288288
func (v Value) IsNil() bool {
289289
k := v.kind()
290290
switch k {
291-
case Chan, Func, Map, Ptr, UnsafePointer:
291+
case Chan, Func, Map, Pointer, UnsafePointer:
292292
// if v.flag&flagMethod != 0 {
293293
// return false
294294
// }

src/reflect/type.go

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ type Type interface {
126126
// Chan: ChanDir, Elem
127127
// Func: In, NumIn, Out, NumOut, IsVariadic.
128128
// Map: Key, Elem
129-
// Ptr: Elem
129+
// Pointer: Elem
130130
// Slice: Elem
131131
// Struct: Field, FieldByIndex, FieldByName, FieldByNameFunc, NumField
132132

@@ -154,7 +154,7 @@ type Type interface {
154154
IsVariadic() bool
155155

156156
// Elem returns a type's element type.
157-
// It panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice.
157+
// It panics if the type's Kind is not Array, Chan, Map, Pointer, or Slice.
158158
Elem() Type
159159

160160
// Field returns a struct type's i'th field.
@@ -261,13 +261,18 @@ const (
261261
Func
262262
Interface
263263
Map
264-
Ptr
264+
Pointer
265265
Slice
266266
String
267267
Struct
268268
UnsafePointer
269269
)
270270

271+
// Ptr is the old name for the Pointer kind.
272+
//
273+
// Deprecated: use the new spelling, Pointer.
274+
const Ptr = Pointer
275+
271276
// tflag is used by an rtype to signal what extra type information is
272277
// available in the memory directly following the rtype value.
273278
//
@@ -658,7 +663,7 @@ var kindNames = []string{
658663
Func: "func",
659664
Interface: "interface",
660665
Map: "map",
661-
Ptr: "ptr",
666+
Pointer: "ptr",
662667
Slice: "slice",
663668
String: "string",
664669
Struct: "struct",
@@ -741,7 +746,7 @@ func (t *rtype) uncommon() *uncommonType {
741746
switch t.Kind() {
742747
case Struct:
743748
return &(*structTypeUncommon)(unsafe.Pointer(t)).u
744-
case Ptr:
749+
case Pointer:
745750
type u struct {
746751
ptrType
747752
u uncommonType
@@ -945,7 +950,7 @@ func (t *rtype) Elem() Type {
945950
case Map:
946951
tt := (*mapType)(unsafe.Pointer(t))
947952
return toType(tt.elem)
948-
case Ptr:
953+
case Pointer:
949954
tt := (*ptrType)(unsafe.Pointer(t))
950955
return toType(tt.elem)
951956
case Slice:
@@ -1265,7 +1270,7 @@ func (t *structType) FieldByIndex(index []int) (f StructField) {
12651270
for i, x := range index {
12661271
if i > 0 {
12671272
ft := f.Type
1268-
if ft.Kind() == Ptr && ft.Elem().Kind() == Struct {
1273+
if ft.Kind() == Pointer && ft.Elem().Kind() == Struct {
12691274
ft = ft.Elem()
12701275
}
12711276
f.Type = ft
@@ -1336,7 +1341,7 @@ func (t *structType) FieldByNameFunc(match func(string) bool) (result StructFiel
13361341
if f.embedded() {
13371342
// Embedded field of type T or *T.
13381343
ntyp = f.typ
1339-
if ntyp.Kind() == Ptr {
1344+
if ntyp.Kind() == Pointer {
13401345
ntyp = ntyp.Elem().common()
13411346
}
13421347
}
@@ -1416,12 +1421,19 @@ func TypeOf(i interface{}) Type {
14161421
return toType(eface.typ)
14171422
}
14181423

1419-
// ptrMap is the cache for PtrTo.
1424+
// ptrMap is the cache for PointerTo.
14201425
var ptrMap sync.Map // map[*rtype]*ptrType
14211426

14221427
// PtrTo returns the pointer type with element t.
14231428
// For example, if t represents type Foo, PtrTo(t) represents *Foo.
1424-
func PtrTo(t Type) Type {
1429+
//
1430+
// Deprecated: use PointerTo. PtrTo is the old spelling.
1431+
// The two functions behaves identically.
1432+
func PtrTo(t Type) Type { return PointerTo(t) }
1433+
1434+
// PointerTo returns the pointer type with element t.
1435+
// For example, if t represents type Foo, PointerTo(t) represents *Foo.
1436+
func PointerTo(t Type) Type {
14251437
return t.(*rtype).ptrTo()
14261438
}
14271439

@@ -1695,7 +1707,7 @@ func haveIdenticalUnderlyingType(T, V *rtype, cmpTags bool) bool {
16951707
case Map:
16961708
return haveIdenticalType(T.Key(), V.Key(), cmpTags) && haveIdenticalType(T.Elem(), V.Elem(), cmpTags)
16971709

1698-
case Ptr, Slice:
1710+
case Pointer, Slice:
16991711
return haveIdenticalType(T.Elem(), V.Elem(), cmpTags)
17001712

17011713
case Struct:
@@ -2136,7 +2148,7 @@ func funcStr(ft *funcType) string {
21362148
// That is, x == x for all values x of type t.
21372149
func isReflexive(t *rtype) bool {
21382150
switch t.Kind() {
2139-
case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Chan, Ptr, String, UnsafePointer:
2151+
case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Chan, Pointer, String, UnsafePointer:
21402152
return true
21412153
case Float32, Float64, Complex64, Complex128, Interface:
21422154
return false
@@ -2160,7 +2172,7 @@ func isReflexive(t *rtype) bool {
21602172
// needKeyUpdate reports whether map overwrites require the key to be copied.
21612173
func needKeyUpdate(t *rtype) bool {
21622174
switch t.Kind() {
2163-
case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Chan, Ptr, UnsafePointer:
2175+
case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Chan, Pointer, UnsafePointer:
21642176
return false
21652177
case Float32, Float64, Complex64, Complex128, Interface, String:
21662178
// Float keys can be updated from +0 to -0.
@@ -2217,10 +2229,10 @@ const (
22172229

22182230
func bucketOf(ktyp, etyp *rtype) *rtype {
22192231
if ktyp.size > maxKeySize {
2220-
ktyp = PtrTo(ktyp).(*rtype)
2232+
ktyp = PointerTo(ktyp).(*rtype)
22212233
}
22222234
if etyp.size > maxValSize {
2223-
etyp = PtrTo(etyp).(*rtype)
2235+
etyp = PointerTo(etyp).(*rtype)
22242236
}
22252237

22262238
// Prepare GC data if any.
@@ -2458,10 +2470,10 @@ func StructOf(fields []StructField) Type {
24582470
repr = append(repr, (" " + name)...)
24592471
if f.embedded() {
24602472
// Embedded field
2461-
if f.typ.Kind() == Ptr {
2473+
if f.typ.Kind() == Pointer {
24622474
// Embedded ** and *interface{} are illegal
24632475
elem := ft.Elem()
2464-
if k := elem.Kind(); k == Ptr || k == Interface {
2476+
if k := elem.Kind(); k == Pointer || k == Interface {
24652477
panic("reflect.StructOf: illegal embedded field type " + ft.String())
24662478
}
24672479
}
@@ -2526,7 +2538,7 @@ func StructOf(fields []StructField) Type {
25262538
tfn: resolveReflectText(unsafe.Pointer(&tfn)),
25272539
})
25282540
}
2529-
case Ptr:
2541+
case Pointer:
25302542
ptr := (*ptrType)(unsafe.Pointer(ft))
25312543
if unt := ptr.uncommon(); unt != nil {
25322544
if i > 0 && unt.mcount > 0 {
@@ -3123,7 +3135,7 @@ func addTypeBits(bv *bitVector, offset uintptr, t *rtype) {
31233135
}
31243136

31253137
switch Kind(t.kind & kindMask) {
3126-
case Chan, Func, Map, Ptr, Slice, String, UnsafePointer:
3138+
case Chan, Func, Map, Pointer, Slice, String, UnsafePointer:
31273139
// 1 pointer at start of representation
31283140
for bv.n < uint32(offset/uintptr(goarch.PtrSize)) {
31293141
bv.append(0)

0 commit comments

Comments
 (0)