diff options
| author | David Chase <drchase@google.com> | 2023-04-14 14:09:12 -0400 |
|---|---|---|
| committer | David Chase <drchase@google.com> | 2023-05-10 22:43:30 +0000 |
| commit | 639957eb661c0c99c000bfc2e79bc750b02abd1a (patch) | |
| tree | 017688d9c0eb9ec20baa56d24ad651b0b5de1f1e /src/runtime | |
| parent | a8515119474b621ae39ad8af9a2ad4c8a7732a6c (diff) | |
| download | go-639957eb661c0c99c000bfc2e79bc750b02abd1a.tar.xz | |
internal/reflectlite, runtime: move more constants and types into internal/abi
Change-Id: If5da1057ead34eb3e4c7f42bbe6ad3d350b97725
Reviewed-on: https://go-review.googlesource.com/c/go/+/484856
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/alg.go | 2 | ||||
| -rw-r--r-- | src/runtime/cgocall.go | 4 | ||||
| -rw-r--r-- | src/runtime/cgocheck.go | 2 | ||||
| -rw-r--r-- | src/runtime/syscall_windows.go | 2 | ||||
| -rw-r--r-- | src/runtime/type.go | 70 |
5 files changed, 14 insertions, 66 deletions
diff --git a/src/runtime/alg.go b/src/runtime/alg.go index 4619abf4f5..e40eb9b47b 100644 --- a/src/runtime/alg.go +++ b/src/runtime/alg.go @@ -174,7 +174,7 @@ func typehash(t *_type, p unsafe.Pointer, h uintptr) uintptr { case kindArray: a := (*arraytype)(unsafe.Pointer(t)) for i := uintptr(0); i < a.Len; i++ { - h = typehash((*_type)(a.Elem), add(p, i*a.Elem.Size_), h) + h = typehash(toType(a.Elem), add(p, i*a.Elem.Size_), h) } return h case kindStruct: diff --git a/src/runtime/cgocall.go b/src/runtime/cgocall.go index e92b7e4fed..e2e37284a2 100644 --- a/src/runtime/cgocall.go +++ b/src/runtime/cgocall.go @@ -466,11 +466,11 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) { if at.Len != 1 { throw("can't happen") } - cgoCheckArg((*_type)(at.Elem), p, at.Elem.Kind_&kindDirectIface == 0, top, msg) + cgoCheckArg(toType(at.Elem), p, at.Elem.Kind_&kindDirectIface == 0, top, msg) return } for i := uintptr(0); i < at.Len; i++ { - cgoCheckArg((*_type)(at.Elem), p, true, top, msg) + cgoCheckArg(toType(at.Elem), p, true, top, msg) p = add(p, at.Elem.Size_) } case kindChan, kindMap: diff --git a/src/runtime/cgocheck.go b/src/runtime/cgocheck.go index cc11ef0469..1acf0f9233 100644 --- a/src/runtime/cgocheck.go +++ b/src/runtime/cgocheck.go @@ -249,7 +249,7 @@ func cgoCheckUsingType(typ *_type, src unsafe.Pointer, off, size uintptr) { at := (*arraytype)(unsafe.Pointer(typ)) for i := uintptr(0); i < at.Len; i++ { if off < at.Elem.Size_ { - cgoCheckUsingType((*_type)(at.Elem), src, off, size) + cgoCheckUsingType(toType(at.Elem), src, off, size) } src = add(src, at.Elem.Size_) skipped := off diff --git a/src/runtime/syscall_windows.go b/src/runtime/syscall_windows.go index 5177f614c8..37f86d0d7f 100644 --- a/src/runtime/syscall_windows.go +++ b/src/runtime/syscall_windows.go @@ -186,7 +186,7 @@ func (p *abiDesc) tryRegAssignArg(t *_type, offset uintptr) bool { case kindArray: at := (*arraytype)(unsafe.Pointer(t)) if at.Len == 1 { - return p.tryRegAssignArg((*_type)(at.Elem), offset) + return p.tryRegAssignArg((*_type)(unsafe.Pointer(at.Elem)), offset) // TODO fix when runtime is fully commoned up w/ abi.Type } case kindStruct: st := (*structtype)(unsafe.Pointer(t)) diff --git a/src/runtime/type.go b/src/runtime/type.go index 85d576379c..bc8ded2821 100644 --- a/src/runtime/type.go +++ b/src/runtime/type.go @@ -19,7 +19,9 @@ type textOff = abi.TextOff // ../cmd/compile/internal/reflectdata/reflect.go:/^func.dcommontype and // ../reflect/type.go:/^type.rtype. // ../internal/reflectlite/type.go:/^type.rtype. -type _type abi.Type +type _type struct { + abi.Type +} func (t *_type) string() string { s := t.nameOff(t.Str).name() @@ -30,65 +32,7 @@ func (t *_type) string() string { } func (t *_type) uncommon() *uncommontype { - if t.TFlag&abi.TFlagUncommon == 0 { - return nil - } - switch t.Kind_ & kindMask { - case kindStruct: - type u struct { - structtype - u uncommontype - } - return &(*u)(unsafe.Pointer(t)).u - case kindPtr: - type u struct { - ptrtype - u uncommontype - } - return &(*u)(unsafe.Pointer(t)).u - case kindFunc: - type u struct { - functype - u uncommontype - } - return &(*u)(unsafe.Pointer(t)).u - case kindSlice: - type u struct { - slicetype - u uncommontype - } - return &(*u)(unsafe.Pointer(t)).u - case kindArray: - type u struct { - arraytype - u uncommontype - } - return &(*u)(unsafe.Pointer(t)).u - case kindChan: - type u struct { - chantype - u uncommontype - } - return &(*u)(unsafe.Pointer(t)).u - case kindMap: - type u struct { - maptype - u uncommontype - } - return &(*u)(unsafe.Pointer(t)).u - case kindInterface: - type u struct { - interfacetype - u uncommontype - } - return &(*u)(unsafe.Pointer(t)).u - default: - type u struct { - _type - u uncommontype - } - return &(*u)(unsafe.Pointer(t)).u - } + return t.Uncommon() } func (t *_type) name() string { @@ -500,6 +444,10 @@ type _typePair struct { t2 *_type } +func toType(t *abi.Type) *_type { + return (*_type)(unsafe.Pointer(t)) +} + // typesEqual reports whether two types are equal. // // Everywhere in the runtime and reflect packages, it is assumed that @@ -554,7 +502,7 @@ func typesEqual(t, v *_type, seen map[_typePair]struct{}) bool { case kindArray: at := (*arraytype)(unsafe.Pointer(t)) av := (*arraytype)(unsafe.Pointer(v)) - return typesEqual((*_type)(at.Elem), (*_type)(av.Elem), seen) && at.Len == av.Len + return typesEqual(toType(at.Elem), toType(av.Elem), seen) && at.Len == av.Len case kindChan: ct := (*chantype)(unsafe.Pointer(t)) cv := (*chantype)(unsafe.Pointer(v)) |
