Permalink
Browse files

natives/reflect: Sort exported methods first; add xcount to uncommonT…

…ype.

What was previously an unused blank identifier field of type uint16 in
Go 1.10 has become the xcount field in Go 1.11. Update our uncommonType
to match.

Also remove the unused uint32 field at the end. In normal Go, it's used
for padding and to keep the struct size fixed size. GopherJS doesn't
need that, because it doesn't support unsafe memory operations.

Fixes:

	$ gopherjs build reflect
	reflect/type.go:2603:5: invalid operation: ut (variable of type *uncommonType) has no field or method xcount
	reflect/type.go:643:7: invalid operation: t (variable of type *uncommonType) has no field or method xcount
	reflect/type.go:646:88: invalid operation: t (variable of type *uncommonType) has no field or method xcount
	reflect/type.go:646:97: invalid operation: t (variable of type *uncommonType) has no field or method xcount

Follows golang/go@86a3389.
Updates golang/go#22075.
  • Loading branch information...
dmitshur committed Jun 27, 2018
1 parent a6e22d0 commit 486731921c14d88d81b96f2eb929cc4f29da68bb
Showing with 26 additions and 6 deletions.
  1. +26 −6 compiler/natives/src/reflect/reflect.go
@@ -53,17 +53,34 @@ func reflectType(typ *js.Object) *rtype {
if typ.Get("named").Bool() {
rt.tflag |= tflagNamed
}
reflectMethods := make([]method, methodSet.Length())
for i := range reflectMethods {
var reflectMethods []method
for i := 0; i < methodSet.Length(); i++ { // Exported methods first.
m := methodSet.Index(i)
reflectMethods[i] = method{
name: newNameOff(newName(internalStr(m.Get("name")), "", internalStr(m.Get("pkg")) == "")),
exported := internalStr(m.Get("pkg")) == ""
if !exported {
continue
}
reflectMethods = append(reflectMethods, method{
name: newNameOff(newName(internalStr(m.Get("name")), "", exported)),
mtyp: newTypeOff(reflectType(m.Get("typ"))),
})
}
xcount := uint16(len(reflectMethods))
for i := 0; i < methodSet.Length(); i++ { // Unexported methods second.
m := methodSet.Index(i)
exported := internalStr(m.Get("pkg")) == ""
if exported {
continue
}
reflectMethods = append(reflectMethods, method{
name: newNameOff(newName(internalStr(m.Get("name")), "", exported)),
mtyp: newTypeOff(reflectType(m.Get("typ"))),
})
}
ut := &uncommonType{
pkgPath: newNameOff(newName(internalStr(typ.Get("pkg")), "", false)),
mcount: uint16(methodSet.Length()),
xcount: xcount,
_methods: reflectMethods,
}
uncommonTypeMap[rt] = ut
@@ -172,9 +189,8 @@ func setKindType(rt *rtype, kindType interface{}) {
type uncommonType struct {
pkgPath nameOff
mcount uint16
_ uint16
xcount uint16
moff uint32
_ uint32
_methods []method
}
@@ -183,6 +199,10 @@ func (t *uncommonType) methods() []method {
return t._methods
}
func (t *uncommonType) exportedMethods() []method {
return t._methods[:t.xcount:t.xcount]
}
var uncommonTypeMap = make(map[*rtype]*uncommonType)
func (t *rtype) uncommon() *uncommonType {

0 comments on commit 4867319

Please sign in to comment.