Skip to content

Commit 94dba61

Browse files
aclementsgopherbot
authored andcommitted
internal/abi: clean up type of Kind and Type.Kind_
Currently, Type.Kind_ is a uint8, Kind is a uint, and some of the abi.Kind consts are not of type Kind. Clean this all up by making Kind a uint8, then making Type.Kind a Kind, and finally making all Kind consts actually have type Kind. This has some ripple effect, but I think all of the changes are improvements. Change-Id: If39be74699c2cdb52bf0ad7092d392bc8fb68d15 Reviewed-on: https://go-review.googlesource.com/c/go/+/575579 Auto-Submit: Austin Clements <austin@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent cb6d15a commit 94dba61

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

src/cmd/link/internal/ld/data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ func (p *GCProg) AddSym(s loader.Sym) {
13461346
}
13471347

13481348
sval := ldr.SymValue(s)
1349-
if decodetypeUsegcprog(p.ctxt.Arch, typData) == 0 {
1349+
if !decodetypeUsegcprog(p.ctxt.Arch, typData) {
13501350
// Copy pointers from mask into program.
13511351
mask := decodetypeGcmask(p.ctxt, typ)
13521352
for i := int64(0); i < nptr; i++ {

src/cmd/link/internal/ld/deadcode.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func (d *deadcodePass) decodeIfaceMethod(ldr *loader.Loader, arch *sys.Arch, sym
512512
if p == nil {
513513
panic(fmt.Sprintf("missing symbol %q", ldr.SymName(symIdx)))
514514
}
515-
if abi.Kind(decodetypeKind(arch, p)&abi.KindMask) != abi.Interface {
515+
if decodetypeKind(arch, p) != abi.Interface {
516516
panic(fmt.Sprintf("symbol %q is not an interface", ldr.SymName(symIdx)))
517517
}
518518
relocs := ldr.Relocs(symIdx)
@@ -533,7 +533,7 @@ func (d *deadcodePass) decodetypeMethods(ldr *loader.Loader, arch *sys.Arch, sym
533533
panic(fmt.Sprintf("no methods on %q", ldr.SymName(symIdx)))
534534
}
535535
off := commonsize(arch) // reflect.rtype
536-
switch abi.Kind(decodetypeKind(arch, p) & abi.KindMask) {
536+
switch decodetypeKind(arch, p) {
537537
case abi.Struct: // reflect.structType
538538
off += 4 * arch.PtrSize
539539
case abi.Pointer: // reflect.ptrType

src/cmd/link/internal/ld/decodesym.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ func structfieldSize(arch *sys.Arch) int { return abi.StructFieldSize(arch.PtrSi
3737
func uncommonSize(arch *sys.Arch) int { return int(abi.UncommonSize()) } // runtime.uncommontype
3838

3939
// Type.commonType.kind
40-
func decodetypeKind(arch *sys.Arch, p []byte) uint8 {
41-
return p[2*arch.PtrSize+7] & abi.KindMask // 0x13 / 0x1f
40+
func decodetypeKind(arch *sys.Arch, p []byte) abi.Kind {
41+
return abi.Kind(p[2*arch.PtrSize+7]) & abi.KindMask // 0x13 / 0x1f
4242
}
4343

4444
// Type.commonType.kind
45-
func decodetypeUsegcprog(arch *sys.Arch, p []byte) uint8 {
46-
return p[2*arch.PtrSize+7] & abi.KindGCProg // 0x13 / 0x1f
45+
func decodetypeUsegcprog(arch *sys.Arch, p []byte) bool {
46+
return abi.Kind(p[2*arch.PtrSize+7])&abi.KindGCProg != 0 // 0x13 / 0x1f
4747
}
4848

4949
// Type.commonType.size

src/cmd/link/internal/ld/dwarf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
542542
bytesize := decodetypeSize(d.arch, tdata)
543543

544544
var die, typedefdie *dwarf.DWDie
545-
switch abi.Kind(kind) {
545+
switch kind {
546546
case abi.Bool:
547547
die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name)
548548
newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_boolean, 0)

src/internal/abi/type.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ const (
7272

7373
const (
7474
// TODO (khr, drchase) why aren't these in TFlag? Investigate, fix if possible.
75-
KindDirectIface = 1 << 5
76-
KindGCProg = 1 << 6 // Type.gc points to GC program
77-
KindMask = (1 << 5) - 1
75+
KindDirectIface Kind = 1 << 5
76+
KindGCProg Kind = 1 << 6 // Type.gc points to GC program
77+
KindMask Kind = (1 << 5) - 1
7878
)
7979

8080
// TFlag is used by a Type to signal what extra type information is
@@ -166,7 +166,7 @@ var kindNames = []string{
166166
UnsafePointer: "unsafe.Pointer",
167167
}
168168

169-
func (t *Type) Kind() Kind { return Kind(t.Kind_ & KindMask) }
169+
func (t *Type) Kind() Kind { return t.Kind_ & KindMask }
170170

171171
func (t *Type) HasName() bool {
172172
return t.TFlag&TFlagNamed != 0

src/internal/reflectlite/type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,5 +661,5 @@ func toType(t *abi.Type) Type {
661661

662662
// ifaceIndir reports whether t is stored indirectly in an interface value.
663663
func ifaceIndir(t *abi.Type) bool {
664-
return t.Kind_&abi.KindDirectIface == 0
664+
return abi.Kind(t.Kind_)&abi.KindDirectIface == 0
665665
}

0 commit comments

Comments
 (0)