diff options
| author | Keith Randall <khr@golang.org> | 2022-06-14 13:38:02 -0700 |
|---|---|---|
| committer | Keith Randall <khr@google.com> | 2022-06-14 23:22:11 +0000 |
| commit | e1e66a03a6bb3210034b640923fa253d7def1a26 (patch) | |
| tree | 03dea7b25888433788a5ec80d8cd3cd083a6d96a /src/runtime | |
| parent | cb9bf93078c54187f5be9d8a65c81c249d12d3c5 (diff) | |
| download | go-e1e66a03a6bb3210034b640923fa253d7def1a26.tar.xz | |
cmd/compile,runtime,reflect: move embedded bit from offset to name
Previously we stole a bit from the field offset to encode whether
a struct field was embedded.
Instead, encode that bit in the name field, where we already have
some unused bits to play with. The bit associates naturally with
the name in any case.
This leaves a full uintptr to specify field offsets. This will make
the fix for #52740 cleaner.
Change-Id: I0bfb85564dc26e8c18101bc8b432f332176d7836
Reviewed-on: https://go-review.googlesource.com/c/go/+/412138
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/alg.go | 2 | ||||
| -rw-r--r-- | src/runtime/cgocall.go | 2 | ||||
| -rw-r--r-- | src/runtime/syscall_windows.go | 2 | ||||
| -rw-r--r-- | src/runtime/type.go | 19 |
4 files changed, 14 insertions, 11 deletions
diff --git a/src/runtime/alg.go b/src/runtime/alg.go index 5d7d1c77f4..2a413eeef3 100644 --- a/src/runtime/alg.go +++ b/src/runtime/alg.go @@ -182,7 +182,7 @@ func typehash(t *_type, p unsafe.Pointer, h uintptr) uintptr { if f.name.isBlank() { continue } - h = typehash(f.typ, add(p, f.offset()), h) + h = typehash(f.typ, add(p, f.offset), h) } return h default: diff --git a/src/runtime/cgocall.go b/src/runtime/cgocall.go index 977d049378..892654ed5b 100644 --- a/src/runtime/cgocall.go +++ b/src/runtime/cgocall.go @@ -536,7 +536,7 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) { if f.typ.ptrdata == 0 { continue } - cgoCheckArg(f.typ, add(p, f.offset()), true, top, msg) + cgoCheckArg(f.typ, add(p, f.offset), true, top, msg) } case kindPtr, kindUnsafePointer: if indir { diff --git a/src/runtime/syscall_windows.go b/src/runtime/syscall_windows.go index a841a31a27..e42d71ad65 100644 --- a/src/runtime/syscall_windows.go +++ b/src/runtime/syscall_windows.go @@ -174,7 +174,7 @@ func (p *abiDesc) tryRegAssignArg(t *_type, offset uintptr) bool { st := (*structtype)(unsafe.Pointer(t)) for i := range st.fields { f := &st.fields[i] - if !p.tryRegAssignArg(f.typ, offset+f.offset()) { + if !p.tryRegAssignArg(f.typ, offset+f.offset) { return false } } diff --git a/src/runtime/type.go b/src/runtime/type.go index b650d6d795..e8e7819ecf 100644 --- a/src/runtime/type.go +++ b/src/runtime/type.go @@ -414,13 +414,9 @@ type ptrtype struct { } type structfield struct { - name name - typ *_type - offsetAnon uintptr -} - -func (f *structfield) offset() uintptr { - return f.offsetAnon >> 1 + name name + typ *_type + offset uintptr } type structtype struct { @@ -443,6 +439,10 @@ func (n name) isExported() bool { return (*n.bytes)&(1<<0) != 0 } +func (n name) isEmbedded() bool { + return (*n.bytes)&(1<<3) != 0 +} + func (n name) readvarint(off int) (int, int) { v := 0 for i := 0; ; i++ { @@ -703,7 +703,10 @@ func typesEqual(t, v *_type, seen map[_typePair]struct{}) bool { if tf.name.tag() != vf.name.tag() { return false } - if tf.offsetAnon != vf.offsetAnon { + if tf.offset != vf.offset { + return false + } + if tf.name.isEmbedded() != vf.name.isEmbedded() { return false } } |
