mtype *types.Type
}
-// Builds a type representing a Bucket structure for
-// the given map type. This type is not visible to users -
-// we include only enough information to generate a correct GC
-// program for it.
-// Make sure this stays in sync with runtime/map.go.
-//
-// A "bucket" is a "struct" {
-// tophash [BUCKETSIZE]uint8
-// keys [BUCKETSIZE]keyType
-// elems [BUCKETSIZE]elemType
-// overflow *bucket
-// }
-const (
- BUCKETSIZE = abi.MapBucketCount
- MAXKEYSIZE = abi.MapMaxKeyBytes
- MAXELEMSIZE = abi.MapMaxElemBytes
-)
-
func commonSize() int { return int(rttype.Type.Size()) } // Sizeof(runtime._type{})
func uncommonSize(t *types.Type) int { // Sizeof(runtime.uncommontype{})
// MapBucketType makes the map bucket type given the type of the map.
func MapBucketType(t *types.Type) *types.Type {
+ // Builds a type representing a Bucket structure for
+ // the given map type. This type is not visible to users -
+ // we include only enough information to generate a correct GC
+ // program for it.
+ // Make sure this stays in sync with runtime/map.go.
+ //
+ // A "bucket" is a "struct" {
+ // tophash [abi.MapBucketCount]uint8
+ // keys [abi.MapBucketCount]keyType
+ // elems [abi.MapBucketCount]elemType
+ // overflow *bucket
+ // }
if t.MapType().Bucket != nil {
return t.MapType().Bucket
}
elemtype := t.Elem()
types.CalcSize(keytype)
types.CalcSize(elemtype)
- if keytype.Size() > MAXKEYSIZE {
+ if keytype.Size() > abi.MapMaxKeyBytes {
keytype = types.NewPtr(keytype)
}
- if elemtype.Size() > MAXELEMSIZE {
+ if elemtype.Size() > abi.MapMaxElemBytes {
elemtype = types.NewPtr(elemtype)
}
field := make([]*types.Field, 0, 5)
// The first field is: uint8 topbits[BUCKETSIZE].
- arr := types.NewArray(types.Types[types.TUINT8], BUCKETSIZE)
+ arr := types.NewArray(types.Types[types.TUINT8], abi.MapBucketCount)
field = append(field, makefield("topbits", arr))
- arr = types.NewArray(keytype, BUCKETSIZE)
+ arr = types.NewArray(keytype, abi.MapBucketCount)
arr.SetNoalg(true)
keys := makefield("keys", arr)
field = append(field, keys)
- arr = types.NewArray(elemtype, BUCKETSIZE)
+ arr = types.NewArray(elemtype, abi.MapBucketCount)
arr.SetNoalg(true)
elems := makefield("elems", arr)
field = append(field, elems)
if !types.IsComparable(t.Key()) {
base.Fatalf("unsupported map key type for %v", t)
}
- if BUCKETSIZE < 8 {
- base.Fatalf("bucket size %d too small for proper alignment %d", BUCKETSIZE, 8)
+ if abi.MapBucketCount < 8 {
+ base.Fatalf("bucket size %d too small for proper alignment %d", abi.MapBucketCount, 8)
}
- if uint8(keytype.Alignment()) > BUCKETSIZE {
+ if uint8(keytype.Alignment()) > abi.MapBucketCount {
base.Fatalf("key align too big for %v", t)
}
- if uint8(elemtype.Alignment()) > BUCKETSIZE {
- base.Fatalf("elem align %d too big for %v, BUCKETSIZE=%d", elemtype.Alignment(), t, BUCKETSIZE)
+ if uint8(elemtype.Alignment()) > abi.MapBucketCount {
+ base.Fatalf("elem align %d too big for %v, BUCKETSIZE=%d", elemtype.Alignment(), t, abi.MapBucketCount)
}
- if keytype.Size() > MAXKEYSIZE {
+ if keytype.Size() > abi.MapMaxKeyBytes {
base.Fatalf("key size too large for %v", t)
}
- if elemtype.Size() > MAXELEMSIZE {
+ if elemtype.Size() > abi.MapMaxElemBytes {
base.Fatalf("elem size too large for %v", t)
}
- if t.Key().Size() > MAXKEYSIZE && !keytype.IsPtr() {
+ if t.Key().Size() > abi.MapMaxKeyBytes && !keytype.IsPtr() {
base.Fatalf("key indirect incorrect for %v", t)
}
- if t.Elem().Size() > MAXELEMSIZE && !elemtype.IsPtr() {
+ if t.Elem().Size() > abi.MapMaxElemBytes && !elemtype.IsPtr() {
base.Fatalf("elem indirect incorrect for %v", t)
}
if keytype.Size()%keytype.Alignment() != 0 {
var flags uint32
// Note: flags must match maptype accessors in ../../../../runtime/type.go
// and maptype builder in ../../../../reflect/type.go:MapOf.
- if t.Key().Size() > MAXKEYSIZE {
+ if t.Key().Size() > abi.MapMaxKeyBytes {
c.Field("KeySize").WriteUint8(uint8(types.PtrSize))
flags |= 1 // indirect key
} else {
c.Field("KeySize").WriteUint8(uint8(t.Key().Size()))
}
- if t.Elem().Size() > MAXELEMSIZE {
+ if t.Elem().Size() > abi.MapMaxElemBytes {
c.Field("ValueSize").WriteUint8(uint8(types.PtrSize))
flags |= 2 // indirect value
} else {
"fmt"
"go/constant"
"go/token"
+ "internal/abi"
"strings"
"cmd/compile/internal/base"
// Maximum key and elem size is 128 bytes, larger objects
// are stored with an indirection. So max bucket size is 2048+eps.
if !ir.IsConst(hint, constant.Int) ||
- constant.Compare(hint.Val(), token.LEQ, constant.MakeInt64(reflectdata.BUCKETSIZE)) {
+ constant.Compare(hint.Val(), token.LEQ, constant.MakeInt64(abi.MapBucketCount)) {
// In case hint is larger than BUCKETSIZE runtime.makemap
// will allocate the buckets on the heap, see #20184
// h.buckets = b
// }
- nif := ir.NewIfStmt(base.Pos, ir.NewBinaryExpr(base.Pos, ir.OLE, hint, ir.NewInt(base.Pos, reflectdata.BUCKETSIZE)), nil, nil)
+ nif := ir.NewIfStmt(base.Pos, ir.NewBinaryExpr(base.Pos, ir.OLE, hint, ir.NewInt(base.Pos, abi.MapBucketCount)), nil, nil)
nif.Likely = true
// var bv bmap
}
}
- if ir.IsConst(hint, constant.Int) && constant.Compare(hint.Val(), token.LEQ, constant.MakeInt64(reflectdata.BUCKETSIZE)) {
+ if ir.IsConst(hint, constant.Int) && constant.Compare(hint.Val(), token.LEQ, constant.MakeInt64(abi.MapBucketCount)) {
// Handling make(map[any]any) and
// make(map[any]any, hint) where hint <= BUCKETSIZE
// special allows for faster map initialization and