From: Martin Möhrmann Date: Sat, 2 Sep 2017 15:32:58 +0000 (+0200) Subject: runtime: move map ismapkey check to the compiler X-Git-Tag: go1.10beta1~1218 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bb31217579974587871a6b7d278ec186f93df126;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/gc/reflect.go b/src/cmd/compile/internal/gc/reflect.go index c5730dbcb8..c4ab1df62d 100644 --- a/src/cmd/compile/internal/gc/reflect.go +++ b/src/cmd/compile/internal/gc/reflect.go @@ -171,6 +171,9 @@ func bmap(t *types.Type) *types.Type { dowidth(bucket) // Check invariants that map code depends on. + if !IsComparable(t.Key()) { + Fatalf("unsupported map key type for %v", t) + } if BUCKETSIZE < 8 { Fatalf("bucket size too small for proper alignment") } diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index cbb1f0defc..bf5d51ab8f 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -296,10 +296,6 @@ func makemap(t *maptype, hint int, h *hmap) *hmap { hint = 0 } - if !ismapkey(t.key) { - throw("runtime.makemap: unsupported map key type") - } - if evacuatedX+1 != evacuatedY { // evacuate relies on this relationship throw("bad evacuatedN") @@ -1157,6 +1153,9 @@ func reflect_makemap(t *maptype, cap int) *hmap { println("runtime: sizeof(hmap) =", sz, ", t.hmap.size =", t.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)) || t.key.size <= maxKeySize && (t.indirectkey || t.keysize != uint8(t.key.size)) { throw("key size wrong")