aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorqiulaidongfeng <2645477756@qq.com>2024-04-02 13:08:24 +0000
committerGopher Robot <gobot@golang.org>2024-04-02 15:10:48 +0000
commitdaaf1f222063174eb7f0938eee38f7f9f364263c (patch)
tree4187c39caf622b61276555ab72ad00f1145ad280 /src/runtime
parente3ec1ca17e339e21ca50fbdb375b4294783bc385 (diff)
downloadgo-daaf1f222063174eb7f0938eee38f7f9f364263c.tar.xz
all: use kind* of abi
For #59670 Change-Id: Id66e102f13e529dd041b68ce869026a56f0a1b9b GitHub-Last-Rev: 43aa9376f72bc02a9d86518cdc99494a6b2f8573 GitHub-Pull-Request: golang/go#65564 Reviewed-on: https://go-review.googlesource.com/c/go/+/562298 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/alg.go28
-rw-r--r--src/runtime/arena.go23
-rw-r--r--src/runtime/cgocall.go43
-rw-r--r--src/runtime/cgocheck.go11
-rw-r--r--src/runtime/debuglog.go5
-rw-r--r--src/runtime/error.go39
-rw-r--r--src/runtime/export_debug_test.go4
-rw-r--r--src/runtime/export_test.go2
-rw-r--r--src/runtime/heapdump.go2
-rw-r--r--src/runtime/mbitmap.go3
-rw-r--r--src/runtime/mbitmap_allocheaders.go22
-rw-r--r--src/runtime/mbitmap_noallocheaders.go6
-rw-r--r--src/runtime/mfinal.go14
-rw-r--r--src/runtime/pinner.go3
-rw-r--r--src/runtime/plugin.go7
-rw-r--r--src/runtime/race.go8
-rw-r--r--src/runtime/stkframe.go2
-rw-r--r--src/runtime/syscall_windows.go16
-rw-r--r--src/runtime/type.go30
-rw-r--r--src/runtime/typekind.go35
20 files changed, 142 insertions, 161 deletions
diff --git a/src/runtime/alg.go b/src/runtime/alg.go
index 93b14accb4..f5125d414f 100644
--- a/src/runtime/alg.go
+++ b/src/runtime/alg.go
@@ -154,30 +154,30 @@ func typehash(t *_type, p unsafe.Pointer, h uintptr) uintptr {
return memhash(p, h, t.Size_)
}
}
- switch t.Kind_ & kindMask {
- case kindFloat32:
+ switch t.Kind_ & abi.KindMask {
+ case abi.Float32:
return f32hash(p, h)
- case kindFloat64:
+ case abi.Float64:
return f64hash(p, h)
- case kindComplex64:
+ case abi.Complex64:
return c64hash(p, h)
- case kindComplex128:
+ case abi.Complex128:
return c128hash(p, h)
- case kindString:
+ case abi.String:
return strhash(p, h)
- case kindInterface:
+ case abi.Interface:
i := (*interfacetype)(unsafe.Pointer(t))
if len(i.Methods) == 0 {
return nilinterhash(p, h)
}
return interhash(p, h)
- case kindArray:
+ case abi.Array:
a := (*arraytype)(unsafe.Pointer(t))
for i := uintptr(0); i < a.Len; i++ {
h = typehash(a.Elem, add(p, i*a.Elem.Size_), h)
}
return h
- case kindStruct:
+ case abi.Struct:
s := (*structtype)(unsafe.Pointer(t))
for _, f := range s.Fields {
if f.Name.IsBlank() {
@@ -204,10 +204,10 @@ func mapKeyError2(t *_type, p unsafe.Pointer) error {
if t.TFlag&abi.TFlagRegularMemory != 0 {
return nil
}
- switch t.Kind_ & kindMask {
- case kindFloat32, kindFloat64, kindComplex64, kindComplex128, kindString:
+ switch t.Kind_ & abi.KindMask {
+ case abi.Float32, abi.Float64, abi.Complex64, abi.Complex128, abi.String:
return nil
- case kindInterface:
+ case abi.Interface:
i := (*interfacetype)(unsafe.Pointer(t))
var t *_type
var pdata *unsafe.Pointer
@@ -236,7 +236,7 @@ func mapKeyError2(t *_type, p unsafe.Pointer) error {
} else {
return mapKeyError2(t, *pdata)
}
- case kindArray:
+ case abi.Array:
a := (*arraytype)(unsafe.Pointer(t))
for i := uintptr(0); i < a.Len; i++ {
if err := mapKeyError2(a.Elem, add(p, i*a.Elem.Size_)); err != nil {
@@ -244,7 +244,7 @@ func mapKeyError2(t *_type, p unsafe.Pointer) error {
}
}
return nil
- case kindStruct:
+ case abi.Struct:
s := (*structtype)(unsafe.Pointer(t))
for _, f := range s.Fields {
if f.Name.IsBlank() {
diff --git a/src/runtime/arena.go b/src/runtime/arena.go
index 5c3350aabf..de3022e08a 100644
--- a/src/runtime/arena.go
+++ b/src/runtime/arena.go
@@ -83,6 +83,7 @@
package runtime
import (
+ "internal/abi"
"internal/goarch"
"internal/goexperiment"
"internal/runtime/atomic"
@@ -110,7 +111,7 @@ func arena_newArena() unsafe.Pointer {
//go:linkname arena_arena_New arena.runtime_arena_arena_New
func arena_arena_New(arena unsafe.Pointer, typ any) any {
t := (*_type)(efaceOf(&typ).data)
- if t.Kind_&kindMask != kindPtr {
+ if t.Kind_&abi.KindMask != abi.Pointer {
throw("arena_New: non-pointer type")
}
te := (*ptrtype)(unsafe.Pointer(t)).Elem
@@ -144,12 +145,12 @@ func arena_heapify(s any) any {
var v unsafe.Pointer
e := efaceOf(&s)
t := e._type
- switch t.Kind_ & kindMask {
- case kindString:
+ switch t.Kind_ & abi.KindMask {
+ case abi.String:
v = stringStructOf((*string)(e.data)).str
- case kindSlice:
+ case abi.Slice:
v = (*slice)(e.data).array
- case kindPtr:
+ case abi.Pointer:
v = e.data
default:
panic("arena: Clone only supports pointers, slices, and strings")
@@ -161,13 +162,13 @@ func arena_heapify(s any) any {
}
// Heap-allocate storage for a copy.
var x any
- switch t.Kind_ & kindMask {
- case kindString:
+ switch t.Kind_ & abi.KindMask {
+ case abi.String:
s1 := s.(string)
s2, b := rawstring(len(s1))
copy(b, s1)
x = s2
- case kindSlice:
+ case abi.Slice:
len := (*slice)(e.data).len
et := (*slicetype)(unsafe.Pointer(t)).Elem
sl := new(slice)
@@ -175,7 +176,7 @@ func arena_heapify(s any) any {
xe := efaceOf(&x)
xe._type = t
xe.data = unsafe.Pointer(sl)
- case kindPtr:
+ case abi.Pointer:
et := (*ptrtype)(unsafe.Pointer(t)).Elem
e2 := newobject(et)
typedmemmove(et, e2, e.data)
@@ -295,11 +296,11 @@ func (a *userArena) slice(sl any, cap int) {
}
i := efaceOf(&sl)
typ := i._type
- if typ.Kind_&kindMask != kindPtr {
+ if typ.Kind_&abi.KindMask != abi.Pointer {
panic("slice result of non-ptr type")
}
typ = (*ptrtype)(unsafe.Pointer(typ)).Elem
- if typ.Kind_&kindMask != kindSlice {
+ if typ.Kind_&abi.KindMask != abi.Slice {
panic("slice of non-ptr-to-slice type")
}
typ = (*slicetype)(unsafe.Pointer(typ)).Elem
diff --git a/src/runtime/cgocall.go b/src/runtime/cgocall.go
index e81852f607..a913c0a3a1 100644
--- a/src/runtime/cgocall.go
+++ b/src/runtime/cgocall.go
@@ -85,6 +85,7 @@
package runtime
import (
+ "internal/abi"
"internal/goarch"
"internal/goexperiment"
"runtime/internal/sys"
@@ -501,29 +502,29 @@ func cgoCheckPointer(ptr any, arg any) {
t := ep._type
top := true
- if arg != nil && (t.Kind_&kindMask == kindPtr || t.Kind_&kindMask == kindUnsafePointer) {
+ if arg != nil && (t.Kind_&abi.KindMask == abi.Pointer || t.Kind_&abi.KindMask == abi.UnsafePointer) {
p := ep.data
- if t.Kind_&kindDirectIface == 0 {
+ if t.Kind_&abi.KindDirectIface == 0 {
p = *(*unsafe.Pointer)(p)
}
if p == nil || !cgoIsGoPointer(p) {
return
}
aep := efaceOf(&arg)
- switch aep._type.Kind_ & kindMask {
- case kindBool:
- if t.Kind_&kindMask == kindUnsafePointer {
+ switch aep._type.Kind_ & abi.KindMask {
+ case abi.Bool:
+ if t.Kind_&abi.KindMask == abi.UnsafePointer {
// We don't know the type of the element.
break
}
pt := (*ptrtype)(unsafe.Pointer(t))
cgoCheckArg(pt.Elem, p, true, false, cgoCheckPointerFail)
return
- case kindSlice:
+ case abi.Slice:
// Check the slice rather than the pointer.
ep = aep
t = ep._type
- case kindArray:
+ case abi.Array:
// Check the array rather than the pointer.
// Pass top as false since we have a pointer
// to the array.
@@ -535,7 +536,7 @@ func cgoCheckPointer(ptr any, arg any) {
}
}
- cgoCheckArg(t, ep.data, t.Kind_&kindDirectIface == 0, top, cgoCheckPointerFail)
+ cgoCheckArg(t, ep.data, t.Kind_&abi.KindDirectIface == 0, top, cgoCheckPointerFail)
}
const cgoCheckPointerFail = "cgo argument has Go pointer to unpinned Go pointer"
@@ -552,28 +553,28 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
return
}
- switch t.Kind_ & kindMask {
+ switch t.Kind_ & abi.KindMask {
default:
throw("can't happen")
- case kindArray:
+ case abi.Array:
at := (*arraytype)(unsafe.Pointer(t))
if !indir {
if at.Len != 1 {
throw("can't happen")
}
- cgoCheckArg(at.Elem, p, at.Elem.Kind_&kindDirectIface == 0, top, msg)
+ cgoCheckArg(at.Elem, p, at.Elem.Kind_&abi.KindDirectIface == 0, top, msg)
return
}
for i := uintptr(0); i < at.Len; i++ {
cgoCheckArg(at.Elem, p, true, top, msg)
p = add(p, at.Elem.Size_)
}
- case kindChan, kindMap:
+ case abi.Chan, abi.Map:
// These types contain internal pointers that will
// always be allocated in the Go heap. It's never OK
// to pass them to C.
panic(errorString(msg))
- case kindFunc:
+ case abi.Func:
if indir {
p = *(*unsafe.Pointer)(p)
}
@@ -581,7 +582,7 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
return
}
panic(errorString(msg))
- case kindInterface:
+ case abi.Interface:
it := *(**_type)(p)
if it == nil {
return
@@ -599,8 +600,8 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
if !top && !isPinned(p) {
panic(errorString(msg))
}
- cgoCheckArg(it, p, it.Kind_&kindDirectIface == 0, false, msg)
- case kindSlice:
+ cgoCheckArg(it, p, it.Kind_&abi.KindDirectIface == 0, false, msg)
+ case abi.Slice:
st := (*slicetype)(unsafe.Pointer(t))
s := (*slice)(p)
p = s.array
@@ -617,7 +618,7 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
cgoCheckArg(st.Elem, p, true, false, msg)
p = add(p, st.Elem.Size_)
}
- case kindString:
+ case abi.String:
ss := (*stringStruct)(p)
if !cgoIsGoPointer(ss.str) {
return
@@ -625,13 +626,13 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
if !top && !isPinned(ss.str) {
panic(errorString(msg))
}
- case kindStruct:
+ case abi.Struct:
st := (*structtype)(unsafe.Pointer(t))
if !indir {
if len(st.Fields) != 1 {
throw("can't happen")
}
- cgoCheckArg(st.Fields[0].Typ, p, st.Fields[0].Typ.Kind_&kindDirectIface == 0, top, msg)
+ cgoCheckArg(st.Fields[0].Typ, p, st.Fields[0].Typ.Kind_&abi.KindDirectIface == 0, top, msg)
return
}
for _, f := range st.Fields {
@@ -640,7 +641,7 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
}
cgoCheckArg(f.Typ, add(p, f.Offset), true, top, msg)
}
- case kindPtr, kindUnsafePointer:
+ case abi.Pointer, abi.UnsafePointer:
if indir {
p = *(*unsafe.Pointer)(p)
if p == nil {
@@ -754,5 +755,5 @@ func cgoCheckResult(val any) {
ep := efaceOf(&val)
t := ep._type
- cgoCheckArg(t, ep.data, t.Kind_&kindDirectIface == 0, false, cgoResultFail)
+ cgoCheckArg(t, ep.data, t.Kind_&abi.KindDirectIface == 0, false, cgoResultFail)
}
diff --git a/src/runtime/cgocheck.go b/src/runtime/cgocheck.go
index fd87723dfc..fbf4edf7cc 100644
--- a/src/runtime/cgocheck.go
+++ b/src/runtime/cgocheck.go
@@ -8,6 +8,7 @@
package runtime
import (
+ "internal/abi"
"internal/goarch"
"internal/goexperiment"
"unsafe"
@@ -142,7 +143,7 @@ func cgoCheckTypedBlock(typ *_type, src unsafe.Pointer, off, size uintptr) {
size = ptrdataSize
}
- if typ.Kind_&kindGCProg == 0 {
+ if typ.Kind_&abi.KindGCProg == 0 {
cgoCheckBits(src, typ.GCData, off, size)
return
}
@@ -259,14 +260,14 @@ func cgoCheckUsingType(typ *_type, src unsafe.Pointer, off, size uintptr) {
size = ptrdataSize
}
- if typ.Kind_&kindGCProg == 0 {
+ if typ.Kind_&abi.KindGCProg == 0 {
cgoCheckBits(src, typ.GCData, off, size)
return
}
- switch typ.Kind_ & kindMask {
+ switch typ.Kind_ & abi.KindMask {
default:
throw("can't happen")
- case kindArray:
+ case abi.Array:
at := (*arraytype)(unsafe.Pointer(typ))
for i := uintptr(0); i < at.Len; i++ {
if off < at.Elem.Size_ {
@@ -284,7 +285,7 @@ func cgoCheckUsingType(typ *_type, src unsafe.Pointer, off, size uintptr) {
}
size -= checked
}
- case kindStruct:
+ case abi.Struct:
st := (*structtype)(unsafe.Pointer(typ))
for _, f := range st.Fields {
if off < f.Typ.Size_ {
diff --git a/src/runtime/debuglog.go b/src/runtime/debuglog.go
index 545fde2b24..695cd204f5 100644
--- a/src/runtime/debuglog.go
+++ b/src/runtime/debuglog.go
@@ -16,6 +16,7 @@
package runtime
import (
+ "internal/abi"
"internal/runtime/atomic"
"runtime/internal/sys"
"unsafe"
@@ -277,8 +278,8 @@ func (l *dlogger) p(x any) *dlogger {
l.w.uvarint(0)
} else {
v := efaceOf(&x)
- switch v._type.Kind_ & kindMask {
- case kindChan, kindFunc, kindMap, kindPtr, kindUnsafePointer:
+ switch v._type.Kind_ & abi.KindMask {
+ case abi.Chan, abi.Func, abi.Map, abi.Pointer, abi.UnsafePointer:
l.w.uvarint(uint64(uintptr(v.data)))
default:
throw("not a pointer type")
diff --git a/src/runtime/error.go b/src/runtime/error.go
index b507f25e18..fe95f31005 100644
--- a/src/runtime/error.go
+++ b/src/runtime/error.go
@@ -4,7 +4,10 @@
package runtime
-import "internal/bytealg"
+import (
+ "internal/abi"
+ "internal/bytealg"
+)
// The Error interface identifies a run time error.
type Error interface {
@@ -259,39 +262,39 @@ func printanycustomtype(i any) {
typestring := toRType(eface._type).string()
switch eface._type.Kind_ {
- case kindString:
+ case abi.String:
print(typestring, `("`, *(*string)(eface.data), `")`)
- case kindBool:
+ case abi.Bool:
print(typestring, "(", *(*bool)(eface.data), ")")
- case kindInt:
+ case abi.Int:
print(typestring, "(", *(*int)(eface.data), ")")
- case kindInt8:
+ case abi.Int8:
print(typestring, "(", *(*int8)(eface.data), ")")
- case kindInt16:
+ case abi.Int16:
print(typestring, "(", *(*int16)(eface.data), ")")
- case kindInt32:
+ case abi.Int32:
print(typestring, "(", *(*int32)(eface.data), ")")
- case kindInt64:
+ case abi.Int64:
print(typestring, "(", *(*int64)(eface.data), ")")
- case kindUint:
+ case abi.Uint:
print(typestring, "(", *(*uint)(eface.data), ")")
- case kindUint8:
+ case abi.Uint8:
print(typestring, "(", *(*uint8)(eface.data), ")")
- case kindUint16:
+ case abi.Uint16:
print(typestring, "(", *(*uint16)(eface.data), ")")
- case kindUint32:
+ case abi.Uint32:
print(typestring, "(", *(*uint32)(eface.data), ")")
- case kindUint64:
+ case abi.Uint64:
print(typestring, "(", *(*uint64)(eface.data), ")")
- case kindUintptr:
+ case abi.Uintptr:
print(typestring, "(", *(*uintptr)(eface.data), ")")
- case kindFloat32:
+ case abi.Float32:
print(typestring, "(", *(*float32)(eface.data), ")")
- case kindFloat64:
+ case abi.Float64:
print(typestring, "(", *(*float64)(eface.data), ")")
- case kindComplex64:
+ case abi.Complex64:
print(typestring, *(*complex64)(eface.data))
- case kindComplex128:
+ case abi.Complex128:
print(typestring, *(*complex128)(eface.data))
default:
print("(", typestring, ") ", eface.data)
diff --git a/src/runtime/export_debug_test.go b/src/runtime/export_debug_test.go
index 7ee73ef07c..810a5a6435 100644
--- a/src/runtime/export_debug_test.go
+++ b/src/runtime/export_debug_test.go
@@ -32,13 +32,13 @@ func InjectDebugCall(gp *g, fn any, regArgs *abi.RegArgs, stackArgs any, tkill f
}
f := efaceOf(&fn)
- if f._type == nil || f._type.Kind_&kindMask != kindFunc {
+ if f._type == nil || f._type.Kind_&abi.KindMask != abi.Func {
return nil, plainError("fn must be a function")
}
fv := (*funcval)(f.data)
a := efaceOf(&stackArgs)
- if a._type != nil && a._type.Kind_&kindMask != kindPtr {
+ if a._type != nil && a._type.Kind_&abi.KindMask != abi.Pointer {
return nil, plainError("args must be a pointer or nil")
}
argp := a.data
diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go
index e71f4766c6..4eb187c007 100644
--- a/src/runtime/export_test.go
+++ b/src/runtime/export_test.go
@@ -1909,7 +1909,7 @@ func NewUserArena() *UserArena {
func (a *UserArena) New(out *any) {
i := efaceOf(out)
typ := i._type
- if typ.Kind_&kindMask != kindPtr {
+ if typ.Kind_&abi.KindMask != abi.Pointer {
panic("new result of non-ptr type")
}
typ = (*ptrtype)(unsafe.Pointer(typ)).Elem
diff --git a/src/runtime/heapdump.go b/src/runtime/heapdump.go
index c1c71fad48..1fbb124f2e 100644
--- a/src/runtime/heapdump.go
+++ b/src/runtime/heapdump.go
@@ -206,7 +206,7 @@ func dumptype(t *_type) {
dwritebyte('.')
dwrite(unsafe.Pointer(unsafe.StringData(name)), uintptr(len(name)))
}
- dumpbool(t.Kind_&kindDirectIface == 0 || t.Pointers())
+ dumpbool(t.Kind_&abi.KindDirectIface == 0 || t.PtrBytes != 0)
}
// dump an object.
diff --git a/src/runtime/mbitmap.go b/src/runtime/mbitmap.go
index 61530bbe7f..0a2f53d0ae 100644
--- a/src/runtime/mbitmap.go
+++ b/src/runtime/mbitmap.go
@@ -5,6 +5,7 @@
package runtime
import (
+ "internal/abi"
"internal/goarch"
"internal/runtime/atomic"
"runtime/internal/sys"
@@ -413,7 +414,7 @@ func typeBitsBulkBarrier(typ *_type, dst, src, size uintptr) {
println("runtime: typeBitsBulkBarrier with type ", toRType(typ).string(), " of size ", typ.Size_, " but memory size", size)
throw("runtime: invalid typeBitsBulkBarrier")
}
- if typ.Kind_&kindGCProg != 0 {
+ if typ.Kind_&abi.KindGCProg != 0 {
println("runtime: typeBitsBulkBarrier with type ", toRType(typ).string(), " with GC prog")
throw("runtime: invalid typeBitsBulkBarrier")
}
diff --git a/src/runtime/mbitmap_allocheaders.go b/src/runtime/mbitmap_allocheaders.go
index 5f1f978189..2640521210 100644
--- a/src/runtime/mbitmap_allocheaders.go
+++ b/src/runtime/mbitmap_allocheaders.go
@@ -215,7 +215,7 @@ func (span *mspan) typePointersOfUnchecked(addr uintptr) typePointers {
//go:nosplit
func (span *mspan) typePointersOfType(typ *abi.Type, addr uintptr) typePointers {
const doubleCheck = false
- if doubleCheck && (typ == nil || typ.Kind_&kindGCProg != 0) {
+ if doubleCheck && (typ == nil || typ.Kind_&abi.KindGCProg != 0) {
throw("bad type passed to typePointersOfType")
}
if span.spanclass.noscan() {
@@ -459,7 +459,7 @@ func bulkBarrierPreWrite(dst, src, size uintptr, typ *abi.Type) {
}
var tp typePointers
- if typ != nil && typ.Kind_&kindGCProg == 0 {
+ if typ != nil && typ.Kind_&abi.KindGCProg == 0 {
tp = s.typePointersOfType(typ, dst)
} else {
tp = s.typePointersOf(dst, size)
@@ -520,7 +520,7 @@ func bulkBarrierPreWriteSrcOnly(dst, src, size uintptr, typ *abi.Type) {
}
var tp typePointers
- if typ != nil && typ.Kind_&kindGCProg == 0 {
+ if typ != nil && typ.Kind_&abi.KindGCProg == 0 {
tp = s.typePointersOfType(typ, dst)
} else {
tp = s.typePointersOf(dst, size)
@@ -860,7 +860,7 @@ func heapSetType(x, dataSize uintptr, typ *_type, header **_type, span *mspan) (
// Handle the case where we have no malloc header.
scanSize = span.writeHeapBitsSmall(x, dataSize, typ)
} else {
- if typ.Kind_&kindGCProg != 0 {
+ if typ.Kind_&abi.KindGCProg != 0 {
// Allocate space to unroll the gcprog. This space will consist of
// a dummy _type value and the unrolled gcprog. The dummy _type will
// refer to the bitmap, and the mspan will refer to the dummy _type.
@@ -964,7 +964,7 @@ func doubleCheckHeapPointers(x, dataSize uintptr, typ *_type, header **_type, sp
}
println("runtime: extra pointer:", hex(addr))
}
- print("runtime: hasHeader=", header != nil, " typ.Size_=", typ.Size_, " hasGCProg=", typ.Kind_&kindGCProg != 0, "\n")
+ print("runtime: hasHeader=", header != nil, " typ.Size_=", typ.Size_, " hasGCProg=", typ.Kind_&abi.KindGCProg != 0, "\n")
print("runtime: x=", hex(x), " dataSize=", dataSize, " elemsize=", span.elemsize, "\n")
print("runtime: typ=", unsafe.Pointer(typ), " typ.PtrBytes=", typ.PtrBytes, "\n")
print("runtime: limit=", hex(x+span.elemsize), "\n")
@@ -1062,10 +1062,10 @@ func doubleCheckHeapPointersInterior(x, interior, size, dataSize uintptr, typ *_
//go:nosplit
func doubleCheckTypePointersOfType(s *mspan, typ *_type, addr, size uintptr) {
- if typ == nil || typ.Kind_&kindGCProg != 0 {
+ if typ == nil || typ.Kind_&abi.KindGCProg != 0 {
return
}
- if typ.Kind_&kindMask == kindInterface {
+ if typ.Kind_&abi.KindMask == abi.Interface {
// Interfaces are unfortunately inconsistently handled
// when it comes to the type pointer, so it's easy to
// produce a lot of false positives here.
@@ -1130,7 +1130,7 @@ func getgcmask(ep any) (mask []byte) {
t := e._type
var et *_type
- if t.Kind_&kindMask != kindPtr {
+ if t.Kind_&abi.KindMask != abi.Pointer {
throw("bad argument to getgcmask: expected type to be a pointer to the value type whose mask is being queried")
}
et = (*ptrtype)(unsafe.Pointer(t)).Elem
@@ -1200,7 +1200,7 @@ func getgcmask(ep any) (mask []byte) {
maskFromHeap = maskFromHeap[:len(maskFromHeap)-1]
}
- if et.Kind_&kindGCProg == 0 {
+ if et.Kind_&abi.KindGCProg == 0 {
// Unroll again, but this time from the type information.
maskFromType := make([]byte, (limit-base)/goarch.PtrSize)
tp = s.typePointersOfType(et, base)
@@ -1298,7 +1298,7 @@ func userArenaHeapBitsSetType(typ *_type, ptr unsafe.Pointer, s *mspan) {
p := typ.GCData // start of 1-bit pointer mask (or GC program)
var gcProgBits uintptr
- if typ.Kind_&kindGCProg != 0 {
+ if typ.Kind_&abi.KindGCProg != 0 {
// Expand gc program, using the object itself for storage.
gcProgBits = runGCProg(addb(p, 4), (*byte)(ptr))
p = (*byte)(ptr)
@@ -1327,7 +1327,7 @@ func userArenaHeapBitsSetType(typ *_type, ptr unsafe.Pointer, s *mspan) {
h = h.pad(s, typ.Size_-typ.PtrBytes)
h.flush(s, uintptr(ptr), typ.Size_)
- if typ.Kind_&kindGCProg != 0 {
+ if typ.Kind_&abi.KindGCProg != 0 {
// Zero out temporary ptrmask buffer inside object.
memclrNoHeapPointers(ptr, (gcProgBits+7)/8)
}
diff --git a/src/runtime/mbitmap_noallocheaders.go b/src/runtime/mbitmap_noallocheaders.go
index 383993aa1e..eeaeaafaac 100644
--- a/src/runtime/mbitmap_noallocheaders.go
+++ b/src/runtime/mbitmap_noallocheaders.go
@@ -552,7 +552,7 @@ func heapBitsSetType(x, size, dataSize uintptr, typ *_type) {
h := writeHeapBitsForAddr(x)
// Handle GC program.
- if typ.Kind_&kindGCProg != 0 {
+ if typ.Kind_&abi.KindGCProg != 0 {
// Expand the gc program into the storage we're going to use for the actual object.
obj := (*uint8)(unsafe.Pointer(x))
n := runGCProg(addb(typ.GCData, 4), obj)
@@ -829,7 +829,7 @@ func userArenaHeapBitsSetType(typ *_type, ptr unsafe.Pointer, s *mspan) {
p := typ.GCData // start of 1-bit pointer mask (or GC program)
var gcProgBits uintptr
- if typ.Kind_&kindGCProg != 0 {
+ if typ.Kind_&abi.KindGCProg != 0 {
// Expand gc program, using the object itself for storage.
gcProgBits = runGCProg(addb(p, 4), (*byte)(ptr))
p = (*byte)(ptr)
@@ -852,7 +852,7 @@ func userArenaHeapBitsSetType(typ *_type, ptr unsafe.Pointer, s *mspan) {
h = h.pad(typ.Size_ - typ.PtrBytes)
h.flush(uintptr(ptr), typ.Size_)
- if typ.Kind_&kindGCProg != 0 {
+ if typ.Kind_&abi.KindGCProg != 0 {
// Zero out temporary ptrmask buffer inside object.
memclrNoHeapPointers(ptr, (gcProgBits+7)/8)
}
diff --git a/src/runtime/mfinal.go b/src/runtime/mfinal.go
index 7820f50e51..1feab27717 100644
--- a/src/runtime/mfinal.go
+++ b/src/runtime/mfinal.go
@@ -235,11 +235,11 @@ func runfinq() {
// confusing the write barrier.
*(*[2]uintptr)(frame) = [2]uintptr{}
}
- switch f.fint.Kind_ & kindMask {
- case kindPtr:
+ switch f.fint.Kind_ & abi.KindMask {
+ case abi.Pointer:
// direct use of pointer
*(*unsafe.Pointer)(r) = f.arg
- case kindInterface:
+ case abi.Interface:
ityp := (*interfacetype)(unsafe.Pointer(f.fint))
// set up with empty interface
(*eface)(r)._type = &f.ot.Type
@@ -418,7 +418,7 @@ func SetFinalizer(obj any, finalizer any) {
if etyp == nil {
throw("runtime.SetFinalizer: first argument is nil")
}
- if etyp.Kind_&kindMask != kindPtr {
+ if etyp.Kind_&abi.KindMask != abi.Pointer {
throw("runtime.SetFinalizer: first argument is " + toRType(etyp).string() + ", not pointer")
}
ot := (*ptrtype)(unsafe.Pointer(etyp))
@@ -464,7 +464,7 @@ func SetFinalizer(obj any, finalizer any) {
return
}
- if ftyp.Kind_&kindMask != kindFunc {
+ if ftyp.Kind_&abi.KindMask != abi.Func {
throw("runtime.SetFinalizer: second argument is " + toRType(ftyp).string() + ", not a function")
}
ft := (*functype)(unsafe.Pointer(ftyp))
@@ -479,13 +479,13 @@ func SetFinalizer(obj any, finalizer any) {
case fint == etyp:
// ok - same type
goto okarg
- case fint.Kind_&kindMask == kindPtr:
+ case fint.Kind_&abi.KindMask == abi.Pointer:
if (fint.Uncommon() == nil || etyp.Uncommon() == nil) && (*ptrtype)(unsafe.Pointer(fint)).Elem == ot.Elem {
// ok - not same type, but both pointers,
// one or the other is unnamed, and same element type, so assignable.
goto okarg
}
- case fint.Kind_&kindMask == kindInterface:
+ case fint.Kind_&abi.KindMask == abi.Interface:
ityp := (*interfacetype)(unsafe.Pointer(fint))
if len(ityp.Methods) == 0 {
// ok - satisfies empty interface
diff --git a/src/runtime/pinner.go b/src/runtime/pinner.go
index f9efe237c1..208fc983ee 100644
--- a/src/runtime/pinner.go
+++ b/src/runtime/pinner.go
@@ -5,6 +5,7 @@
package runtime
import (
+ "internal/abi"
"internal/runtime/atomic"
"unsafe"
)
@@ -107,7 +108,7 @@ func pinnerGetPtr(i *any) unsafe.Pointer {
if etyp == nil {
panic(errorString("runtime.Pinner: argument is nil"))
}
- if kind := etyp.Kind_ & kindMask; kind != kindPtr && kind != kindUnsafePointer {
+ if kind := etyp.Kind_ & abi.KindMask; kind != abi.Pointer && kind != abi.UnsafePointer {
panic(errorString("runtime.Pinner: argument is not a pointer: " + toRType(etyp).string()))
}
if inUserArenaChunk(uintptr(e.data)) {
diff --git a/src/runtime/plugin.go b/src/runtime/plugin.go
index 40dfefde17..4b6821b1fb 100644
--- a/src/runtime/plugin.go
+++ b/src/runtime/plugin.go
@@ -4,7 +4,10 @@
package runtime
-import "unsafe"
+import (
+ "internal/abi"
+ "unsafe"
+)
//go:linkname plugin_lastmoduleinit plugin.lastmoduleinit
func plugin_lastmoduleinit() (path string, syms map[string]any, initTasks []*initTask, errstr string) {
@@ -85,7 +88,7 @@ func plugin_lastmoduleinit() (path string, syms map[string]any, initTasks []*ini
(*valp)[0] = unsafe.Pointer(t)
name := symName.Name()
- if t.Kind_&kindMask == kindFunc {
+ if t.Kind_&abi.KindMask == abi.Func {
name = "." + name
}
syms[name] = val
diff --git a/src/runtime/race.go b/src/runtime/race.go
index ca4f051979..9acc0c6920 100644
--- a/src/runtime/race.go
+++ b/src/runtime/race.go
@@ -93,8 +93,8 @@ const raceenabled = true
// callerpc is a return PC of the function that calls this function,
// pc is start PC of the function that calls this function.
func raceReadObjectPC(t *_type, addr unsafe.Pointer, callerpc, pc uintptr) {
- kind := t.Kind_ & kindMask
- if kind == kindArray || kind == kindStruct {
+ kind := t.Kind_ & abi.KindMask
+ if kind == abi.Array || kind == abi.Struct {
// for composite objects we have to read every address
// because a write might happen to any subobject.
racereadrangepc(addr, t.Size_, callerpc, pc)
@@ -106,8 +106,8 @@ func raceReadObjectPC(t *_type, addr unsafe.Pointer, callerpc, pc uintptr) {
}
func raceWriteObjectPC(t *_type, addr unsafe.Pointer, callerpc, pc uintptr) {
- kind := t.Kind_ & kindMask
- if kind == kindArray || kind == kindStruct {
+ kind := t.Kind_ & abi.KindMask
+ if kind == abi.Array || kind == abi.Struct {
// for composite objects we have to write every address
// because a write might happen to any subobject.
racewriterangepc(addr, t.Size_, callerpc, pc)
diff --git a/src/runtime/stkframe.go b/src/runtime/stkframe.go
index becb729e59..42b6947751 100644
--- a/src/runtime/stkframe.go
+++ b/src/runtime/stkframe.go
@@ -264,7 +264,7 @@ var methodValueCallFrameObjs [1]stackObjectRecord // initialized in stackobjecti
func stkobjinit() {
var abiRegArgsEface any = abi.RegArgs{}
abiRegArgsType := efaceOf(&abiRegArgsEface)._type
- if abiRegArgsType.Kind_&kindGCProg != 0 {
+ if abiRegArgsType.Kind_&abi.KindGCProg != 0 {
throw("abiRegArgsType needs GC Prog, update methodValueCallFrameObjs")
}
// Set methodValueCallFrameObjs[0].gcdataoff so that
diff --git a/src/runtime/syscall_windows.go b/src/runtime/syscall_windows.go
index 09762aed51..f0e7661a1b 100644
--- a/src/runtime/syscall_windows.go
+++ b/src/runtime/syscall_windows.go
@@ -103,7 +103,7 @@ func (p *abiDesc) assignArg(t *_type) {
// registers and the stack.
panic("compileCallback: argument size is larger than uintptr")
}
- if k := t.Kind_ & kindMask; GOARCH != "386" && (k == kindFloat32 || k == kindFloat64) {
+ if k := t.Kind_ & abi.KindMask; GOARCH != "386" && (k == abi.Float32 || k == abi.Float64) {
// In fastcall, floating-point arguments in
// the first four positions are passed in
// floating-point registers, which we don't
@@ -174,21 +174,21 @@ func (p *abiDesc) assignArg(t *_type) {
//
// Returns whether the assignment succeeded.
func (p *abiDesc) tryRegAssignArg(t *_type, offset uintptr) bool {
- switch k := t.Kind_ & kindMask; k {
- case kindBool, kindInt, kindInt8, kindInt16, kindInt32, kindUint, kindUint8, kindUint16, kindUint32, kindUintptr, kindPtr, kindUnsafePointer:
+ switch k := t.Kind_ & abi.KindMask; k {
+ case abi.Bool, abi.Int, abi.Int8, abi.Int16, abi.Int32, abi.Uint, abi.Uint8, abi.Uint16, abi.Uint32, abi.Uintptr, abi.Pointer, abi.UnsafePointer:
// Assign a register for all these types.
return p.assignReg(t.Size_, offset)
- case kindInt64, kindUint64:
+ case abi.Int64, abi.Uint64:
// Only register-assign if the registers are big enough.
if goarch.PtrSize == 8 {
return p.assignReg(t.Size_, offset)
}
- case kindArray:
+ case abi.Array:
at := (*arraytype)(unsafe.Pointer(t))
if at.Len == 1 {
return p.tryRegAssignArg(at.Elem, offset) // TODO fix when runtime is fully commoned up w/ abi.Type
}
- case kindStruct:
+ case abi.Struct:
st := (*structtype)(unsafe.Pointer(t))
for i := range st.Fields {
f := &st.Fields[i]
@@ -269,7 +269,7 @@ func compileCallback(fn eface, cdecl bool) (code uintptr) {
cdecl = false
}
- if fn._type == nil || (fn._type.Kind_&kindMask) != kindFunc {
+ if fn._type == nil || (fn._type.Kind_&abi.KindMask) != abi.Func {
panic("compileCallback: expected function with one uintptr-sized result")
}
ft := (*functype)(unsafe.Pointer(fn._type))
@@ -290,7 +290,7 @@ func compileCallback(fn eface, cdecl bool) (code uintptr) {
if ft.OutSlice()[0].Size_ != goarch.PtrSize {
panic("compileCallback: expected function with one uintptr-sized result")
}
- if k := ft.OutSlice()[0].Kind_ & kindMask; k == kindFloat32 || k == kindFloat64 {
+ if k := ft.OutSlice()[0].Kind_ & abi.KindMask; k == abi.Float32 || k == abi.Float64 {
// In cdecl and stdcall, float results are returned in
// ST(0). In fastcall, they're returned in XMM0.
// Either way, it's not AX.
diff --git a/src/runtime/type.go b/src/runtime/type.go
index 1150a53208..a2975c4a99 100644
--- a/src/runtime/type.go
+++ b/src/runtime/type.go
@@ -61,11 +61,11 @@ func (t rtype) pkgpath() string {
if u := t.uncommon(); u != nil {
return t.nameOff(u.PkgPath).Name()
}
- switch t.Kind_ & kindMask {
- case kindStruct:
+ switch t.Kind_ & abi.KindMask {
+ case abi.Struct:
st := (*structtype)(unsafe.Pointer(t.Type))
return st.PkgPath.Name()
- case kindInterface:
+ case abi.Interface:
it := (*interfacetype)(unsafe.Pointer(t.Type))
return it.PkgPath.Name()
}
@@ -338,8 +338,8 @@ func typesEqual(t, v *_type, seen map[_typePair]struct{}) bool {
if t == v {
return true
}
- kind := t.Kind_ & kindMask
- if kind != v.Kind_&kindMask {
+ kind := t.Kind_ & abi.KindMask
+ if kind != v.Kind_&abi.KindMask {
return false
}
rt, rv := toRType(t), toRType(v)
@@ -358,21 +358,21 @@ func typesEqual(t, v *_type, seen map[_typePair]struct{}) bool {
return false
}
}
- if kindBool <= kind && kind <= kindComplex128 {
+ if abi.Bool <= kind && kind <= abi.Complex128 {
return true
}
switch kind {
- case kindString, kindUnsafePointer:
+ case abi.String, abi.UnsafePointer:
return true
- case kindArray:
+ case abi.Array:
at := (*arraytype)(unsafe.Pointer(t))
av := (*arraytype)(unsafe.Pointer(v))
return typesEqual(at.Elem, av.Elem, seen) && at.Len == av.Len
- case kindChan:
+ case abi.Chan:
ct := (*chantype)(unsafe.Pointer(t))
cv := (*chantype)(unsafe.Pointer(v))
return ct.Dir == cv.Dir && typesEqual(ct.Elem, cv.Elem, seen)
- case kindFunc:
+ case abi.Func:
ft := (*functype)(unsafe.Pointer(t))
fv := (*functype)(unsafe.Pointer(v))
if ft.OutCount != fv.OutCount || ft.InCount != fv.InCount {
@@ -391,7 +391,7 @@ func typesEqual(t, v *_type, seen map[_typePair]struct{}) bool {
}
}
return true
- case kindInterface:
+ case abi.Interface:
it := (*interfacetype)(unsafe.Pointer(t))
iv := (*interfacetype)(unsafe.Pointer(v))
if it.PkgPath.Name() != iv.PkgPath.Name() {
@@ -420,19 +420,19 @@ func typesEqual(t, v *_type, seen map[_typePair]struct{}) bool {
}
}
return true
- case kindMap:
+ case abi.Map:
mt := (*maptype)(unsafe.Pointer(t))
mv := (*maptype)(unsafe.Pointer(v))
return typesEqual(mt.Key, mv.Key, seen) && typesEqual(mt.Elem, mv.Elem, seen)
- case kindPtr:
+ case abi.Pointer:
pt := (*ptrtype)(unsafe.Pointer(t))
pv := (*ptrtype)(unsafe.Pointer(v))
return typesEqual(pt.Elem, pv.Elem, seen)
- case kindSlice:
+ case abi.Slice:
st := (*slicetype)(unsafe.Pointer(t))
sv := (*slicetype)(unsafe.Pointer(v))
return typesEqual(st.Elem, sv.Elem, seen)
- case kindStruct:
+ case abi.Struct:
st := (*structtype)(unsafe.Pointer(t))
sv := (*structtype)(unsafe.Pointer(v))
if len(st.Fields) != len(sv.Fields) {
diff --git a/src/runtime/typekind.go b/src/runtime/typekind.go
index bd2dec94c4..4920a7cf14 100644
--- a/src/runtime/typekind.go
+++ b/src/runtime/typekind.go
@@ -4,40 +4,9 @@
package runtime
-const (
- kindBool = 1 + iota
- kindInt
- kindInt8
- kindInt16
- kindInt32
- kindInt64
- kindUint
- kindUint8
- kindUint16
- kindUint32
- kindUint64
- kindUintptr
- kindFloat32
- kindFloat64
- kindComplex64
- kindComplex128
- kindArray
- kindChan
- kindFunc
- kindInterface
- kindMap
- kindPtr
- kindSlice
- kindString
- kindStruct
- kindUnsafePointer
-
- kindDirectIface = 1 << 5
- kindGCProg = 1 << 6
- kindMask = (1 << 5) - 1
-)
+import "internal/abi"
// isDirectIface reports whether t is stored directly in an interface value.
func isDirectIface(t *_type) bool {
- return t.Kind_&kindDirectIface != 0
+ return t.Kind_&abi.KindDirectIface != 0
}