commit | 8f3d9855a10a7a77bffe635bb37f4cfe1090ea0e | [log] [tgz] |
---|---|---|
author | Matthew Dempsky <mdempsky@google.com> | Tue Sep 10 16:03:03 2019 -0700 |
committer | Matthew Dempsky <mdempsky@google.com> | Mon Sep 16 23:05:09 2019 +0000 |
tree | 6466856391d3a62a5f01ee33c3b3167fc6f704fb | |
parent | 115e4c9c14779f2561de4299b5748b98d7dd8cf0 [diff] |
cmd/compile: major refactoring of switch walking There are a lot of complexities to handling switches efficiently: 1. Order matters for expression switches with non-constant cases and for type expressions with interface types. We have to respect side-effects, and we also can't allow later cases to accidentally take precedence over earlier cases. 2. For runs of integers, floats, and string constants in expression switches or runs of concrete types in type switches, we want to emit efficient binary searches. 3. For runs of consecutive integers in expression switches, we want to collapse them into range comparisons. 4. For binary searches of strings, we want to compare by length first, because that's more efficient and we don't need to respect any particular ordering. 5. For "switch true { ... }" and "switch false { ... }", we want to optimize "case x:" as simply "if x" or "if !x", respectively, unless x is interface-typed. The current swt.go code reflects how these constraints have been incrementally added over time, with each of them being handled ad hocly in different parts of the code. Also, the existing code tries very hard to reuse logic between expression and type switches, even though the similarities are very superficial. This CL rewrites switch handling to better abstract away the logic involved in constructing the binary searches. In particular, it's intended to make further optimizations to switch dispatch much easier. It also eliminates the need for both OXCASE and OCASE ops, and a subsequent CL can collapse the two. Passes toolstash-check. Change-Id: Ifcd1e56f81f858117a412971d82e98abe7c4481f Reviewed-on: https://go-review.googlesource.com/c/go/+/194660 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Official binary distributions are available at https://golang.org/dl/.
After downloading a binary release, visit https://golang.org/doc/install or load doc/install.html in your web browser for installation instructions.
If a binary distribution is not available for your combination of operating system and architecture, visit https://golang.org/doc/install/source or load doc/install-source.html in your web browser for source installation instructions.
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines: https://golang.org/doc/contribute.html
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://golang.org/wiki/Questions for a list of places to ask questions about the Go language.