Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: constant indexing into map literals should be folded #10848
This code from internal/syscall/unix/getrandom_linux.go:
currently compiles into non-trivial chunk of code. However, gc could instead recognize that runtime.GOARCH and all of the map literal keys are constants and that all of the value expressions are side-effect free, and fold to just the corresponding value expression.
It looks like changing the code to:
produces simpler code by taking advantage of the existing switch constant folding logic, but still needs a dynamic initializer.
Alternatively, we could just create 4 extra files and use +build rules. (This is my preference if no one's opposed.)
While here, enable getrandom on arm64 too (using the value found in include/uapi/asm-generic/unistd.h, which seems to match up with other GOARCH=arm64 syscall numbers). Updates #10848. Change-Id: I5ab36ccf6ee8d5cc6f0e1a61d09f0da7410288b9 Reviewed-on: https://go-review.googlesource.com/16662 Run-TryBot: Matthew Dempsky <firstname.lastname@example.org> TryBot-Result: Gobot Gobot <email@example.com> Reviewed-by: Ian Lance Taylor <firstname.lastname@example.org>
Indeed. That map thing is a terrible idiom and should not be encouraged.
On Mon, Mar 21, 2016 at 4:01 AM GopherBot email@example.com wrote: