Skip to content

Commit e92816b

Browse files
runtime,reflect: clean duplicate definitions itab
For #65355 Change-Id: If676bffe28ae3f20e4ed15a56993811bee05ef22
1 parent 39ec246 commit e92816b

File tree

11 files changed

+88
-77
lines changed

11 files changed

+88
-77
lines changed

src/cmd/internal/objabi/pkgspecial.go

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ var runtimePkgs = []string{
5757
"internal/godebugs",
5858
"internal/goexperiment",
5959
"internal/goos",
60+
61+
"internal/runtime/itab",
6062
}
6163

6264
// extraNoInstrumentPkgs is the set of packages in addition to runtimePkgs that

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
17861786
"type:internal/abi.SliceType",
17871787
"type:internal/abi.StructType",
17881788
"type:internal/abi.InterfaceType",
1789-
"type:runtime.itab",
1789+
"type:internal/runtime/itab.Itab",
17901790
"type:internal/abi.Imethod"} {
17911791
d.defgotype(d.lookupOrDiag(typ))
17921792
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestRuntimeTypesPresent(t *testing.T) {
6565
"internal/abi.SliceType": true,
6666
"internal/abi.StructType": true,
6767
"internal/abi.InterfaceType": true,
68-
"runtime.itab": true,
68+
"internal/runtime/itab.Itab": true,
6969
}
7070

7171
found := findTypes(t, dwarf, want)

src/go/build/deps_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ var depsRules = `
5656
5757
unsafe < maps;
5858
59+
internal/abi < internal/runtime/itab;
60+
5961
# RUNTIME is the core runtime group of packages, all of them very light-weight.
6062
internal/abi,
6163
internal/chacha8rand,
@@ -64,7 +66,8 @@ var depsRules = `
6466
internal/goarch,
6567
internal/godebugs,
6668
internal/goexperiment,
67-
internal/goos
69+
internal/goos,
70+
internal/runtime/itab
6871
< internal/bytealg
6972
< internal/itoa
7073
< internal/unsafeheader
@@ -189,7 +192,7 @@ var depsRules = `
189192
190193
# FMT is OS (which includes string routines) plus reflect and fmt.
191194
# It does not include package log, which should be avoided in core packages.
192-
arena, strconv, unicode
195+
arena, strconv, unicode, internal/runtime/itab
193196
< reflect;
194197
195198
os, reflect

src/internal/runtime/itab/itab.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package itab
6+
7+
import "internal/abi"
8+
9+
// layout of Itab known to compilers
10+
// allocated in non-garbage-collected memory
11+
// Needs to be in sync with
12+
// ../cmd/compile/internal/reflectdata/reflect.go:/^func.WritePluginTable.
13+
type Itab struct {
14+
Inter *abi.InterfaceType
15+
Type *abi.Type
16+
Hash uint32 // copy of _type.hash. Used for type switches.
17+
_ [4]byte
18+
Fun [1]uintptr // variable sized. fun[0]==0 means _type does not implement inter.
19+
}

src/reflect/value.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"internal/abi"
1010
"internal/goarch"
1111
"internal/itoa"
12+
"internal/runtime/itab"
1213
"internal/unsafeheader"
1314
"math"
1415
"runtime"
@@ -208,14 +209,7 @@ type emptyInterface struct {
208209

209210
// nonEmptyInterface is the header for an interface value with methods.
210211
type nonEmptyInterface struct {
211-
// see ../runtime/iface.go:/Itab
212-
itab *struct {
213-
ityp *abi.Type // static interface type
214-
typ *abi.Type // dynamic concrete type
215-
hash uint32 // copy of typ.hash
216-
_ [4]byte
217-
fun [100000]unsafe.Pointer // method table
218-
}
212+
itab *itab.Itab
219213
word unsafe.Pointer
220214
}
221215

@@ -883,7 +877,7 @@ func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs
883877
// The return value t gives the method type signature (without the receiver).
884878
// The return value fn is a pointer to the method code.
885879
func methodReceiver(op string, v Value, methodIndex int) (rcvrtype *abi.Type, t *funcType, fn unsafe.Pointer) {
886-
i := methodIndex
880+
i := uintptr(methodIndex)
887881
if v.typ().Kind() == abi.Interface {
888882
tt := (*interfaceType)(unsafe.Pointer(v.typ()))
889883
if uint(i) >= uint(len(tt.Methods)) {
@@ -897,8 +891,8 @@ func methodReceiver(op string, v Value, methodIndex int) (rcvrtype *abi.Type, t
897891
if iface.itab == nil {
898892
panic("reflect: " + op + " of method on nil interface value")
899893
}
900-
rcvrtype = iface.itab.typ
901-
fn = unsafe.Pointer(&iface.itab.fun[i])
894+
rcvrtype = iface.itab.Type
895+
fn = unsafe.Add(unsafe.Pointer(&iface.itab.Fun[0]), unsafe.Sizeof(iface.itab.Fun[0])*i)
902896
t = (*funcType)(unsafe.Pointer(tt.typeOff(m.Typ)))
903897
} else {
904898
rcvrtype = v.typ()

src/runtime/alg.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"internal/abi"
99
"internal/cpu"
1010
"internal/goarch"
11+
"internal/runtime/itab"
1112
"unsafe"
1213
)
1314

@@ -100,7 +101,7 @@ func interhash(p unsafe.Pointer, h uintptr) uintptr {
100101
if tab == nil {
101102
return h
102103
}
103-
t := tab._type
104+
t := tab.Type
104105
if t.Equal == nil {
105106
// Check hashability here. We could do this check inside
106107
// typehash, but we want to report the topmost type in
@@ -223,7 +224,7 @@ func mapKeyError2(t *_type, p unsafe.Pointer) error {
223224
if a.tab == nil {
224225
return nil
225226
}
226-
t = a.tab._type
227+
t = a.tab.Type
227228
pdata = &a.data
228229
}
229230

@@ -325,11 +326,11 @@ func efaceeq(t *_type, x, y unsafe.Pointer) bool {
325326
}
326327
return eq(x, y)
327328
}
328-
func ifaceeq(tab *itab, x, y unsafe.Pointer) bool {
329+
func ifaceeq(tab *itab.Itab, x, y unsafe.Pointer) bool {
329330
if tab == nil {
330331
return true
331332
}
332-
t := tab._type
333+
t := tab.Type
333334
eq := t.Equal
334335
if eq == nil {
335336
panic(errorString("comparing uncomparable type " + toRType(t).string()))

src/runtime/heapdump.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"internal/abi"
1616
"internal/goarch"
1717
"internal/goexperiment"
18+
"internal/runtime/itab"
1819
"unsafe"
1920
)
2021

@@ -539,8 +540,8 @@ func dumpparams() {
539540
dumpint(uint64(ncpu))
540541
}
541542

542-
func itab_callback(tab *itab) {
543-
t := tab._type
543+
func itab_callback(tab *itab.Itab) {
544+
t := tab.Type
544545
dumptype(t)
545546
dumpint(tagItab)
546547
dumpint(uint64(uintptr(unsafe.Pointer(tab))))

0 commit comments

Comments
 (0)