@@ -55,24 +55,6 @@ type typeSig struct {
55
55
mtype * types.Type
56
56
}
57
57
58
- // Builds a type representing a Bucket structure for
59
- // the given map type. This type is not visible to users -
60
- // we include only enough information to generate a correct GC
61
- // program for it.
62
- // Make sure this stays in sync with runtime/map.go.
63
- //
64
- // A "bucket" is a "struct" {
65
- // tophash [BUCKETSIZE]uint8
66
- // keys [BUCKETSIZE]keyType
67
- // elems [BUCKETSIZE]elemType
68
- // overflow *bucket
69
- // }
70
- const (
71
- BUCKETSIZE = abi .MapBucketCount
72
- MAXKEYSIZE = abi .MapMaxKeyBytes
73
- MAXELEMSIZE = abi .MapMaxElemBytes
74
- )
75
-
76
58
func commonSize () int { return int (rttype .Type .Size ()) } // Sizeof(runtime._type{})
77
59
78
60
func uncommonSize (t * types.Type ) int { // Sizeof(runtime.uncommontype{})
@@ -89,6 +71,18 @@ func makefield(name string, t *types.Type) *types.Field {
89
71
90
72
// MapBucketType makes the map bucket type given the type of the map.
91
73
func MapBucketType (t * types.Type ) * types.Type {
74
+ // Builds a type representing a Bucket structure for
75
+ // the given map type. This type is not visible to users -
76
+ // we include only enough information to generate a correct GC
77
+ // program for it.
78
+ // Make sure this stays in sync with runtime/map.go.
79
+ //
80
+ // A "bucket" is a "struct" {
81
+ // tophash [abi.MapBucketCount]uint8
82
+ // keys [abi.MapBucketCount]keyType
83
+ // elems [abi.MapBucketCount]elemType
84
+ // overflow *bucket
85
+ // }
92
86
if t .MapType ().Bucket != nil {
93
87
return t .MapType ().Bucket
94
88
}
@@ -97,25 +91,25 @@ func MapBucketType(t *types.Type) *types.Type {
97
91
elemtype := t .Elem ()
98
92
types .CalcSize (keytype )
99
93
types .CalcSize (elemtype )
100
- if keytype .Size () > MAXKEYSIZE {
94
+ if keytype .Size () > abi . MapMaxKeyBytes {
101
95
keytype = types .NewPtr (keytype )
102
96
}
103
- if elemtype .Size () > MAXELEMSIZE {
97
+ if elemtype .Size () > abi . MapMaxElemBytes {
104
98
elemtype = types .NewPtr (elemtype )
105
99
}
106
100
107
101
field := make ([]* types.Field , 0 , 5 )
108
102
109
103
// The first field is: uint8 topbits[BUCKETSIZE].
110
- arr := types .NewArray (types .Types [types .TUINT8 ], BUCKETSIZE )
104
+ arr := types .NewArray (types .Types [types .TUINT8 ], abi . MapBucketCount )
111
105
field = append (field , makefield ("topbits" , arr ))
112
106
113
- arr = types .NewArray (keytype , BUCKETSIZE )
107
+ arr = types .NewArray (keytype , abi . MapBucketCount )
114
108
arr .SetNoalg (true )
115
109
keys := makefield ("keys" , arr )
116
110
field = append (field , keys )
117
111
118
- arr = types .NewArray (elemtype , BUCKETSIZE )
112
+ arr = types .NewArray (elemtype , abi . MapBucketCount )
119
113
arr .SetNoalg (true )
120
114
elems := makefield ("elems" , arr )
121
115
field = append (field , elems )
@@ -142,25 +136,25 @@ func MapBucketType(t *types.Type) *types.Type {
142
136
if ! types .IsComparable (t .Key ()) {
143
137
base .Fatalf ("unsupported map key type for %v" , t )
144
138
}
145
- if BUCKETSIZE < 8 {
146
- base .Fatalf ("bucket size %d too small for proper alignment %d" , BUCKETSIZE , 8 )
139
+ if abi . MapBucketCount < 8 {
140
+ base .Fatalf ("bucket size %d too small for proper alignment %d" , abi . MapBucketCount , 8 )
147
141
}
148
- if uint8 (keytype .Alignment ()) > BUCKETSIZE {
142
+ if uint8 (keytype .Alignment ()) > abi . MapBucketCount {
149
143
base .Fatalf ("key align too big for %v" , t )
150
144
}
151
- if uint8 (elemtype .Alignment ()) > BUCKETSIZE {
152
- base .Fatalf ("elem align %d too big for %v, BUCKETSIZE=%d" , elemtype .Alignment (), t , BUCKETSIZE )
145
+ if uint8 (elemtype .Alignment ()) > abi . MapBucketCount {
146
+ base .Fatalf ("elem align %d too big for %v, BUCKETSIZE=%d" , elemtype .Alignment (), t , abi . MapBucketCount )
153
147
}
154
- if keytype .Size () > MAXKEYSIZE {
148
+ if keytype .Size () > abi . MapMaxKeyBytes {
155
149
base .Fatalf ("key size too large for %v" , t )
156
150
}
157
- if elemtype .Size () > MAXELEMSIZE {
151
+ if elemtype .Size () > abi . MapMaxElemBytes {
158
152
base .Fatalf ("elem size too large for %v" , t )
159
153
}
160
- if t .Key ().Size () > MAXKEYSIZE && ! keytype .IsPtr () {
154
+ if t .Key ().Size () > abi . MapMaxKeyBytes && ! keytype .IsPtr () {
161
155
base .Fatalf ("key indirect incorrect for %v" , t )
162
156
}
163
- if t .Elem ().Size () > MAXELEMSIZE && ! elemtype .IsPtr () {
157
+ if t .Elem ().Size () > abi . MapMaxElemBytes && ! elemtype .IsPtr () {
164
158
base .Fatalf ("elem indirect incorrect for %v" , t )
165
159
}
166
160
if keytype .Size ()% keytype .Alignment () != 0 {
@@ -1124,14 +1118,14 @@ func writeType(t *types.Type) *obj.LSym {
1124
1118
var flags uint32
1125
1119
// Note: flags must match maptype accessors in ../../../../runtime/type.go
1126
1120
// and maptype builder in ../../../../reflect/type.go:MapOf.
1127
- if t .Key ().Size () > MAXKEYSIZE {
1121
+ if t .Key ().Size () > abi . MapMaxKeyBytes {
1128
1122
c .Field ("KeySize" ).WriteUint8 (uint8 (types .PtrSize ))
1129
1123
flags |= 1 // indirect key
1130
1124
} else {
1131
1125
c .Field ("KeySize" ).WriteUint8 (uint8 (t .Key ().Size ()))
1132
1126
}
1133
1127
1134
- if t .Elem ().Size () > MAXELEMSIZE {
1128
+ if t .Elem ().Size () > abi . MapMaxElemBytes {
1135
1129
c .Field ("ValueSize" ).WriteUint8 (uint8 (types .PtrSize ))
1136
1130
flags |= 2 // indirect value
1137
1131
} else {
0 commit comments