mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
9f69a44308
commit
17910ed4ff
3 changed files with 38 additions and 24 deletions
|
|
@ -100,13 +100,15 @@ const (
|
||||||
Func
|
Func
|
||||||
Interface
|
Interface
|
||||||
Map
|
Map
|
||||||
Ptr
|
Pointer
|
||||||
Slice
|
Slice
|
||||||
String
|
String
|
||||||
Struct
|
Struct
|
||||||
UnsafePointer
|
UnsafePointer
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const Ptr = Pointer
|
||||||
|
|
||||||
// tflag is used by an rtype to signal what extra type information is
|
// tflag is used by an rtype to signal what extra type information is
|
||||||
// available in the memory directly following the rtype value.
|
// available in the memory directly following the rtype value.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ func (f flag) ro() flag {
|
||||||
}
|
}
|
||||||
|
|
||||||
// pointer returns the underlying pointer represented by v.
|
// pointer returns the underlying pointer represented by v.
|
||||||
// v.Kind() must be Ptr, Map, Chan, Func, or UnsafePointer
|
// v.Kind() must be Pointer, Map, Chan, Func, or UnsafePointer
|
||||||
func (v Value) pointer() unsafe.Pointer {
|
func (v Value) pointer() unsafe.Pointer {
|
||||||
if v.typ.size != goarch.PtrSize || !v.typ.pointers() {
|
if v.typ.size != goarch.PtrSize || !v.typ.pointers() {
|
||||||
panic("can't call pointer on a non-pointer Value")
|
panic("can't call pointer on a non-pointer Value")
|
||||||
|
|
@ -220,7 +220,7 @@ func (v Value) CanSet() bool {
|
||||||
|
|
||||||
// Elem returns the value that the interface v contains
|
// Elem returns the value that the interface v contains
|
||||||
// or that the pointer v points to.
|
// or that the pointer v points to.
|
||||||
// It panics if v's Kind is not Interface or Ptr.
|
// It panics if v's Kind is not Interface or Pointer.
|
||||||
// It returns the zero Value if v is nil.
|
// It returns the zero Value if v is nil.
|
||||||
func (v Value) Elem() Value {
|
func (v Value) Elem() Value {
|
||||||
k := v.kind()
|
k := v.kind()
|
||||||
|
|
@ -239,7 +239,7 @@ func (v Value) Elem() Value {
|
||||||
x.flag |= v.flag.ro()
|
x.flag |= v.flag.ro()
|
||||||
}
|
}
|
||||||
return x
|
return x
|
||||||
case Ptr:
|
case Pointer:
|
||||||
ptr := v.ptr
|
ptr := v.ptr
|
||||||
if v.flag&flagIndir != 0 {
|
if v.flag&flagIndir != 0 {
|
||||||
ptr = *(*unsafe.Pointer)(ptr)
|
ptr = *(*unsafe.Pointer)(ptr)
|
||||||
|
|
@ -288,7 +288,7 @@ func valueInterface(v Value) interface{} {
|
||||||
func (v Value) IsNil() bool {
|
func (v Value) IsNil() bool {
|
||||||
k := v.kind()
|
k := v.kind()
|
||||||
switch k {
|
switch k {
|
||||||
case Chan, Func, Map, Ptr, UnsafePointer:
|
case Chan, Func, Map, Pointer, UnsafePointer:
|
||||||
// if v.flag&flagMethod != 0 {
|
// if v.flag&flagMethod != 0 {
|
||||||
// return false
|
// return false
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ type Type interface {
|
||||||
// Chan: ChanDir, Elem
|
// Chan: ChanDir, Elem
|
||||||
// Func: In, NumIn, Out, NumOut, IsVariadic.
|
// Func: In, NumIn, Out, NumOut, IsVariadic.
|
||||||
// Map: Key, Elem
|
// Map: Key, Elem
|
||||||
// Ptr: Elem
|
// Pointer: Elem
|
||||||
// Slice: Elem
|
// Slice: Elem
|
||||||
// Struct: Field, FieldByIndex, FieldByName, FieldByNameFunc, NumField
|
// Struct: Field, FieldByIndex, FieldByName, FieldByNameFunc, NumField
|
||||||
|
|
||||||
|
|
@ -154,7 +154,7 @@ type Type interface {
|
||||||
IsVariadic() bool
|
IsVariadic() bool
|
||||||
|
|
||||||
// Elem returns a type's element type.
|
// 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
|
Elem() Type
|
||||||
|
|
||||||
// Field returns a struct type's i'th field.
|
// Field returns a struct type's i'th field.
|
||||||
|
|
@ -261,13 +261,18 @@ const (
|
||||||
Func
|
Func
|
||||||
Interface
|
Interface
|
||||||
Map
|
Map
|
||||||
Ptr
|
Pointer
|
||||||
Slice
|
Slice
|
||||||
String
|
String
|
||||||
Struct
|
Struct
|
||||||
UnsafePointer
|
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
|
// tflag is used by an rtype to signal what extra type information is
|
||||||
// available in the memory directly following the rtype value.
|
// available in the memory directly following the rtype value.
|
||||||
//
|
//
|
||||||
|
|
@ -658,7 +663,7 @@ var kindNames = []string{
|
||||||
Func: "func",
|
Func: "func",
|
||||||
Interface: "interface",
|
Interface: "interface",
|
||||||
Map: "map",
|
Map: "map",
|
||||||
Ptr: "ptr",
|
Pointer: "ptr",
|
||||||
Slice: "slice",
|
Slice: "slice",
|
||||||
String: "string",
|
String: "string",
|
||||||
Struct: "struct",
|
Struct: "struct",
|
||||||
|
|
@ -741,7 +746,7 @@ func (t *rtype) uncommon() *uncommonType {
|
||||||
switch t.Kind() {
|
switch t.Kind() {
|
||||||
case Struct:
|
case Struct:
|
||||||
return &(*structTypeUncommon)(unsafe.Pointer(t)).u
|
return &(*structTypeUncommon)(unsafe.Pointer(t)).u
|
||||||
case Ptr:
|
case Pointer:
|
||||||
type u struct {
|
type u struct {
|
||||||
ptrType
|
ptrType
|
||||||
u uncommonType
|
u uncommonType
|
||||||
|
|
@ -945,7 +950,7 @@ func (t *rtype) Elem() Type {
|
||||||
case Map:
|
case Map:
|
||||||
tt := (*mapType)(unsafe.Pointer(t))
|
tt := (*mapType)(unsafe.Pointer(t))
|
||||||
return toType(tt.elem)
|
return toType(tt.elem)
|
||||||
case Ptr:
|
case Pointer:
|
||||||
tt := (*ptrType)(unsafe.Pointer(t))
|
tt := (*ptrType)(unsafe.Pointer(t))
|
||||||
return toType(tt.elem)
|
return toType(tt.elem)
|
||||||
case Slice:
|
case Slice:
|
||||||
|
|
@ -1265,7 +1270,7 @@ func (t *structType) FieldByIndex(index []int) (f StructField) {
|
||||||
for i, x := range index {
|
for i, x := range index {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
ft := f.Type
|
ft := f.Type
|
||||||
if ft.Kind() == Ptr && ft.Elem().Kind() == Struct {
|
if ft.Kind() == Pointer && ft.Elem().Kind() == Struct {
|
||||||
ft = ft.Elem()
|
ft = ft.Elem()
|
||||||
}
|
}
|
||||||
f.Type = ft
|
f.Type = ft
|
||||||
|
|
@ -1336,7 +1341,7 @@ func (t *structType) FieldByNameFunc(match func(string) bool) (result StructFiel
|
||||||
if f.embedded() {
|
if f.embedded() {
|
||||||
// Embedded field of type T or *T.
|
// Embedded field of type T or *T.
|
||||||
ntyp = f.typ
|
ntyp = f.typ
|
||||||
if ntyp.Kind() == Ptr {
|
if ntyp.Kind() == Pointer {
|
||||||
ntyp = ntyp.Elem().common()
|
ntyp = ntyp.Elem().common()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1416,12 +1421,19 @@ func TypeOf(i interface{}) Type {
|
||||||
return toType(eface.typ)
|
return toType(eface.typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ptrMap is the cache for PtrTo.
|
// ptrMap is the cache for PointerTo.
|
||||||
var ptrMap sync.Map // map[*rtype]*ptrType
|
var ptrMap sync.Map // map[*rtype]*ptrType
|
||||||
|
|
||||||
// PtrTo returns the pointer type with element t.
|
// PtrTo returns the pointer type with element t.
|
||||||
// For example, if t represents type Foo, PtrTo(t) represents *Foo.
|
// 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()
|
return t.(*rtype).ptrTo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1695,7 +1707,7 @@ func haveIdenticalUnderlyingType(T, V *rtype, cmpTags bool) bool {
|
||||||
case Map:
|
case Map:
|
||||||
return haveIdenticalType(T.Key(), V.Key(), cmpTags) && haveIdenticalType(T.Elem(), V.Elem(), cmpTags)
|
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)
|
return haveIdenticalType(T.Elem(), V.Elem(), cmpTags)
|
||||||
|
|
||||||
case Struct:
|
case Struct:
|
||||||
|
|
@ -2136,7 +2148,7 @@ func funcStr(ft *funcType) string {
|
||||||
// That is, x == x for all values x of type t.
|
// That is, x == x for all values x of type t.
|
||||||
func isReflexive(t *rtype) bool {
|
func isReflexive(t *rtype) bool {
|
||||||
switch t.Kind() {
|
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
|
return true
|
||||||
case Float32, Float64, Complex64, Complex128, Interface:
|
case Float32, Float64, Complex64, Complex128, Interface:
|
||||||
return false
|
return false
|
||||||
|
|
@ -2160,7 +2172,7 @@ func isReflexive(t *rtype) bool {
|
||||||
// needKeyUpdate reports whether map overwrites require the key to be copied.
|
// needKeyUpdate reports whether map overwrites require the key to be copied.
|
||||||
func needKeyUpdate(t *rtype) bool {
|
func needKeyUpdate(t *rtype) bool {
|
||||||
switch t.Kind() {
|
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
|
return false
|
||||||
case Float32, Float64, Complex64, Complex128, Interface, String:
|
case Float32, Float64, Complex64, Complex128, Interface, String:
|
||||||
// Float keys can be updated from +0 to -0.
|
// Float keys can be updated from +0 to -0.
|
||||||
|
|
@ -2217,10 +2229,10 @@ const (
|
||||||
|
|
||||||
func bucketOf(ktyp, etyp *rtype) *rtype {
|
func bucketOf(ktyp, etyp *rtype) *rtype {
|
||||||
if ktyp.size > maxKeySize {
|
if ktyp.size > maxKeySize {
|
||||||
ktyp = PtrTo(ktyp).(*rtype)
|
ktyp = PointerTo(ktyp).(*rtype)
|
||||||
}
|
}
|
||||||
if etyp.size > maxValSize {
|
if etyp.size > maxValSize {
|
||||||
etyp = PtrTo(etyp).(*rtype)
|
etyp = PointerTo(etyp).(*rtype)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare GC data if any.
|
// Prepare GC data if any.
|
||||||
|
|
@ -2458,10 +2470,10 @@ func StructOf(fields []StructField) Type {
|
||||||
repr = append(repr, (" " + name)...)
|
repr = append(repr, (" " + name)...)
|
||||||
if f.embedded() {
|
if f.embedded() {
|
||||||
// Embedded field
|
// Embedded field
|
||||||
if f.typ.Kind() == Ptr {
|
if f.typ.Kind() == Pointer {
|
||||||
// Embedded ** and *interface{} are illegal
|
// Embedded ** and *interface{} are illegal
|
||||||
elem := ft.Elem()
|
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())
|
panic("reflect.StructOf: illegal embedded field type " + ft.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2526,7 +2538,7 @@ func StructOf(fields []StructField) Type {
|
||||||
tfn: resolveReflectText(unsafe.Pointer(&tfn)),
|
tfn: resolveReflectText(unsafe.Pointer(&tfn)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
case Ptr:
|
case Pointer:
|
||||||
ptr := (*ptrType)(unsafe.Pointer(ft))
|
ptr := (*ptrType)(unsafe.Pointer(ft))
|
||||||
if unt := ptr.uncommon(); unt != nil {
|
if unt := ptr.uncommon(); unt != nil {
|
||||||
if i > 0 && unt.mcount > 0 {
|
if i > 0 && unt.mcount > 0 {
|
||||||
|
|
@ -3123,7 +3135,7 @@ func addTypeBits(bv *bitVector, offset uintptr, t *rtype) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch Kind(t.kind & kindMask) {
|
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
|
// 1 pointer at start of representation
|
||||||
for bv.n < uint32(offset/uintptr(goarch.PtrSize)) {
|
for bv.n < uint32(offset/uintptr(goarch.PtrSize)) {
|
||||||
bv.append(0)
|
bv.append(0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue