compiler, runtime, reflect: generate hash functions only for map keys
commit10172a64cedd95b302a9709429a4832a879667da
authorIan Lance Taylor <ian@gcc.gnu.org>
Thu, 2 Jan 2020 21:55:32 +0000 (2 21:55 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Thu, 2 Jan 2020 21:55:32 +0000 (2 21:55 +0000)
tree736b88eb69baa715a8ac1dbfb4b059eece8a049f
parent9279b5ba4538da8041f074db3f5fcd9e8ecff93e
compiler, runtime, reflect: generate hash functions only for map keys

    Right now we generate hash functions for all types, just in case they
    are used as map keys. That's a lot of wasted effort and binary size
    for types which will never be used as a map key. Instead, generate
    hash functions only for types that we know are map keys.

    Just doing that is a bit too simple, since maps with an interface type
    as a key might have to hash any concrete key type that implements that
    interface. So for that case, implement hashing of such types at
    runtime (instead of with generated code). It will be slower, but only
    for maps with interface types as keys, and maybe only a bit slower as
    the aeshash time probably dominates the dispatch time.

    Reorg where we keep the equals and hash functions. Move the hash function
    from the key type to the map type, saving a field in every non-map type.
    That leaves only one function in the alg structure, so get rid of that and
    just keep the equal function in the type descriptor itself.

    While we're here, reorganize the rtype struct to more closely match
    the gc version.

    This is the gofrontend version of https://golang.org/cl/191198.

    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/212843

From-SVN: r279848
18 files changed:
gcc/go/gofrontend/MERGE
gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/gogo.h
gcc/go/gofrontend/names.cc
gcc/go/gofrontend/types.cc
gcc/go/gofrontend/types.h
libgo/go/internal/reflectlite/type.go
libgo/go/reflect/type.go
libgo/go/reflect/value.go
libgo/go/runtime/alg.go
libgo/go/runtime/map.go
libgo/go/runtime/map_benchmark_test.go
libgo/go/runtime/map_fast32.go
libgo/go/runtime/map_fast64.go
libgo/go/runtime/map_faststr.go
libgo/go/runtime/map_test.go
libgo/go/runtime/type.go
libgo/runtime/go-unsafe-pointer.c