Commit 9c9df65c authored by Daniel Martí's avatar Daniel Martí

reflect: remove useless parameter from newName

pkgPath always received the empty string. Worse yet, it panicked if it
received anything else. This has been the case ever since newName was
introduced in early 2016.

Change-Id: I5f164305bd30c34455ef35e776c7616f303b37e4
Reviewed-on: https://go-review.googlesource.com/54331
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
parent 29186526
...@@ -111,7 +111,7 @@ func IsExported(t Type) bool { ...@@ -111,7 +111,7 @@ func IsExported(t Type) bool {
} }
func ResolveReflectName(s string) { func ResolveReflectName(s string) {
resolveReflectName(newName(s, "", "", false)) resolveReflectName(newName(s, "", false))
} }
type Buffer struct { type Buffer struct {
......
...@@ -531,7 +531,7 @@ func round(n, a uintptr) uintptr { ...@@ -531,7 +531,7 @@ func round(n, a uintptr) uintptr {
return (n + a - 1) &^ (a - 1) return (n + a - 1) &^ (a - 1)
} }
func newName(n, tag, pkgPath string, exported bool) name { func newName(n, tag string, exported bool) name {
if len(n) > 1<<16-1 { if len(n) > 1<<16-1 {
panic("reflect.nameFrom: name too long: " + n) panic("reflect.nameFrom: name too long: " + n)
} }
...@@ -548,9 +548,6 @@ func newName(n, tag, pkgPath string, exported bool) name { ...@@ -548,9 +548,6 @@ func newName(n, tag, pkgPath string, exported bool) name {
l += 2 + len(tag) l += 2 + len(tag)
bits |= 1 << 1 bits |= 1 << 1
} }
if pkgPath != "" {
bits |= 1 << 2
}
b := make([]byte, l) b := make([]byte, l)
b[0] = bits b[0] = bits
...@@ -564,10 +561,6 @@ func newName(n, tag, pkgPath string, exported bool) name { ...@@ -564,10 +561,6 @@ func newName(n, tag, pkgPath string, exported bool) name {
copy(tb[2:], tag) copy(tb[2:], tag)
} }
if pkgPath != "" {
panic("reflect: creating a name with a package path is not supported")
}
return name{bytes: &b[0]} return name{bytes: &b[0]}
} }
...@@ -1436,7 +1429,7 @@ func (t *rtype) ptrTo() *rtype { ...@@ -1436,7 +1429,7 @@ func (t *rtype) ptrTo() *rtype {
prototype := *(**ptrType)(unsafe.Pointer(&iptr)) prototype := *(**ptrType)(unsafe.Pointer(&iptr))
pp := *prototype pp := *prototype
pp.str = resolveReflectName(newName(s, "", "", false)) pp.str = resolveReflectName(newName(s, "", false))
pp.ptrToThis = 0 pp.ptrToThis = 0
// For the type structures linked into the binary, the // For the type structures linked into the binary, the
...@@ -1849,7 +1842,7 @@ func ChanOf(dir ChanDir, t Type) Type { ...@@ -1849,7 +1842,7 @@ func ChanOf(dir ChanDir, t Type) Type {
ch := *prototype ch := *prototype
ch.tflag = 0 ch.tflag = 0
ch.dir = uintptr(dir) ch.dir = uintptr(dir)
ch.str = resolveReflectName(newName(s, "", "", false)) ch.str = resolveReflectName(newName(s, "", false))
ch.hash = fnv1(typ.hash, 'c', byte(dir)) ch.hash = fnv1(typ.hash, 'c', byte(dir))
ch.elem = typ ch.elem = typ
...@@ -1892,7 +1885,7 @@ func MapOf(key, elem Type) Type { ...@@ -1892,7 +1885,7 @@ func MapOf(key, elem Type) Type {
// Make a map type. // Make a map type.
var imap interface{} = (map[unsafe.Pointer]unsafe.Pointer)(nil) var imap interface{} = (map[unsafe.Pointer]unsafe.Pointer)(nil)
mt := **(**mapType)(unsafe.Pointer(&imap)) mt := **(**mapType)(unsafe.Pointer(&imap))
mt.str = resolveReflectName(newName(s, "", "", false)) mt.str = resolveReflectName(newName(s, "", false))
mt.tflag = 0 mt.tflag = 0
mt.hash = fnv1(etyp.hash, 'm', byte(ktyp.hash>>24), byte(ktyp.hash>>16), byte(ktyp.hash>>8), byte(ktyp.hash)) mt.hash = fnv1(etyp.hash, 'm', byte(ktyp.hash>>24), byte(ktyp.hash>>16), byte(ktyp.hash>>8), byte(ktyp.hash))
mt.key = ktyp mt.key = ktyp
...@@ -2060,7 +2053,7 @@ func FuncOf(in, out []Type, variadic bool) Type { ...@@ -2060,7 +2053,7 @@ func FuncOf(in, out []Type, variadic bool) Type {
} }
// Populate the remaining fields of ft and store in cache. // Populate the remaining fields of ft and store in cache.
ft.str = resolveReflectName(newName(str, "", "", false)) ft.str = resolveReflectName(newName(str, "", false))
ft.ptrToThis = 0 ft.ptrToThis = 0
return addToCache(&ft.rtype) return addToCache(&ft.rtype)
} }
...@@ -2255,7 +2248,7 @@ func bucketOf(ktyp, etyp *rtype) *rtype { ...@@ -2255,7 +2248,7 @@ func bucketOf(ktyp, etyp *rtype) *rtype {
b.align = 8 b.align = 8
} }
s := "bucket(" + ktyp.String() + "," + etyp.String() + ")" s := "bucket(" + ktyp.String() + "," + etyp.String() + ")"
b.str = resolveReflectName(newName(s, "", "", false)) b.str = resolveReflectName(newName(s, "", false))
return b return b
} }
...@@ -2285,7 +2278,7 @@ func SliceOf(t Type) Type { ...@@ -2285,7 +2278,7 @@ func SliceOf(t Type) Type {
prototype := *(**sliceType)(unsafe.Pointer(&islice)) prototype := *(**sliceType)(unsafe.Pointer(&islice))
slice := *prototype slice := *prototype
slice.tflag = 0 slice.tflag = 0
slice.str = resolveReflectName(newName(s, "", "", false)) slice.str = resolveReflectName(newName(s, "", false))
slice.hash = fnv1(typ.hash, '[') slice.hash = fnv1(typ.hash, '[')
slice.elem = typ slice.elem = typ
slice.ptrToThis = 0 slice.ptrToThis = 0
...@@ -2684,7 +2677,7 @@ func StructOf(fields []StructField) Type { ...@@ -2684,7 +2677,7 @@ func StructOf(fields []StructField) Type {
} }
} }
typ.str = resolveReflectName(newName(str, "", "", false)) typ.str = resolveReflectName(newName(str, "", false))
typ.tflag = 0 typ.tflag = 0
typ.hash = hash typ.hash = hash
typ.size = size typ.size = size
...@@ -2813,7 +2806,7 @@ func runtimeStructField(field StructField) structField { ...@@ -2813,7 +2806,7 @@ func runtimeStructField(field StructField) structField {
resolveReflectType(field.Type.common()) // install in runtime resolveReflectType(field.Type.common()) // install in runtime
return structField{ return structField{
name: newName(field.Name, string(field.Tag), "", true), name: newName(field.Name, string(field.Tag), true),
typ: field.Type.common(), typ: field.Type.common(),
offsetAnon: offsetAnon, offsetAnon: offsetAnon,
} }
...@@ -2877,7 +2870,7 @@ func ArrayOf(count int, elem Type) Type { ...@@ -2877,7 +2870,7 @@ func ArrayOf(count int, elem Type) Type {
prototype := *(**arrayType)(unsafe.Pointer(&iarray)) prototype := *(**arrayType)(unsafe.Pointer(&iarray))
array := *prototype array := *prototype
array.tflag = 0 array.tflag = 0
array.str = resolveReflectName(newName(s, "", "", false)) array.str = resolveReflectName(newName(s, "", false))
array.hash = fnv1(typ.hash, '[') array.hash = fnv1(typ.hash, '[')
for n := uint32(count); n > 0; n >>= 8 { for n := uint32(count); n > 0; n >>= 8 {
array.hash = fnv1(array.hash, byte(n)) array.hash = fnv1(array.hash, byte(n))
...@@ -3130,7 +3123,7 @@ func funcLayout(t *rtype, rcvr *rtype) (frametype *rtype, argSize, retOffset uin ...@@ -3130,7 +3123,7 @@ func funcLayout(t *rtype, rcvr *rtype) (frametype *rtype, argSize, retOffset uin
} else { } else {
s = "funcargs(" + t.String() + ")" s = "funcargs(" + t.String() + ")"
} }
x.str = resolveReflectName(newName(s, "", "", false)) x.str = resolveReflectName(newName(s, "", false))
// cache result for future callers // cache result for future callers
framePool = &sync.Pool{New: func() interface{} { framePool = &sync.Pool{New: func() interface{} {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment