1
0
mirror of https://github.com/golang/go synced 2024-09-30 11:18:33 -06:00
Commit Graph

29287 Commits

Author SHA1 Message Date
Ian Lance Taylor
873dca4c17 net: use runtime.Keepalive for *netFD values
The net package sets a finalizer on *netFD. I looked through all the
uses of *netFD in the package, looking for each case where a *netFD
was passed as an argument and the final reference to the argument was
not a function or method call. I added a call to runtime.KeepAlive after
each such final reference (there were only three).

The code is safe today without the KeepAlive calls because the compiler
keeps arguments alive for the duration of the function. However, that is
not a language requirement, so adding the KeepAlive calls ensures that
this code remains safe even if the compiler changes in the future.

Change-Id: I4e2bd7c5a946035dc509ccefb4828f72335a9ee3
Reviewed-on: https://go-review.googlesource.com/27650
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-24 16:57:50 +00:00
Ian Lance Taylor
e69912e6f4 os: use runtime.Keepalive for *Process values
The os package sets a finalizer on *Process. I looked through all the
uses of *Process in the package, looking for each case where a *Process
was passed as an argument and the final reference to the argument was
not a function or method call. I added a call to runtime.KeepAlive after
each such final reference (there were only three).

The code is safe today without the KeepAlive calls because the compiler
keeps arguments alive for the duration of the function. However, that is
not a language requirement, so adding the KeepAlive calls ensures that
this code remains safe even if the compiler changes in the future.

I also removed an existing unnecessry call to runtime.KeepAlive. The
syscall.Syscall function is handled specially by the compiler to keep
its arguments alive.

Change-Id: Ibd2ff20b31ed3de4f6a59dd1633c1b44001d91d9
Reviewed-on: https://go-review.googlesource.com/27637
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-24 16:57:09 +00:00
Hiroshi Ioka
9be2a279ee internal/testenv: make MustHaveSymlink message friendly
Change-Id: If6e12ebc41152bc0534d3d383df80e960efe97f0
Reviewed-on: https://go-review.googlesource.com/27577
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-24 05:08:52 +00:00
Josh Bleecher Snyder
5bddca64a8 cmd/compile: minor cleanup in mapinit
Change-Id: I7d58d200f7e8b2c0a6e35371da0dafd9b44e9057
Reviewed-on: https://go-review.googlesource.com/26757
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-24 01:37:44 +00:00
Josh Bleecher Snyder
41943d9639 cmd/compile: convert getdyn int arg to bool
Passes toolstash -cmp.

Change-Id: I5b893b8b82b358534fd85542f05e3aa7e666bcd3
Reviewed-on: https://go-review.googlesource.com/26752
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-24 01:07:35 +00:00
Josh Bleecher Snyder
67bcee8d98 cmd/compile: convert Dodata to a bool, rename to IsStatic
Passes toolstash -cmp.

Change-Id: I2c204ec14b0a72b592fb336acdd4dff55650f7f6
Reviewed-on: https://go-review.googlesource.com/26751
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-24 00:56:54 +00:00
Josh Bleecher Snyder
a301b329e5 cmd/compile: simplify isglobal
Passes toolstash -cmp.

Change-Id: I16ec0c11096bf4c020cf41392effeb67436f32ba
Reviewed-on: https://go-review.googlesource.com/26750
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-24 00:52:58 +00:00
Alex Brainman
af9342ca10 syscall, internal/syscall/windows, internal/syscall/windows/registry: make go generate work on every os
Fixes #16368

Change-Id: I2ef7a2deb5798e11cc1d3f8ca29a6e1655155422
Reviewed-on: https://go-review.googlesource.com/27411
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-24 00:52:32 +00:00
Mikio Hara
e9267ca825 vendor: update vendored route
Updates golang_org/x/net/route to rev 4d38db7 for:
- route: don't crash or hang up with corrupted messages

Change-Id: I22492f56a5e211b5a0479f1e07ad8f42f7b9ea03
Reviewed-on: https://go-review.googlesource.com/27574
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-24 00:14:58 +00:00
Jess Frazelle
c6e0c49b41 cmd/go: updates go get to return exit status 0 for test file only pkgs
Updates the behavior of `go get` to return exit status 0 when a
requested package only contains test files.

Fixes #15093

Change-Id: I76b80517d58748090f5e8c6f41178361e2d7ca54
Reviewed-on: https://go-review.googlesource.com/23314
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-23 23:49:34 +00:00
Keith Randall
3e270ab80b cmd/compile: clean up ctz ops
Now that we have ops that can return 2 results, have BSF return a result
and flags.  We can then get rid of the redundant comparison and use CMOV
instead of CMOVconst ops.

Get rid of a bunch of the ops we don't use.  Ctz{8,16}, plus all the Clzs,
and CMOVNEs.  I don't think we'll ever use them, and they would be easy
to add back if needed.

Change-Id: I8858a1d017903474ea7e4002fc76a6a86e7bd487
Reviewed-on: https://go-review.googlesource.com/27630
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2016-08-23 23:45:12 +00:00
Robert Griesemer
6394eb378e cmd/compile: export package for _ (blank) struct fields
Blank struct fields are regular unexported fields. Two
blank fields are different if they are from different
packages. In order to correctly differentiate them, the
compiler needs the package information. Add it to the
export data.

Fixes #15514.

Change-Id: I421aaca22b542fcd0d66b2d2db777249cad78df6
Reviewed-on: https://go-review.googlesource.com/27639
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-23 23:40:36 +00:00
Robert Griesemer
a8eb6d51bb cmd/compile: simplify field/method export (internal cleanup)
Towards a fix for #15514.

Change-Id: I62073e9fdcfe5ddda9b0a47fe8554b524191a77c
Reviewed-on: https://go-review.googlesource.com/27638
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-23 23:39:51 +00:00
Ross Light
ec75230b55 reflect: document equality guarantee for Type
The only previous mention of this property was in the String() method.
Since this is the only way to uniquely identify a type and we can't
change this property without breaking the Go 1 guarantee, it seems
better to document this property than hiding it on a method.

Fixes #16348

Change-Id: I3d25f7d6e6007e3c15c2e13010869888d0181fc2
Reviewed-on: https://go-review.googlesource.com/27170
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-08-23 23:20:48 +00:00
Ian Lance Taylor
8050782cba flag: improve comment for calling String with zero value
Update #16694.

Change-Id: Id6be1535d8a146b3dac3bee429ce407a51272032
Reviewed-on: https://go-review.googlesource.com/27634
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2016-08-23 22:07:43 +00:00
Than McIntosh
78fac02cfd test: add test for gccgo issue #15722
Change-Id: I4faf9a55414e217f0c48528efb13ab8fdcd9bb16
Reviewed-on: https://go-review.googlesource.com/24845
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
2016-08-23 20:43:59 +00:00
Josh Bleecher Snyder
e14e67fff6 cmd/compile: clean up one Node.Etype usage
Whoever Marvin is, we're one step closer to realizing his dream.

Change-Id: I8dece4417d0f9ec234be158d0ee7bc6735342d93
Reviewed-on: https://go-review.googlesource.com/27465
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-23 20:01:22 +00:00
Robert Griesemer
874ea6a4c7 cmd/compile: add comment
Minor update on https://go-review.googlesource.com/27441 .

Change-Id: I605a8bfbe67e259020aa53f1d2357808197d02b6
Reviewed-on: https://go-review.googlesource.com/27631
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-23 18:22:44 +00:00
Martin Möhrmann
9aea69d6dc cmd/compile: fix binary import of unsafe.Pointer literals
Add a type conversion to uintptr for untyped constants
before the conversion to unsafe.Pointer.

Fixes #16317

Change-Id: Ib85feccad1019e687e7eb6135890b64b82fb87fb
Reviewed-on: https://go-review.googlesource.com/27441
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-23 18:03:07 +00:00
Robert Griesemer
ee333b4b74 cmd/compile: don't Fatal when printing -m debug information
Some FmtSharp export formatting flag support was removed with
commit b4e9f70. Don't panic if FmtSharp is set, just ignore it.

Fixes #16820.

Change-Id: Ie0c3d3774bd55002f6d2781b1212d070f083e6b2
Reviewed-on: https://go-review.googlesource.com/27556
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-23 17:51:28 +00:00
Kevin Burke
8e24a98abe cmd/compile: precompute constant square roots
If a program wants to evaluate math.Sqrt for any constant value
(for example, math.Sqrt(3)), we can replace that expression with
its evaluation (1.7320508075688772) at compile time, instead of
generating a SQRT assembly command or equivalent.

Adds tests that math.Sqrt generates the correct values. I also
compiled a short program and verified that the Sqrt expression was
replaced by a constant value in the "after opt" step.

Adds a short doc to the top of generic.rules explaining what the file
does and how other files interact with it.

Fixes #15543.

Change-Id: I6b6e63ac61cec50763a09ba581024adeee03d4fa
Reviewed-on: https://go-review.googlesource.com/27457
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
2016-08-23 17:30:55 +00:00
Ian Lance Taylor
d00890b5f3 runtime: add msan calls before calling traceback functions
Tell msan that the arguments to the traceback functions are initialized,
in case the traceback functions are compiled with -fsanitize=memory.

Change-Id: I3ab0816604906c6cd7086245e6ae2e7fa62fe354
Reviewed-on: https://go-review.googlesource.com/24856
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-23 16:31:16 +00:00
Michael Matloob
24158644dd cmd/link/internal/ld: camelCase a buch of snake_case names
I've also unexported a few symbols that weren't used outside the
package.

Updates #16818

Change-Id: I39d9d87b3eec30b88b4a17c1333cfbbfa6b3518f
Reviewed-on: https://go-review.googlesource.com/27468
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-08-23 16:28:59 +00:00
Ian Lance Taylor
5e66ac9ac6 flag: document that Value.String must work on the zero value
Otherwise flag.PrintDefaults will fail when it tries to determine
whether the default is the zero value.

Fixes #16694.

Change-Id: I253fbf11ffc0a9069fd48c2c3cf3074df53e3a03
Reviewed-on: https://go-review.googlesource.com/27003
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-23 16:26:43 +00:00
Gabriel Russell
eb29ac7a7c time: fix optional fractional seconds range err
The optional fractional seconds overrides any range error
from the second parsing. Instead don't look for optional fractional
seconds if a range error has occured.

Change-Id: I27e0a2432740f6753668bd8833e48b9495bc4036
Reviewed-on: https://go-review.googlesource.com/27590
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-23 15:58:08 +00:00
Hiroshi Ioka
03723c909e path/filepath: use testenv.MustHaveSymlink to simplify symlink tests
Cleanup test code for symbolic links.

Change-Id: I25f561cd34dc4d120a4143f933619d233a6cffc5
Reviewed-on: https://go-review.googlesource.com/27573
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-23 14:53:47 +00:00
Hiroshi Ioka
e893c72f2a os: use testenv.MustHaveSymlink to simplify symlink tests
Cleanup test code for symbolic links.

Change-Id: I7a116e4d5c0e955578eca53c1af559e9092f60cd
Reviewed-on: https://go-review.googlesource.com/27572
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-23 14:46:46 +00:00
Ian Lance Taylor
25d18954f6 test: add test case that gccgo miscompiled
Change-Id: I384eac632a4a87c12977e56a7d7bad7614305c51
Reviewed-on: https://go-review.googlesource.com/25143
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-23 14:19:45 +00:00
Mikio Hara
a7ed9ff754 net: document unimplemented methods and functions
Fixes #16802.

Change-Id: I41be7bb4e21e3beaa2136ee69771b0f455b2a7c6
Reviewed-on: https://go-review.googlesource.com/27417
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-23 14:19:39 +00:00
Mikio Hara
4333d3823d net: fix typo in error message of TCPConn.ReadFrom
On some error when using io.Copy with TCPConn, it displays an error
correlation like the following:

read tcp 192.0.2.1:1111->192.0.2.2:2222: read tcp [2001:db8::2]:2222->[2001:db8::3]:3333 read: connection reset by peer

the correlation "some error on reading after reading operation" looks a
bit confusing because the operation on the ReadFrom method of TCPConn is
actually "writing after reading." To clarify and avoid confusion, this
change sets "readfrom" to the Op field of outer-most OpError instead of
"read."

Change-Id: I6bf4e2e7247143fa54bbcf9cef7a8ae1ede1b35c
Reviewed-on: https://go-review.googlesource.com/25220
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-23 14:15:02 +00:00
Ian Lance Taylor
fe251d2581 runtime: remove unused function in test
Change-Id: I43f14cdd9eb4a1d5471fc88c1b4759ceb2c674cf
Reviewed-on: https://go-review.googlesource.com/24817
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-23 14:09:52 +00:00
Ian Lance Taylor
2d85e87f08 runtime/cgo: add tsan acquire/release around setenv/unsetenv
Change-Id: Iabb25e97714d070c31c657559a97a3bfc979da18
Reviewed-on: https://go-review.googlesource.com/25403
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-23 14:07:58 +00:00
Michael Matloob
0889d2d04a debug/macho: fix comment on Section64
Change-Id: I7c809ec385b56ebb2ec784a1479d466df6ab4d1a
Reviewed-on: https://go-review.googlesource.com/27565
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-08-23 13:44:12 +00:00
Josh Bleecher Snyder
d98de0c3d0 cmd/compile: use two tables for table-driven map inserts
This enables better packing when key and value
types have different alignments.

Cuts 57k off cmd/go.

Change-Id: Ifdd125264caccd7852d622382c94e4689e757978
Reviewed-on: https://go-review.googlesource.com/26669
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-08-23 13:40:30 +00:00
Ian Lance Taylor
c8941bb85c doc: add note about CL 24180 to go1.8.txt
Change-Id: Ie2bef1c181a49d7a02ed8068894d2bd81fc5bafa
Reviewed-on: https://go-review.googlesource.com/27566
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-08-23 13:15:32 +00:00
Ian Lance Taylor
d92a3606f5 cmd/go, cmd/link: build c-archive as position independent on ELF
This permits people to use -buildmode=c-archive to produce an archive
file that can be included in a PIE or shared library.

Change-Id: Ie340ee2f08bcff4f6fd1415f7d96d51ee3a7c9a1
Reviewed-on: https://go-review.googlesource.com/24180
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-08-23 13:12:56 +00:00
Ian Lance Taylor
dc9755c2a2 runtime: add missing race and msan checks to reflect functions
Add missing race and msan checks to reflect.typedmmemove and
reflect.typedslicecopy. Missing these checks caused the race detector
to miss races and caused msan to issue false positive errors.

Fixes #16281.

Change-Id: I500b5f92bd68dc99dd5d6f297827fd5d2609e88b
Reviewed-on: https://go-review.googlesource.com/24760
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2016-08-23 13:12:15 +00:00
Ian Lance Taylor
d9504d4623 cmd/link: don't record interpreter in flagInterpreter
Keep flagInterpreter unchanged after flag parsing. This lets us replace
flagInterpreterSet with flagInterpreter != "".

Change-Id: Ifd2edbb2ce0011e97276ca18281b8ffbabde1c50
Reviewed-on: https://go-review.googlesource.com/27563
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-23 13:10:12 +00:00
Mikio Hara
e3cecfdcae net: fix a typo
Change-Id: I29fadde646095fa8507f239a339857bf53172c14
Reviewed-on: https://go-review.googlesource.com/27418
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-23 13:04:11 +00:00
Elias Naur
80b31c05e6 time: load time zones from the system tzdata file on Android
Android timezones are in a packed format, different from the separate
files of a regular Unix system. This CL contain the necessary code to
parse the packed tzdata file and extract time zones from it. It also
adds a basic test to ensure the new parser works.

Fixes #13581

Change-Id: Idebe73726c3d4c2de89dd6ae1d7d19f975207500
Reviewed-on: https://go-review.googlesource.com/24494
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-23 06:15:35 +00:00
Carlos Eduardo Seo
0df5ab7e65 runtime: Use clock_gettime to get current time on ppc64x
Fetch the current time in nanoseconds, not microseconds, by using
clock_gettime rather than gettimeofday.

Updates #11222

Change-Id: I1c2c1b88f80ae82002518359436e19099061c6fb
Reviewed-on: https://go-review.googlesource.com/26790
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Minux Ma <minux@golang.org>
2016-08-23 05:37:05 +00:00
Hiroshi Ioka
8a9b96ace4 internal/testenv: add HasSymlink/MustHaveSymlink
os package and path/filepath package have duplicated code for
checking symlink supports in test code.
This CL tries to simplify such test code.

Change-Id: I0371488337f5e951eca699852daab9ccb16ddd62
Reviewed-on: https://go-review.googlesource.com/27331
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-23 05:35:06 +00:00
Ian Lance Taylor
0b5f2f0d11 net/http: if context is canceled, return its error
This permits the error message to distinguish between a context that was
canceled and a context that timed out.

Updates #16381.

Change-Id: I3994b98e32952abcd7ddb5fee08fa1535999be6d
Reviewed-on: https://go-review.googlesource.com/24978
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-23 05:31:45 +00:00
Josh Bleecher Snyder
643b9ec07c cmd/compile: tidy up switch case expansion
No functional changes.

Change-Id: I0961227e8a7be2d7c611452896843b6955303fa6
Reviewed-on: https://go-review.googlesource.com/26768
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-23 05:29:10 +00:00
Josh Bleecher Snyder
a9266eef93 cmd/compile: simplify constant switch case sorting
This sort is now only reachable for constant clauses
for a non-interface switch expression value.

Refactor a bit so that the few tests that remain
are concise and easy to read.

Add a test that string length takes priority
over built-in string order.

Change-Id: Iedaa11ff77049d5ad1bf14f54cbb8c3411d589a7
Reviewed-on: https://go-review.googlesource.com/26767
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-23 05:28:50 +00:00
Josh Bleecher Snyder
e26499153e cmd/compile: use a map to track const switch cases
This is simpler than the sorting technique.
It also allows us to simplify or eliminate
some of the sorting decisions.

Most important, sorting will not work when case clauses
represent ranges of integers: There is no correct
sort order that allows overlap detection by comparing
neighbors. Using a map allows of a cheap, simple
approach to ranges, namely to insert every int
in the map. The equivalent approach for sorting
means juggling temporary Nodes for every int,
which is a lot more expensive.

Change-Id: I84df3cb805992a1b04d14e0e4b2334f943e0ce05
Reviewed-on: https://go-review.googlesource.com/26766
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-23 05:28:33 +00:00
Josh Bleecher Snyder
b7ac426ee3 cmd/compile: split genCaseClauses by switch type
The implementations are going to start diverging more.
Instead of more if clauses and empty parameters,
specialize.

Change-Id: I44584450592e8c9f72a10d8ada859c07e9d9aa19
Reviewed-on: https://go-review.googlesource.com/26764
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-23 05:27:27 +00:00
Josh Bleecher Snyder
b046786528 cmd/compile: eliminate switch case kinds
We used to have separate kinds for the default
case and the nil type case. Now that those are
gone, we can use a simple bool instead.

Change-Id: I65488e945df68178e893cddd2e091ebb6e32ef4d
Reviewed-on: https://go-review.googlesource.com/26763
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-23 05:26:57 +00:00
Josh Bleecher Snyder
4739dcf7fb cmd/compile: fix printing of OCASE nodes
Switch lowering splits each case expression out
into its own OCASE node.

Change-Id: Ifcb72b99975ed36da8540f6e43343e9aa2058572
Reviewed-on: https://go-review.googlesource.com/26769
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-23 05:26:45 +00:00
Josh Bleecher Snyder
bd2838be77 cmd/compile: use a map to detect duplicate type switch cases
This is a bit simpler than playing sorting games,
and it is clearer that it generates errors
in the correct (source) order.

It also allows us to simplify sorting.

It also prevents quadratic error messages for
(pathological) inputs with many duplicate type cases.

While we’re here, refactoring deduping into separate functions.

Negligible compilebench impact.

Fixes #15912.

Change-Id: I6cc19edd38875389a70ccbdbdf0d9b7d5ac5946f
Reviewed-on: https://go-review.googlesource.com/26762
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-23 05:17:05 +00:00