aboutsummaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2021-08-11 10:54:39 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2021-09-03 04:24:17 +0000
commit17910ed4ff5a3cb3dcf4367d4af23ad5a7fe5809 (patch)
treea483b5c945b706156e84be933b2c28c4efa2e1e5 /src/reflect
parent9f69a44308f4f9cbdae68925202dfef2027a7d20 (diff)
downloadgo-17910ed4ff5a3cb3dcf4367d4af23ad5a7fe5809.tar.gz
go-17910ed4ff5a3cb3dcf4367d4af23ad5a7fe5809.zip
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 <bradfitz@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Joe Tsai <joetsai@digital-static.net> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/type.go50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/reflect/type.go b/src/reflect/type.go
index 278426da09..1d637d134e 100644
--- a/src/reflect/type.go
+++ b/src/reflect/type.go
@@ -126,7 +126,7 @@ type Type interface {
// Chan: ChanDir, Elem
// Func: In, NumIn, Out, NumOut, IsVariadic.
// Map: Key, Elem
- // Ptr: Elem
+ // Pointer: Elem
// Slice: Elem
// Struct: Field, FieldByIndex, FieldByName, FieldByNameFunc, NumField
@@ -154,7 +154,7 @@ type Type interface {
IsVariadic() bool
// Elem returns a type's element type.
- // It panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice.
+ // It panics if the type's Kind is not Array, Chan, Map, Pointer, or Slice.
Elem() Type
// Field returns a struct type's i'th field.
@@ -261,13 +261,18 @@ const (
Func
Interface
Map
- Ptr
+ Pointer
Slice
String
Struct
UnsafePointer
)
+// Ptr is the old name for the Pointer kind.
+//
+// Deprecated: use the new spelling, Pointer.
+const Ptr = Pointer
+
// tflag is used by an rtype to signal what extra type information is
// available in the memory directly following the rtype value.
//
@@ -658,7 +663,7 @@ var kindNames = []string{
Func: "func",
Interface: "interface",
Map: "map",
- Ptr: "ptr",
+ Pointer: "ptr",
Slice: "slice",
String: "string",
Struct: "struct",
@@ -741,7 +746,7 @@ func (t *rtype) uncommon() *uncommonType {
switch t.Kind() {
case Struct:
return &(*structTypeUncommon)(unsafe.Pointer(t)).u
- case Ptr:
+ case Pointer:
type u struct {
ptrType
u uncommonType
@@ -945,7 +950,7 @@ func (t *rtype) Elem() Type {
case Map:
tt := (*mapType)(unsafe.Pointer(t))
return toType(tt.elem)
- case Ptr:
+ case Pointer:
tt := (*ptrType)(unsafe.Pointer(t))
return toType(tt.elem)
case Slice:
@@ -1265,7 +1270,7 @@ func (t *structType) FieldByIndex(index []int) (f StructField) {
for i, x := range index {
if i > 0 {
ft := f.Type
- if ft.Kind() == Ptr && ft.Elem().Kind() == Struct {
+ if ft.Kind() == Pointer && ft.Elem().Kind() == Struct {
ft = ft.Elem()
}
f.Type = ft
@@ -1336,7 +1341,7 @@ func (t *structType) FieldByNameFunc(match func(string) bool) (result StructFiel
if f.embedded() {
// Embedded field of type T or *T.
ntyp = f.typ
- if ntyp.Kind() == Ptr {
+ if ntyp.Kind() == Pointer {
ntyp = ntyp.Elem().common()
}
}
@@ -1416,12 +1421,19 @@ func TypeOf(i interface{}) Type {
return toType(eface.typ)
}
-// ptrMap is the cache for PtrTo.
+// ptrMap is the cache for PointerTo.
var ptrMap sync.Map // map[*rtype]*ptrType
// PtrTo returns the pointer type with element t.
// For example, if t represents type Foo, PtrTo(t) represents *Foo.
-func PtrTo(t Type) Type {
+//
+// Deprecated: use PointerTo. PtrTo is the old spelling.
+// The two functions behaves identically.
+func PtrTo(t Type) Type { return PointerTo(t) }
+
+// PointerTo returns the pointer type with element t.
+// For example, if t represents type Foo, PointerTo(t) represents *Foo.
+func PointerTo(t Type) Type {
return t.(*rtype).ptrTo()
}
@@ -1695,7 +1707,7 @@ func haveIdenticalUnderlyingType(T, V *rtype, cmpTags bool) bool {
case Map:
return haveIdenticalType(T.Key(), V.Key(), cmpTags) && haveIdenticalType(T.Elem(), V.Elem(), cmpTags)
- case Ptr, Slice:
+ case Pointer, Slice:
return haveIdenticalType(T.Elem(), V.Elem(), cmpTags)
case Struct:
@@ -2136,7 +2148,7 @@ func funcStr(ft *funcType) string {
// That is, x == x for all values x of type t.
func isReflexive(t *rtype) bool {
switch t.Kind() {
- case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Chan, Ptr, String, UnsafePointer:
+ case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Chan, Pointer, String, UnsafePointer:
return true
case Float32, Float64, Complex64, Complex128, Interface:
return false
@@ -2160,7 +2172,7 @@ func isReflexive(t *rtype) bool {
// needKeyUpdate reports whether map overwrites require the key to be copied.
func needKeyUpdate(t *rtype) bool {
switch t.Kind() {
- case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Chan, Ptr, UnsafePointer:
+ case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Chan, Pointer, UnsafePointer:
return false
case Float32, Float64, Complex64, Complex128, Interface, String:
// Float keys can be updated from +0 to -0.
@@ -2217,10 +2229,10 @@ const (
func bucketOf(ktyp, etyp *rtype) *rtype {
if ktyp.size > maxKeySize {
- ktyp = PtrTo(ktyp).(*rtype)
+ ktyp = PointerTo(ktyp).(*rtype)
}
if etyp.size > maxValSize {
- etyp = PtrTo(etyp).(*rtype)
+ etyp = PointerTo(etyp).(*rtype)
}
// Prepare GC data if any.
@@ -2458,10 +2470,10 @@ func StructOf(fields []StructField) Type {
repr = append(repr, (" " + name)...)
if f.embedded() {
// Embedded field
- if f.typ.Kind() == Ptr {
+ if f.typ.Kind() == Pointer {
// Embedded ** and *interface{} are illegal
elem := ft.Elem()
- if k := elem.Kind(); k == Ptr || k == Interface {
+ if k := elem.Kind(); k == Pointer || k == Interface {
panic("reflect.StructOf: illegal embedded field type " + ft.String())
}
}
@@ -2526,7 +2538,7 @@ func StructOf(fields []StructField) Type {
tfn: resolveReflectText(unsafe.Pointer(&tfn)),
})
}
- case Ptr:
+ case Pointer:
ptr := (*ptrType)(unsafe.Pointer(ft))
if unt := ptr.uncommon(); unt != nil {
if i > 0 && unt.mcount > 0 {
@@ -3123,7 +3135,7 @@ func addTypeBits(bv *bitVector, offset uintptr, t *rtype) {
}
switch Kind(t.kind & kindMask) {
- case Chan, Func, Map, Ptr, Slice, String, UnsafePointer:
+ case Chan, Func, Map, Pointer, Slice, String, UnsafePointer:
// 1 pointer at start of representation
for bv.n < uint32(offset/uintptr(goarch.PtrSize)) {
bv.append(0)