Skip to content

Commit daaf1f2

Browse files
qiulaidongfenggopherbot
authored andcommitted
all: use kind* of abi
For #59670 Change-Id: Id66e102f13e529dd041b68ce869026a56f0a1b9b GitHub-Last-Rev: 43aa937 GitHub-Pull-Request: #65564 Reviewed-on: https://go-review.googlesource.com/c/go/+/562298 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Austin Clements <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Austin Clements <[email protected]>
1 parent e3ec1ca commit daaf1f2

28 files changed

+235
-313
lines changed

src/cmd/compile/internal/reflectdata/reflect.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -624,33 +624,33 @@ func dmethodptrOff(c rttype.Cursor, x *obj.LSym) {
624624
r.Type = objabi.R_METHODOFF
625625
}
626626

627-
var kinds = []int{
628-
types.TINT: objabi.KindInt,
629-
types.TUINT: objabi.KindUint,
630-
types.TINT8: objabi.KindInt8,
631-
types.TUINT8: objabi.KindUint8,
632-
types.TINT16: objabi.KindInt16,
633-
types.TUINT16: objabi.KindUint16,
634-
types.TINT32: objabi.KindInt32,
635-
types.TUINT32: objabi.KindUint32,
636-
types.TINT64: objabi.KindInt64,
637-
types.TUINT64: objabi.KindUint64,
638-
types.TUINTPTR: objabi.KindUintptr,
639-
types.TFLOAT32: objabi.KindFloat32,
640-
types.TFLOAT64: objabi.KindFloat64,
641-
types.TBOOL: objabi.KindBool,
642-
types.TSTRING: objabi.KindString,
643-
types.TPTR: objabi.KindPtr,
644-
types.TSTRUCT: objabi.KindStruct,
645-
types.TINTER: objabi.KindInterface,
646-
types.TCHAN: objabi.KindChan,
647-
types.TMAP: objabi.KindMap,
648-
types.TARRAY: objabi.KindArray,
649-
types.TSLICE: objabi.KindSlice,
650-
types.TFUNC: objabi.KindFunc,
651-
types.TCOMPLEX64: objabi.KindComplex64,
652-
types.TCOMPLEX128: objabi.KindComplex128,
653-
types.TUNSAFEPTR: objabi.KindUnsafePointer,
627+
var kinds = []abi.Kind{
628+
types.TINT: abi.Int,
629+
types.TUINT: abi.Uint,
630+
types.TINT8: abi.Int8,
631+
types.TUINT8: abi.Uint8,
632+
types.TINT16: abi.Int16,
633+
types.TUINT16: abi.Uint16,
634+
types.TINT32: abi.Int32,
635+
types.TUINT32: abi.Uint32,
636+
types.TINT64: abi.Int64,
637+
types.TUINT64: abi.Uint64,
638+
types.TUINTPTR: abi.Uintptr,
639+
types.TFLOAT32: abi.Float32,
640+
types.TFLOAT64: abi.Float64,
641+
types.TBOOL: abi.Bool,
642+
types.TSTRING: abi.String,
643+
types.TPTR: abi.Pointer,
644+
types.TSTRUCT: abi.Struct,
645+
types.TINTER: abi.Interface,
646+
types.TCHAN: abi.Chan,
647+
types.TMAP: abi.Map,
648+
types.TARRAY: abi.Array,
649+
types.TSLICE: abi.Slice,
650+
types.TFUNC: abi.Func,
651+
types.TCOMPLEX64: abi.Complex64,
652+
types.TCOMPLEX128: abi.Complex128,
653+
types.TUNSAFEPTR: abi.UnsafePointer,
654654
}
655655

656656
var (
@@ -743,14 +743,14 @@ func dcommontype(c rttype.Cursor, t *types.Type) {
743743
c.Field("Align_").WriteUint8(uint8(t.Alignment()))
744744
c.Field("FieldAlign_").WriteUint8(uint8(t.Alignment()))
745745

746-
i = kinds[t.Kind()]
746+
kind := kinds[t.Kind()]
747747
if types.IsDirectIface(t) {
748-
i |= objabi.KindDirectIface
748+
kind |= abi.KindDirectIface
749749
}
750750
if useGCProg {
751-
i |= objabi.KindGCProg
751+
kind |= abi.KindGCProg
752752
}
753-
c.Field("Kind_").WriteUint8(uint8(i))
753+
c.Field("Kind_").WriteUint8(uint8(kind))
754754

755755
c.Field("Equal").WritePtr(eqfunc)
756756
c.Field("GCData").WritePtr(gcsym)

src/cmd/internal/objabi/typekind.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"cmd/link/internal/loader"
1212
"cmd/link/internal/sym"
1313
"fmt"
14+
"internal/abi"
1415
"internal/buildcfg"
1516
"strings"
1617
"unicode"
@@ -511,7 +512,7 @@ func (d *deadcodePass) decodeIfaceMethod(ldr *loader.Loader, arch *sys.Arch, sym
511512
if p == nil {
512513
panic(fmt.Sprintf("missing symbol %q", ldr.SymName(symIdx)))
513514
}
514-
if decodetypeKind(arch, p)&kindMask != kindInterface {
515+
if abi.Kind(decodetypeKind(arch, p)&abi.KindMask) != abi.Interface {
515516
panic(fmt.Sprintf("symbol %q is not an interface", ldr.SymName(symIdx)))
516517
}
517518
relocs := ldr.Relocs(symIdx)
@@ -532,22 +533,22 @@ func (d *deadcodePass) decodetypeMethods(ldr *loader.Loader, arch *sys.Arch, sym
532533
panic(fmt.Sprintf("no methods on %q", ldr.SymName(symIdx)))
533534
}
534535
off := commonsize(arch) // reflect.rtype
535-
switch decodetypeKind(arch, p) & kindMask {
536-
case kindStruct: // reflect.structType
536+
switch abi.Kind(decodetypeKind(arch, p) & abi.KindMask) {
537+
case abi.Struct: // reflect.structType
537538
off += 4 * arch.PtrSize
538-
case kindPtr: // reflect.ptrType
539+
case abi.Pointer: // reflect.ptrType
539540
off += arch.PtrSize
540-
case kindFunc: // reflect.funcType
541+
case abi.Func: // reflect.funcType
541542
off += arch.PtrSize // 4 bytes, pointer aligned
542-
case kindSlice: // reflect.sliceType
543+
case abi.Slice: // reflect.sliceType
543544
off += arch.PtrSize
544-
case kindArray: // reflect.arrayType
545+
case abi.Array: // reflect.arrayType
545546
off += 3 * arch.PtrSize
546-
case kindChan: // reflect.chanType
547+
case abi.Chan: // reflect.chanType
547548
off += 2 * arch.PtrSize
548-
case kindMap: // reflect.mapType
549+
case abi.Map: // reflect.mapType
549550
off += 4*arch.PtrSize + 8
550-
case kindInterface: // reflect.interfaceType
551+
case abi.Interface: // reflect.interfaceType
551552
off += 3 * arch.PtrSize
552553
default:
553554
// just Sizeof(rtype)

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package ld
66

77
import (
8-
"cmd/internal/objabi"
98
"cmd/internal/sys"
109
"cmd/link/internal/loader"
1110
"cmd/link/internal/sym"
@@ -39,12 +38,12 @@ func uncommonSize(arch *sys.Arch) int { return int(abi.UncommonSize()) }
3938

4039
// Type.commonType.kind
4140
func decodetypeKind(arch *sys.Arch, p []byte) uint8 {
42-
return p[2*arch.PtrSize+7] & objabi.KindMask // 0x13 / 0x1f
41+
return p[2*arch.PtrSize+7] & abi.KindMask // 0x13 / 0x1f
4342
}
4443

4544
// Type.commonType.kind
4645
func decodetypeUsegcprog(arch *sys.Arch, p []byte) uint8 {
47-
return p[2*arch.PtrSize+7] & objabi.KindGCProg // 0x13 / 0x1f
46+
return p[2*arch.PtrSize+7] & abi.KindGCProg // 0x13 / 0x1f
4847
}
4948

5049
// Type.commonType.size
@@ -81,19 +80,6 @@ func decodetypeIfaceMethodCount(arch *sys.Arch, p []byte) int64 {
8180
return int64(decodeInuxi(arch, p[commonsize(arch)+2*arch.PtrSize:], arch.PtrSize))
8281
}
8382

84-
// Matches runtime/typekind.go and reflect.Kind.
85-
const (
86-
kindArray = 17
87-
kindChan = 18
88-
kindFunc = 19
89-
kindInterface = 20
90-
kindMap = 21
91-
kindPtr = 22
92-
kindSlice = 23
93-
kindStruct = 25
94-
kindMask = (1 << 5) - 1
95-
)
96-
9783
func decodeReloc(ldr *loader.Loader, symIdx loader.Sym, relocs *loader.Relocs, off int32) loader.Reloc {
9884
for j := 0; j < relocs.Count(); j++ {
9985
rel := relocs.At(j)

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

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

544544
var die, typedefdie *dwarf.DWDie
545-
switch kind {
546-
case objabi.KindBool:
545+
switch abi.Kind(kind) {
546+
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)
549549
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
550550

551-
case objabi.KindInt,
552-
objabi.KindInt8,
553-
objabi.KindInt16,
554-
objabi.KindInt32,
555-
objabi.KindInt64:
551+
case abi.Int,
552+
abi.Int8,
553+
abi.Int16,
554+
abi.Int32,
555+
abi.Int64:
556556
die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name)
557557
newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_signed, 0)
558558
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
559559

560-
case objabi.KindUint,
561-
objabi.KindUint8,
562-
objabi.KindUint16,
563-
objabi.KindUint32,
564-
objabi.KindUint64,
565-
objabi.KindUintptr:
560+
case abi.Uint,
561+
abi.Uint8,
562+
abi.Uint16,
563+
abi.Uint32,
564+
abi.Uint64,
565+
abi.Uintptr:
566566
die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name)
567567
newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_unsigned, 0)
568568
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
569569

570-
case objabi.KindFloat32,
571-
objabi.KindFloat64:
570+
case abi.Float32,
571+
abi.Float64:
572572
die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name)
573573
newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_float, 0)
574574
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
575575

576-
case objabi.KindComplex64,
577-
objabi.KindComplex128:
576+
case abi.Complex64,
577+
abi.Complex128:
578578
die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name)
579579
newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_complex_float, 0)
580580
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
581581

582-
case objabi.KindArray:
582+
case abi.Array:
583583
die = d.newdie(&dwtypes, dwarf.DW_ABRV_ARRAYTYPE, name)
584584
typedefdie = d.dotypedef(&dwtypes, name, die)
585585
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
@@ -592,15 +592,15 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
592592

593593
d.newrefattr(fld, dwarf.DW_AT_type, d.uintptrInfoSym)
594594

595-
case objabi.KindChan:
595+
case abi.Chan:
596596
die = d.newdie(&dwtypes, dwarf.DW_ABRV_CHANTYPE, name)
597597
s := decodetypeChanElem(d.ldr, d.arch, gotype)
598598
d.newrefattr(die, dwarf.DW_AT_go_elem, d.defgotype(s))
599599
// Save elem type for synthesizechantypes. We could synthesize here
600600
// but that would change the order of DIEs we output.
601601
d.newrefattr(die, dwarf.DW_AT_type, s)
602602

603-
case objabi.KindFunc:
603+
case abi.Func:
604604
die = d.newdie(&dwtypes, dwarf.DW_ABRV_FUNCTYPE, name)
605605
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
606606
typedefdie = d.dotypedef(&dwtypes, name, die)
@@ -626,7 +626,7 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
626626
d.newrefattr(fld, dwarf.DW_AT_type, d.defptrto(d.defgotype(s)))
627627
}
628628

629-
case objabi.KindInterface:
629+
case abi.Interface:
630630
die = d.newdie(&dwtypes, dwarf.DW_ABRV_IFACETYPE, name)
631631
typedefdie = d.dotypedef(&dwtypes, name, die)
632632
data := d.ldr.Data(gotype)
@@ -639,7 +639,7 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
639639
}
640640
d.newrefattr(die, dwarf.DW_AT_type, d.defgotype(s))
641641

642-
case objabi.KindMap:
642+
case abi.Map:
643643
die = d.newdie(&dwtypes, dwarf.DW_ABRV_MAPTYPE, name)
644644
s := decodetypeMapKey(d.ldr, d.arch, gotype)
645645
d.newrefattr(die, dwarf.DW_AT_go_key, d.defgotype(s))
@@ -649,25 +649,25 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
649649
// but that would change the order of the DIEs.
650650
d.newrefattr(die, dwarf.DW_AT_type, gotype)
651651

652-
case objabi.KindPtr:
652+
case abi.Pointer:
653653
die = d.newdie(&dwtypes, dwarf.DW_ABRV_PTRTYPE, name)
654654
typedefdie = d.dotypedef(&dwtypes, name, die)
655655
s := decodetypePtrElem(d.ldr, d.arch, gotype)
656656
d.newrefattr(die, dwarf.DW_AT_type, d.defgotype(s))
657657

658-
case objabi.KindSlice:
658+
case abi.Slice:
659659
die = d.newdie(&dwtypes, dwarf.DW_ABRV_SLICETYPE, name)
660660
typedefdie = d.dotypedef(&dwtypes, name, die)
661661
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
662662
s := decodetypeArrayElem(d.ldr, d.arch, gotype)
663663
elem := d.defgotype(s)
664664
d.newrefattr(die, dwarf.DW_AT_go_elem, elem)
665665

666-
case objabi.KindString:
666+
case abi.String:
667667
die = d.newdie(&dwtypes, dwarf.DW_ABRV_STRINGTYPE, name)
668668
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
669669

670-
case objabi.KindStruct:
670+
case abi.Struct:
671671
die = d.newdie(&dwtypes, dwarf.DW_ABRV_STRUCTTYPE, name)
672672
typedefdie = d.dotypedef(&dwtypes, name, die)
673673
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
@@ -688,7 +688,7 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
688688
}
689689
}
690690

691-
case objabi.KindUnsafePointer:
691+
case abi.UnsafePointer:
692692
die = d.newdie(&dwtypes, dwarf.DW_ABRV_BARE_PTRTYPE, name)
693693

694694
default:
@@ -748,7 +748,7 @@ func (d *dwctxt) defptrto(dwtype loader.Sym) loader.Sym {
748748
// pointers of slices. Link to the ones we can find.
749749
gts := d.ldr.Lookup("type:"+ptrname, 0)
750750
if gts != 0 && d.ldr.AttrReachable(gts) {
751-
newattr(pdie, dwarf.DW_AT_go_kind, dwarf.DW_CLS_CONSTANT, int64(objabi.KindPtr), 0)
751+
newattr(pdie, dwarf.DW_AT_go_kind, dwarf.DW_CLS_CONSTANT, int64(abi.Pointer), 0)
752752
newattr(pdie, dwarf.DW_AT_go_runtime_type, dwarf.DW_CLS_GO_TYPEREF, 0, dwSym(gts))
753753
}
754754

@@ -1759,7 +1759,7 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
17591759
uintptrDie := d.mkBuiltinType(ctxt, dwarf.DW_ABRV_BASETYPE, "uintptr")
17601760
newattr(uintptrDie, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_unsigned, 0)
17611761
newattr(uintptrDie, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, int64(d.arch.PtrSize), 0)
1762-
newattr(uintptrDie, dwarf.DW_AT_go_kind, dwarf.DW_CLS_CONSTANT, objabi.KindUintptr, 0)
1762+
newattr(uintptrDie, dwarf.DW_AT_go_kind, dwarf.DW_CLS_CONSTANT, int64(abi.Uintptr), 0)
17631763
newattr(uintptrDie, dwarf.DW_AT_go_runtime_type, dwarf.DW_CLS_GO_TYPEREF, 0, dwSym(d.lookupOrDiag("type:uintptr")))
17641764

17651765
d.uintptrInfoSym = d.mustFind("uintptr")

src/internal/abi/type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Type struct {
2424
TFlag TFlag // extra type information flags
2525
Align_ uint8 // alignment of variable with this type
2626
FieldAlign_ uint8 // alignment of struct field with this type
27-
Kind_ uint8 // enumeration for C
27+
Kind_ Kind // enumeration for C
2828
// function for comparing objects of this type
2929
// (ptr to object A, ptr to object B) -> ==?
3030
Equal func(unsafe.Pointer, unsafe.Pointer) bool
@@ -38,7 +38,7 @@ type Type struct {
3838

3939
// A Kind represents the specific kind of type that a Type represents.
4040
// The zero Kind is not a valid kind.
41-
type Kind uint
41+
type Kind uint8
4242

4343
const (
4444
Invalid Kind = iota

0 commit comments

Comments
 (0)