From bb31217579974587871a6b7d278ec186f93df126 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20M=C3=B6hrmann?= Date: Sat, 2 Sep 2017 17:32:58 +0200 Subject: [PATCH] runtime: move map ismapkey check to the compiler MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/cmd/compile/internal/gc/reflect.go | 3 +++ src/runtime/hashmap.go | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) 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") -- 2.50.0