aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/reflectdata
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2024-09-17 18:00:21 -0400
committerGopher Robot <gobot@golang.org>2024-10-30 15:11:27 +0000
commitb5fec2cf54ff9f7b562cb904a2a025266aec2763 (patch)
treebe774c2cef2df29292da32aa083577c207fe2500 /src/cmd/compile/internal/reflectdata
parent2220fd36368c96da3dd833bdc2bbd13be291216a (diff)
downloadgo-b5fec2cf54ff9f7b562cb904a2a025266aec2763.tar.xz
cmd/compile,runtime: add indirect key/elem to swissmap
We use the same heuristics as existing maps. For #54766. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest-swissmap Change-Id: I44bb51483cae2c1714717f1b501850fb9e55a39a Reviewed-on: https://go-review.googlesource.com/c/go/+/616461 Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/compile/internal/reflectdata')
-rw-r--r--src/cmd/compile/internal/reflectdata/map_swiss.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/reflectdata/map_swiss.go b/src/cmd/compile/internal/reflectdata/map_swiss.go
index b531d785d3..4b1166347b 100644
--- a/src/cmd/compile/internal/reflectdata/map_swiss.go
+++ b/src/cmd/compile/internal/reflectdata/map_swiss.go
@@ -34,9 +34,21 @@ func SwissMapGroupType(t *types.Type) *types.Type {
// elem elemType
// }
// }
+
+ keytype := t.Key()
+ elemtype := t.Elem()
+ types.CalcSize(keytype)
+ types.CalcSize(elemtype)
+ if keytype.Size() > abi.SwissMapMaxKeyBytes {
+ keytype = types.NewPtr(keytype)
+ }
+ if elemtype.Size() > abi.SwissMapMaxElemBytes {
+ elemtype = types.NewPtr(elemtype)
+ }
+
slotFields := []*types.Field{
- makefield("key", t.Key()),
- makefield("elem", t.Elem()),
+ makefield("key", keytype),
+ makefield("elem", elemtype),
}
slot := types.NewStruct(slotFields)
slot.SetNoalg(true)
@@ -64,6 +76,12 @@ func SwissMapGroupType(t *types.Type) *types.Type {
// the end to ensure pointers are valid.
base.Fatalf("bad group size for %v", t)
}
+ if t.Key().Size() > abi.SwissMapMaxKeyBytes && !keytype.IsPtr() {
+ base.Fatalf("key indirect incorrect for %v", t)
+ }
+ if t.Elem().Size() > abi.SwissMapMaxElemBytes && !elemtype.IsPtr() {
+ base.Fatalf("elem indirect incorrect for %v", t)
+ }
t.MapType().SwissGroup = group
group.StructType().Map = t
@@ -269,6 +287,12 @@ func writeSwissMapType(t *types.Type, lsym *obj.LSym, c rttype.Cursor) {
if hashMightPanic(t.Key()) {
flags |= abi.SwissMapHashMightPanic
}
+ if t.Key().Size() > abi.SwissMapMaxKeyBytes {
+ flags |= abi.SwissMapIndirectKey
+ }
+ if t.Elem().Size() > abi.SwissMapMaxKeyBytes {
+ flags |= abi.SwissMapIndirectElem
+ }
c.Field("Flags").WriteUint32(flags)
if u := t.Underlying(); u != t {