]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: move map ismapkey check to the compiler
authorMartin Möhrmann <moehrmann@google.com>
Sat, 2 Sep 2017 15:32:58 +0000 (17:32 +0200)
committerMartin Möhrmann <moehrmann@google.com>
Tue, 5 Sep 2017 20:39:52 +0000 (20:39 +0000)
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: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/reflect.go
src/runtime/hashmap.go

index c5730dbcb80a4678e0aa729dc3b3bb14c1b98894..c4ab1df62d10eb6faa2480008d01ca159053343b 100644 (file)
@@ -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")
        }
index cbb1f0defc2e7cb46f50f48e3bbe34b123fc2261..bf5d51ab8f517aea11172dc005a2d468a8ff6d69 100644 (file)
@@ -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")