Debian Codegraph @

src/internal/runtime/maps/export_noswiss_test.go

raw
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 //go:build !goexperiment.swissmap
6
7 // This file allows non-GOEXPERIMENT=swissmap builds (i.e., old map builds) to
8 // construct a swissmap table for running the tests in this package.
9
10 package maps
11
12 import (
13 "internal/abi"
14 "unsafe"
15 )
16
17 type instantiatedGroup[K comparable, V any] struct {
18 ctrls ctrlGroup
19 slots [abi.SwissMapGroupSlots]instantiatedSlot[K, V]
20 }
21
22 type instantiatedSlot[K comparable, V any] struct {
23 key K
24 elem V
25 }
26
27 func newTestMapType[K comparable, V any]() *abi.SwissMapType {
28 var m map[K]V
29 mTyp := abi.TypeOf(m)
30 omt := (*abi.OldMapType)(unsafe.Pointer(mTyp))
31
32 var grp instantiatedGroup[K, V]
33 var slot instantiatedSlot[K, V]
34
35 mt := &abi.SwissMapType{
36 Key: omt.Key,
37 Elem: omt.Elem,
38 Group: abi.TypeOf(grp),
39 Hasher: omt.Hasher,
40 SlotSize: unsafe.Sizeof(slot),
41 GroupSize: unsafe.Sizeof(grp),
42 ElemOff: unsafe.Offsetof(slot.elem),
43 }
44 if omt.NeedKeyUpdate() {
45 mt.Flags |= abi.SwissMapNeedKeyUpdate
46 }
47 if omt.HashMightPanic() {
48 mt.Flags |= abi.SwissMapHashMightPanic
49 }
50 return mt
51 }