]> Cypherpunks repositories - gostls13.git/commitdiff
internal/abi: clean up type of Kind and Type.Kind_
authorAustin Clements <austin@google.com>
Mon, 1 Apr 2024 19:39:41 +0000 (15:39 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 2 Apr 2024 16:25:18 +0000 (16:25 +0000)
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>

src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/deadcode.go
src/cmd/link/internal/ld/decodesym.go
src/cmd/link/internal/ld/dwarf.go
src/internal/abi/type.go
src/internal/reflectlite/type.go

index b4930277e40da740e5fafc0463a9e1ed5d446d67..11dc48b18b524978335394c262d75654e90cdded 100644 (file)
@@ -1346,7 +1346,7 @@ func (p *GCProg) AddSym(s loader.Sym) {
        }
 
        sval := ldr.SymValue(s)
-       if decodetypeUsegcprog(p.ctxt.Arch, typData) == 0 {
+       if !decodetypeUsegcprog(p.ctxt.Arch, typData) {
                // Copy pointers from mask into program.
                mask := decodetypeGcmask(p.ctxt, typ)
                for i := int64(0); i < nptr; i++ {
index f635d7582f498bedd42d005bfc762f0bd65b80db..241cf603dbd7661d1e34a21d9f8f5ba541a51b90 100644 (file)
@@ -512,7 +512,7 @@ func (d *deadcodePass) decodeIfaceMethod(ldr *loader.Loader, arch *sys.Arch, sym
        if p == nil {
                panic(fmt.Sprintf("missing symbol %q", ldr.SymName(symIdx)))
        }
-       if abi.Kind(decodetypeKind(arch, p)&abi.KindMask) != abi.Interface {
+       if decodetypeKind(arch, p) != abi.Interface {
                panic(fmt.Sprintf("symbol %q is not an interface", ldr.SymName(symIdx)))
        }
        relocs := ldr.Relocs(symIdx)
@@ -533,7 +533,7 @@ func (d *deadcodePass) decodetypeMethods(ldr *loader.Loader, arch *sys.Arch, sym
                panic(fmt.Sprintf("no methods on %q", ldr.SymName(symIdx)))
        }
        off := commonsize(arch) // reflect.rtype
-       switch abi.Kind(decodetypeKind(arch, p) & abi.KindMask) {
+       switch decodetypeKind(arch, p) {
        case abi.Struct: // reflect.structType
                off += 4 * arch.PtrSize
        case abi.Pointer: // reflect.ptrType
index 99f058aed2f250884b729ea10d00f701d6dbb92f..ab2b8fac590511ff505076a3c9ed459dceb4eb84 100644 (file)
@@ -37,13 +37,13 @@ func structfieldSize(arch *sys.Arch) int { return abi.StructFieldSize(arch.PtrSi
 func uncommonSize(arch *sys.Arch) int    { return int(abi.UncommonSize()) }           // runtime.uncommontype
 
 // Type.commonType.kind
-func decodetypeKind(arch *sys.Arch, p []byte) uint8 {
-       return p[2*arch.PtrSize+7] & abi.KindMask //  0x13 / 0x1f
+func decodetypeKind(arch *sys.Arch, p []byte) abi.Kind {
+       return abi.Kind(p[2*arch.PtrSize+7]) & abi.KindMask //  0x13 / 0x1f
 }
 
 // Type.commonType.kind
-func decodetypeUsegcprog(arch *sys.Arch, p []byte) uint8 {
-       return p[2*arch.PtrSize+7] & abi.KindGCProg //  0x13 / 0x1f
+func decodetypeUsegcprog(arch *sys.Arch, p []byte) bool {
+       return abi.Kind(p[2*arch.PtrSize+7])&abi.KindGCProg != 0 //  0x13 / 0x1f
 }
 
 // Type.commonType.size
index 50fbdf1f185bc2e527ef4c08313a66cb638954aa..886c1ff6725a5699418157635a63779f635f6f20 100644 (file)
@@ -542,7 +542,7 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
        bytesize := decodetypeSize(d.arch, tdata)
 
        var die, typedefdie *dwarf.DWDie
-       switch abi.Kind(kind) {
+       switch kind {
        case abi.Bool:
                die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name)
                newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_boolean, 0)
index 1b6cc00855f65bd94c3fe6ec613d11f491c79458..0686bac4c3729d2dbb97e2eea682f2ee9b317fc5 100644 (file)
@@ -72,9 +72,9 @@ const (
 
 const (
        // TODO (khr, drchase) why aren't these in TFlag?  Investigate, fix if possible.
-       KindDirectIface = 1 << 5
-       KindGCProg      = 1 << 6 // Type.gc points to GC program
-       KindMask        = (1 << 5) - 1
+       KindDirectIface Kind = 1 << 5
+       KindGCProg      Kind = 1 << 6 // Type.gc points to GC program
+       KindMask        Kind = (1 << 5) - 1
 )
 
 // TFlag is used by a Type to signal what extra type information is
@@ -166,7 +166,7 @@ var kindNames = []string{
        UnsafePointer: "unsafe.Pointer",
 }
 
-func (t *Type) Kind() Kind { return Kind(t.Kind_ & KindMask) }
+func (t *Type) Kind() Kind { return t.Kind_ & KindMask }
 
 func (t *Type) HasName() bool {
        return t.TFlag&TFlagNamed != 0
index e585d24f538c11877a49406a58e42c8f1a235bef..8c47a265b8c75ec9e73f71e0f30fb881dca6f1af 100644 (file)
@@ -661,5 +661,5 @@ func toType(t *abi.Type) Type {
 
 // ifaceIndir reports whether t is stored indirectly in an interface value.
 func ifaceIndir(t *abi.Type) bool {
-       return t.Kind_&abi.KindDirectIface == 0
+       return abi.Kind(t.Kind_)&abi.KindDirectIface == 0
 }