Commit bb312175 authored by Martin Möhrmann's avatar Martin Möhrmann

runtime: move map ismapkey check to the compiler

Remove the runtime ismapkey check from makemap and
add a check that the map key type supports comparison
to the hmap construction in the compiler.

Move the ismapkey check for the reflect code path
into reflect_makemap.

Change-Id: I718f79b0670c05b63ef31721e72408f59ec4ae86
Reviewed-on: https://go-review.googlesource.com/61035
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent 2d362f7a
...@@ -171,6 +171,9 @@ func bmap(t *types.Type) *types.Type { ...@@ -171,6 +171,9 @@ func bmap(t *types.Type) *types.Type {
dowidth(bucket) dowidth(bucket)
// Check invariants that map code depends on. // Check invariants that map code depends on.
if !IsComparable(t.Key()) {
Fatalf("unsupported map key type for %v", t)
}
if BUCKETSIZE < 8 { if BUCKETSIZE < 8 {
Fatalf("bucket size too small for proper alignment") Fatalf("bucket size too small for proper alignment")
} }
......
...@@ -296,10 +296,6 @@ func makemap(t *maptype, hint int, h *hmap) *hmap { ...@@ -296,10 +296,6 @@ func makemap(t *maptype, hint int, h *hmap) *hmap {
hint = 0 hint = 0
} }
if !ismapkey(t.key) {
throw("runtime.makemap: unsupported map key type")
}
if evacuatedX+1 != evacuatedY { if evacuatedX+1 != evacuatedY {
// evacuate relies on this relationship // evacuate relies on this relationship
throw("bad evacuatedN") throw("bad evacuatedN")
...@@ -1157,6 +1153,9 @@ func reflect_makemap(t *maptype, cap int) *hmap { ...@@ -1157,6 +1153,9 @@ func reflect_makemap(t *maptype, cap int) *hmap {
println("runtime: sizeof(hmap) =", sz, ", t.hmap.size =", t.hmap.size) println("runtime: sizeof(hmap) =", sz, ", t.hmap.size =", t.hmap.size)
throw("bad hmap size") throw("bad hmap size")
} }
if !ismapkey(t.key) {
throw("runtime.reflect_makemap: unsupported map key type")
}
if t.key.size > maxKeySize && (!t.indirectkey || t.keysize != uint8(sys.PtrSize)) || if t.key.size > maxKeySize && (!t.indirectkey || t.keysize != uint8(sys.PtrSize)) ||
t.key.size <= maxKeySize && (t.indirectkey || t.keysize != uint8(t.key.size)) { t.key.size <= maxKeySize && (t.indirectkey || t.keysize != uint8(t.key.size)) {
throw("key size wrong") throw("key size wrong")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment