David R. Jenni [Sun, 5 Feb 2017 10:02:03 +0000 (11:02 +0100)]
sort: optimize average calculation in binary search
Use fewer instructions to calculate the average of i and j without
overflowing at the addition.
Even if both i and j are math.MaxInt{32,64}, the sum fits into a
uint{32,64}. Because the sum of i and j is always ≥ 0, the right
shift by one does the same as a division by two. The result of the
shift operation is at most math.MaxInt{32,64} and fits again into
an int{32,64}.
name old time/op new time/op delta
SearchWrappers-4 153ns ± 3% 143ns ± 6% -6.33% (p=0.000 n=90+100)
This calculation is documented in:
https://research.googleblog.com/2006/06/extra-extra-read-all-about-it-nearly.html
Change-Id: I2be7922afc03b3617fce32e59364606c37a83678
Reviewed-on: https://go-review.googlesource.com/36332 Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Alex Brainman [Fri, 13 Jan 2017 07:02:07 +0000 (18:02 +1100)]
cmd/link: do not prefix external symbols with underscore on windows/386/cgo
CL 18057 added underscore to most external pe symbols
on windows/386/cgo. The CL changed runtime.epclntab and
runtime.pclntab pe symbols into _runtime.pclntab and
_runtime.epclntab, and now cmd/nm cannot find them.
Revert correspondent CL 18057 changes, because most pe
symbols do not need underscore prefix.
This CL also removes code that added obj.SHOSTOBJ symbols
explicitly, because each of those was also added via
genasmsym call. These created duplicate pe symbols (like
_GetProcAddress@8 and __GetProcAddress@8), and external
linker would complain.
This CL adds new test in cmd/nm to verify go programs
built with cgo.
Fixes #18416
Change-Id: I68b1be8fb631d95ec69bd485c77c79604fb23f26
Reviewed-on: https://go-review.googlesource.com/35076 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Peter Nguyen [Fri, 3 Feb 2017 20:45:50 +0000 (21:45 +0100)]
net/rpc/jsonrpc: Update package doc with info about JSON-RPC 2.0
Currently the net/rpc/jsonrpc package only implements JSON-RPC version
1.0. This change updates the package's documentation with link to find
packages for JSON-RPC 2.0.
Michael Munday [Fri, 3 Feb 2017 09:55:34 +0000 (04:55 -0500)]
cmd/compile: fix type propagation through s390x SSA rules
This CL fixes two issues:
1. Load ops were initially always lowered to unsigned loads, even
for signed types. This was fine by itself however LoadReg ops
(used to re-load spilled values) were lowered to signed loads
for signed types. This meant that spills could invalidate
optimizations that assumed the original unsigned load.
2. Types were not always being maintained correctly through rules
designed to eliminate unnecessary zero and sign extensions.
Russ Cox [Fri, 13 Jan 2017 16:49:16 +0000 (11:49 -0500)]
cmd/go: break a few dependencies
This CL makes a few naming changes to break dependencies
between different parts of the go command, to make it easier
to split into different packages.
This is the first CL in a long sequence of changes to break up the
go command from one package into a plausible group of packages.
This sequence is concerned only with moving code, not changing
or cleaning up code. There will still be more cleanup after this sequence.
The entire sequence will be submitted together: it is not a goal
for the tree to build at every step.
For #18653.
Change-Id: I69a98b9ea48e61b1e1cda95273d29860b525415f
Reviewed-on: https://go-review.googlesource.com/36129 Reviewed-by: David Crawshaw <crawshaw@golang.org>
Elias Naur [Sun, 29 Jan 2017 14:34:50 +0000 (15:34 +0100)]
runtime: handle SIGPIPE in c-archive and c-shared programs
Before this CL, Go programs in c-archive or c-shared buildmodes
would not handle SIGPIPE. That leads to surprising behaviour where
writes on a closed pipe or socket would raise SIGPIPE and terminate
the program. This CL changes the Go runtime to handle
SIGPIPE regardless of buildmode. In addition, SIGPIPE from non-Go
code is forwarded.
This is a refinement of CL 32796 that fixes the case where a non-default
handler for SIGPIPE is installed by the host C program.
Fixes #17393
Change-Id: Ia41186e52c1ac209d0a594bae9904166ae7df7de
Reviewed-on: https://go-review.googlesource.com/35960
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
When the number of variables in a function is very large,
liveness analysis gets less efficient, since every bit vector
is O(number of variables).
Improve the situation by returning a sparse representation
from progeffects. In all scenarios, progeffects either
returns a slice that is shared function-wide,
and which is usually small, or a slice that is guaranteed
to have at most three values.
Reduces compilation time for the code in #8225 Comment 1 by ~10%.
Minor effects on regular packages (below).
Keith Randall [Mon, 30 Jan 2017 22:55:12 +0000 (14:55 -0800)]
cmd/compile: make sure output params are live if there is a defer
If there is a defer, and that defer recovers, then the caller
can see all of the output parameters. That means that we must
mark all the output parameters live at any point which might panic.
If there is no defer then this is not necessary. This is implemented.
We could also detect whether there is a recover in any of the defers.
If not, we would need to mark only output params that the defer
actually references (and the closure mechanism already does that).
This is not implemented.
These rules trigger 116 times while running make.bash.
And at least for the sample code at
https://github.com/golang/go/issues/18906#issuecomment-277174241
they are providing optimizations not already present
in amd64.
This speeds up compilation of the code in #8225 by 25%-30%.
The complexity of the algorithm is unchanged,
but this shrinks the constant factor so much that it doesn't matter,
even the size of the giant type switch gets scaled up dramatically.
Keith Randall [Fri, 3 Feb 2017 02:50:45 +0000 (18:50 -0800)]
runtime: darwin/amd64, don't depend on outarg slots being unmodified
sigtramp was calling sigtrampgo and depending on the fact that
the 3rd argument slot will not be modified on return. Our calling
convention doesn't guarantee that. Avoid that assumption.
There's no actual bug here, as sigtrampgo does not in fact modify its
argument slots. But I found this while working on the dead stack slot
clobbering tool. https://go-review.googlesource.com/c/23924/
Change-Id: Ia7e791a2b4c1c74fff24cba8169e7840b4b06ffc
Reviewed-on: https://go-review.googlesource.com/36216
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Russ Cox [Fri, 3 Feb 2017 01:37:29 +0000 (20:37 -0500)]
net/http: fix dns hijacking test
The name lookups are unrooted; the test should be unrooted too.
Correctly skips the tests if the DNS config specifies a domain
suffix that has a wildcard entry causing all unrooted names to resolve.
Lars Wiegman [Tue, 17 Jan 2017 10:38:18 +0000 (11:38 +0100)]
runtime: use mach_absolute_time for runtime.nanotime
The existing darwin/amd64 implementation of runtime.nanotime returns the
wallclock time, which results in timers not functioning properly when
system time runs backwards. By implementing the algorithm used by the
darwin syscall mach_absolute_time, timers will function as expected.
The algorithm is described at
https://opensource.apple.com/source/xnu/xnu-3248.60.10/libsyscall/wrappers/mach_absolute_time.s
cmd/compile: convert constants to interfaces without allocating
The order pass is responsible for ensuring that
values passed to runtime functions, including
convT2E/convT2I, are addressable.
Prior to this CL, this was always accomplished
by creating a temp, which frequently escaped to
the heap, causing allocations, perhaps most
notably in code like:
fmt.Println(1, 2, 3) // allocates three times
None of the runtime routines modify the contents
of the pointers they receive, so in the case of
constants, instead of creating a temp value,
we can create a static value.
(Marking the static value as read-only provides
protection against accidental attempts by the runtime
to modify the constant data.)
This improves code generation for code like:
panic("abc")
c <- 2 // c is a chan int
which can now simply refer to "abc" and 2,
rather than going by way of a temporary.
It also allows us to optimize convT2E/convT2I,
by recognizing static readonly values
and directly constructing the interface.
This CL adds ~0.5% to binary size, despite
decreasing the size of many functions,
because it also adds many static symbols.
This binary size regression could be recovered in
future (but currently unplanned) work.
There is a lot of content-duplication in these
symbols; this statement generates six new symbols,
three containing an int 1 and three containing
a pointer to the string "a":
fmt.Println(1, 1, 1, "a", "a", "a")
These symbols could be made content-addressable.
Furthermore, these symbols are small, so the
alignment and naming overhead is large.
As with the go.strings section, these symbols
could be hidden and have their alignment reduced.
The changes to test/live.go make it impossible
(at least with current optimization techniques)
to place the values being passed to the runtime
in static symbols, preserving autotmp creation.
cmd/compile: reduce slice growth in fuseBlockPlain
Instead of always appending to c.Values,
choose whichever slice is larger;
b.Values will be set to nil anyway.
Appending once instead of in a loop also
limits slice growth to once per function call
and is more efficient.
Reduces max rss for the program in #18602 by 6.5%,
and eliminates fuseBlockPlain from the alloc_space
pprof output. fuseBlockPlain previously accounted
for 16.74% of allocated memory.
Keith Randall [Sun, 27 Nov 2016 18:41:37 +0000 (10:41 -0800)]
cmd/compile: fix CSE with commutative ops
CSE opportunities were being missed for commutative ops. We used to
order the args of commutative ops (by arg ID) once at the start of CSE.
But that may not be enough.
Equivalent commutative ops x1 and x2 may not get their args ordered in
the same way because because at the start of CSE, we don't know that
the i values will be CSEd. If x1 and x2 get opposite orders we won't
CSE them.
Instead, (re)order the args of commutative operations by their
equivalence class IDs each time we partition an equivalence class.
Emmanuel Odeke [Sat, 14 Jan 2017 12:23:23 +0000 (05:23 -0700)]
cmd/compile: improve error for wrong type in switch
Fixes #10561.
Provides a better diagnostic message for failed type switch
satisfaction in the case that a value receiver is being used
in place of the pointer receiver that implements and satisfies
the interface.
Change-Id: If8c13ba13f2a8d81bf44bac7c3a66c12921ba921
Reviewed-on: https://go-review.googlesource.com/35235 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Hiroshi Ioka [Thu, 2 Feb 2017 12:53:52 +0000 (21:53 +0900)]
cmd/cgo: don't track same node twice in guessKinds
Change-Id: Ib2c1490a42e3485913a05a0b2fecdcc425d42871
Reviewed-on: https://go-review.googlesource.com/36083
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Elias Naur [Wed, 1 Feb 2017 17:41:27 +0000 (18:41 +0100)]
misc/ios: allow exit code 0 to mean test success
Tests that use TestMain might never call m.Run(), and simply return
from TestMain. In that case, the iOS test harness never sees the
PASS from the testing framework and assumes the test failed.
Allow an exit with exit code 0 to also mean test success, thereby
fixing the objdump test on iOS.
Change-Id: I1fe9077b05931aa0905e41b88945cd153c5b35b6
Reviewed-on: https://go-review.googlesource.com/36065 Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Emmanuel Odeke [Sun, 1 Jan 2017 10:08:48 +0000 (03:08 -0700)]
cmd/compile: improve error message if init is directly invoked
Fixes #8481.
Inform the user that init functions cannot be directly invoked
in user code, as mandated by the spec at:
http://golang.org/ref/spec#Program_initialization_and_execution.
Change-Id: Ib12c0c08718ffd48b76b6f9b13c76bb6612d2e7b
Reviewed-on: https://go-review.googlesource.com/34790 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
cmd/compile: fix conversion error message for printed slices
Fixes #15055.
Updates exprfmt printing using fmt verb "%v" to check that n.Left
is non-nil before attempting to print it, otherwise we'll print
the nodes in the list using verb "%.v".
Credit to @mdempsky for this approach and for finding
the root cause of the issue.
Change-Id: I20a6464e916dc70d5565e145164bb9553e5d3865
Reviewed-on: https://go-review.googlesource.com/25361 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Matthew Dempsky [Thu, 2 Feb 2017 00:40:46 +0000 (16:40 -0800)]
cmd/compile: skip reexporting types in reexportdep
The binary export format embeds type definitions inline as necessary,
so there's no need to add them to exportlist. Also, constants are
embedded directly by value, so they can be omitted too.
Change-Id: Id1879eb97c298a5a52f615cf9883c346c7f7bd69
Reviewed-on: https://go-review.googlesource.com/36170
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Matthew Dempsky [Wed, 1 Feb 2017 23:13:48 +0000 (15:13 -0800)]
cmd/compile/internal/gc: add comment and test for #15550
When switching to the new parser, I changed cmd/compile to handle iota
per an intuitive interpretation of how nested constant declarations
should work (which also matches go/types).
Note: if we end up deciding that the current spec wording is
intentional (i.e., confirming gccgo's current behavior), the test will
need to be updated to expect 4 instead of 1.
Alex Brainman [Tue, 17 Jan 2017 04:06:12 +0000 (15:06 +1100)]
cmd/link: assume that runtime.epclntab lives in .text section
Sometimes STEXT symbols point to the first byte of .data
section, instead of the end of .text section. But, while writing
pe symbol table, we should treat them as if they belong to the
.text section. Change pe symbol table records for these symbols.
Elias Naur [Wed, 1 Feb 2017 11:28:47 +0000 (12:28 +0100)]
misc/ios: use the default go test timeout
If -test.timeout is not specified to go test, it will time out after
a default 10 minutes.
The iOS exec wrapper also contains a fail safe timeout mechanism for
a stuck device. However, if no explicit -test.timeout is specified,
it will use a timeout of 0, plus some constant amount.
Use the same default timeout in the exec wrapper as for go test,
10 minutes.
Change-Id: I6465ccd9f7b9ce08fa302e6697f7938a0ea9af34
Reviewed-on: https://go-review.googlesource.com/36062 Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Elias Naur [Wed, 1 Feb 2017 08:37:47 +0000 (09:37 +0100)]
misc/ios: include the bundle id in the GOIOS_APP_ID env variable
The iOS exec wrapper use the constant bundle id "golang.gotest" for
running Go programs on iOS. However, that only happens to work on
the old iOS builders where their provisioning profile covers
that bundle id.
Expand the detection script to list all available provisioning
profiles for the attached device and include the bundle id in the
GOIOS_APP_ID environment variable.
To allow the old builders to continue, the "golang.gotest" bundle
id is used as a fallback if only the app id prefix is specified in
GOIOS_APP_ID.
For the new builders.
Change-Id: I8baa1d4d57f845de851c3fad3f178e05e9a01b17
Reviewed-on: https://go-review.googlesource.com/36060 Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Elias Naur [Wed, 1 Feb 2017 07:57:46 +0000 (08:57 +0100)]
misc/ios: ignore stderr from iOS tools
On (at least) macOS 10.12, the `security cms` subcommand used by the
iOS detection script will output an error to stderr. The command
otherwise succeeds, but the extra line confuses a later parsing step.
To fix it, use only stdout and ignore stderr from every command run
by detect.go.
For the new iOS builders.
Change-Id: Iee426da7926d7f987ba1be061fa92ebb853ef53d
Reviewed-on: https://go-review.googlesource.com/36059 Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Adam Langley [Mon, 5 Dec 2016 18:24:30 +0000 (10:24 -0800)]
crypto/tls: reject SNI values with a trailing dot.
SNI values may not include a trailing dot according to
https://tools.ietf.org/html/rfc6066#section-3. Although crypto/tls
handled this correctly as a client, it didn't reject this as a server.
This change makes sending an SNI value with a trailing dot a fatal
error.
Adam Langley [Wed, 14 Dec 2016 22:10:26 +0000 (14:10 -0800)]
crypto/x509: add test for v1 intermediates.
X.509v1 certificates are ancient and should be dead. (They are even
prohibited by the Baseline requirements, section 7.1.1.)
However, there are a number of v1 roots from the 1990's that are still
in operation. Thus crypto/x509.Certificate.CheckSignatureFrom allows
X.509v1 certificates to sign other certificates.
The chain building code, however, only allows v1 certificates to sign
others if they're a root. This change adds a test to check that.
Anmol Sethi [Sun, 29 Jan 2017 08:18:17 +0000 (03:18 -0500)]
crypto/tls: document ConnectionState.NegotiatedProtocol more clearly
ConnectionState.NegotiatedProtocol's documentation implies that it will
always be from Config.NextProtos. This commit clarifies that there is no
guarantee.
This commit also adds a note to
ConnectionState.NegotiatedProtocolIsMutual, making it clear that it is
client side only.
Thomas Bonfort [Sun, 1 Jan 2017 16:02:44 +0000 (17:02 +0100)]
image/jpeg: improve performance when encoding *image.YCbCr
The existing implementation falls back to using image.At()
for each pixel when encoding an *image.YCbCr which is
inefficient and causes many memory allocations.
This change makes the jpeg encoder directly read Y, Cb, and Cr
pixel values.
benchmark old ns/op new ns/op delta
BenchmarkEncodeYCbCr-4 4399084624201148 -44.99%
benchmark old MB/s new MB/s speedup
BenchmarkEncodeYCbCr-4 20.95 38.08 1.82x
Alberto Donizetti [Wed, 21 Dec 2016 10:07:11 +0000 (11:07 +0100)]
cmd/compile: never report "truncated to real" for toint calls
Whoever called toint() is expecting the {Mpint, Mpflt, Mpcplx} arg to
be converted to an integer expression, so it never makes sense to
report an error as "constant X truncated to real".
Fixes #11580
Change-Id: Iadcb105f0802358a7f77188c2b1e63fe80c5580c
Reviewed-on: https://go-review.googlesource.com/34638
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Ibrahim AshShohail [Sat, 21 Jan 2017 23:46:25 +0000 (02:46 +0300)]
archive/zip: update the ZIP spec link
Update the link to PKWARE "Application Notes on the .ZIP file format" document.
Now uses the permanent link according to 1.5 in version 6.3.3 (https://pkware.cachefly.net/webdocs/APPNOTE/APPNOTE-6.3.3.TXT):
http://www.pkware.com/appnote
Patrick Pelletier [Thu, 26 Jan 2017 06:09:26 +0000 (22:09 -0800)]
mime/multipart: allow boundary len <= 70
As per RFC 2046, the boundary for multipart MIME is allowed up to 70
characters. The old SetBoundary implementation only allowed up to 69 so
this bumps it to the correct value of 70.
The relevant RFC is at https://www.ietf.org/rfc/rfc2046.txt and section
5.1.1 defines the boundary specification.
Matthew Dempsky [Tue, 31 Jan 2017 22:32:11 +0000 (14:32 -0800)]
cmd/compile: allocate Nodes together with Name/Param/Func
After allocating a Node that needs a Name, Param, and/or Func field,
we never clear that field, so we can reduce GC overhead slightly by
allocating them together with the owner Node.
Matthew Dempsky [Wed, 1 Feb 2017 00:31:11 +0000 (16:31 -0800)]
cmd/compile: simplify noding const declarations
By grouping all the logic into constDecl, we're able to get rid of the
lastconst and lasttype globals, and simplify the logic slightly. Still
clunky, but much easier to reason about.
cmd/compile: disable memory profiling when not in use
The default value of runtime.MemProfileRate
is non-zero, which means that a small portion
of allocations go through the (slow) profiled
allocation path.
This is never useful in the compiler
unless the -memprofile flag has been passed.
I noticed this when samples from mprof.go
showed up in a compiler cpu pprof listing.