1
0
mirror of https://github.com/golang/go synced 2024-09-29 02:24:33 -06:00
Commit Graph

45403 Commits

Author SHA1 Message Date
Cherry Zhang
fd56942fe3 runtime: add a comment about thread pointer alignment on darwin/arm64
Address a review comment in CL 266373.

Change-Id: Ic21bd5c4f87fd0c7dc594155a10fe23602698187
Reviewed-on: https://go-review.googlesource.com/c/go/+/266777
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Austin Clements <austin@google.com>
2020-10-30 22:36:07 +00:00
Michael Anthony Knyszek
64a9a75ce9 runtime: release worldsema with a direct G handoff
Currently worldsema is not released with direct handoff, so the
semaphore is an unfair synchronization mechanism. If, for example,
ReadMemStats is called in a loop, it can continuously stomp on attempts
by the GC to stop the world.

Note that it's specifically possible for ReadMemStats to delay a STW to
end GC since ReadMemStats is able to STW during a GC since #19112 was
fixed.

While this particular case is unlikely and the right answer in most
applications is to simply not call such an expensive operation in a
loop, this pattern is used often in tests.

Fixes #40459.

Change-Id: Ia4a54f0fd956ea145a319f9f06c4cd37dd52fd8a
Reviewed-on: https://go-review.googlesource.com/c/go/+/243977
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: David Chase <drchase@google.com>
2020-10-30 22:21:02 +00:00
Cherry Zhang
f96b62be2e cmd/internal/objabi, runtime: compact FUNCDATA indices
As we deleted register maps, move FUNCDATA indices of stack
objects, inline trees, and open-coded defers earlier.

Change-Id: If73797b8c11fd207655c9498802fca9f6f9ac338
Reviewed-on: https://go-review.googlesource.com/c/go/+/265761
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Austin Clements <austin@google.com>
2020-10-30 21:14:09 +00:00
Cherry Zhang
8414b1a5a4 runtime: remove go115ReduceLiveness and go115RestartSeq
Make them always true. Delete code that are only executed when
they are false.

Change-Id: I6194fa00de23486c2b0a0c9075fe3a09d9c52762
Reviewed-on: https://go-review.googlesource.com/c/go/+/264339
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Austin Clements <austin@google.com>
2020-10-30 21:13:24 +00:00
Michael Pratt
420c68dd68 runtime: tighten systemstack in lock assertions
We use systemstack on the locking path to avoid stack splits which could
cause locks to be recorded out of order (see comment on lockWithRank).

This concern is irrelevant on lock assertions, where we simply need to
see if a lock is held and don't care if another is taken in the
meantime. Thus we can simply drop these unless we actually need to
crash.

Updates #40677

Change-Id: I85d730913a59867753ee1ed0386f8c5efda5c432
Reviewed-on: https://go-review.googlesource.com/c/go/+/266718
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Trust: Michael Pratt <mpratt@google.com>
2020-10-30 21:02:17 +00:00
Cherry Zhang
84d7a85089 cmd/compile: delete register maps, completely
Remove go115ReduceLiveness feature gating flag, along with code
that only needed when go115ReduceLiveness is false.

Change-Id: I7571913cc74cbd17b330a0ee0160fefc9eeee66e
Reviewed-on: https://go-review.googlesource.com/c/go/+/264338
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Austin Clements <austin@google.com>
2020-10-30 20:55:43 +00:00
Michael Pratt
89a6540d8a runtime: elide timer re-check if P has no timers
In golang.org/cl/264477, I missed this new block after rebasing past
golang.org/cl/232298. These fields must be zero if there are no timers.

Updates #28808
Updates #18237

Change-Id: I2d9e1cbf326497c833daa26b11aed9a1e12c2270
Reviewed-on: https://go-review.googlesource.com/c/go/+/266367
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Michael Pratt <mpratt@google.com>
2020-10-30 20:36:27 +00:00
Michael Pratt
9393b5bae5 runtime: add heap lock assertions
Some functions that required holding the heap lock _or_ world stop have
been simplified to simply requiring the heap lock. This is conceptually
simpler and taking the heap lock during world stop is guaranteed to not
contend. This was only done on functions already called on the
systemstack to avoid too many extra systemstack calls in GC.

Updates #40677

Change-Id: I15aa1dadcdd1a81aac3d2a9ecad6e7d0377befdc
Reviewed-on: https://go-review.googlesource.com/c/go/+/250262
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Trust: Michael Pratt <mpratt@google.com>
2020-10-30 20:21:14 +00:00
Michael Pratt
6abbfc17c2 runtime: add world-stopped assertions
Stopping the world is an implicit lock for many operations, so we should
assert the world is stopped in functions that require it.

This is enabled along with the rest of lock ranking, though it is a bit
orthogonal and likely cheap enough to enable all the time should we
choose.

Requiring a lock _or_ world stop is common, so that can be expressed as
well.

Updates #40677

Change-Id: If0a58544f4251d367f73c4120c9d39974c6cd091
Reviewed-on: https://go-review.googlesource.com/c/go/+/248577
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Trust: Michael Pratt <mpratt@google.com>
2020-10-30 20:20:58 +00:00
Michele Di Pede
94b3fd06cb cmd/compile: code cleanup
Change-Id: Ibf68e663f29a5cb3b64a7d923c005c16da647769
Reviewed-on: https://go-review.googlesource.com/c/go/+/266537
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-30 19:48:57 +00:00
Matthew Dempsky
7191f1136b cmd/compile: fix reassignVisitor
reassignVisitor was short-circuiting on assignment statements after
checking the LHS, but there might be further assignment statements
nested within the RHS expressions.

Fixes #42284.

Change-Id: I175eef87513b973ed5ebe6a6527adb9766dde6cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/266618
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-30 19:30:44 +00:00
Cherry Zhang
b53df56001 runtime, cmd: support race detector on darwin/arm64
https://reviews.llvm.org/D90435 is the counterpart in LLVM TSAN.

race_linux_arm64.syso is built with LLVM commit
00da38ce2d36c07f12c287dc515d37bb7bc410e9 on a macOS/ARM64 machine.
(It is not built on a builder with golang.org/x/build/cmd/racebuild
as we don't have darwin/arm64 builder for now.)

Updates #38485.

Change-Id: I391efdacd9480197e308370bfccd05777deb4aee
Reviewed-on: https://go-review.googlesource.com/c/go/+/266373
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-30 19:00:33 +00:00
Bryan C. Mills
6d087c807e cmd/go/internal/modload: handle NotExist errors in (*mvsReqs).Previous
Previous is used during downgrading. If the module proxy does not
advertise any versions (for example, because it contains only
pseudo-versions), then Previous should return "none" instead of a
non-nil error.

For #37438

Change-Id: I4edfec19cfeb3ffe50df4979f99a01321c442509
Reviewed-on: https://go-review.googlesource.com/c/go/+/266370
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-30 18:06:13 +00:00
Bryan C. Mills
8494a6243e cmd/go: make TestScript/mod_get_patchmod self-contained
I find it pretty difficult to reason about test-dependency modules
when they aren't in the same file as the rest of the test.

Now that 'go get' supports replacements (CL 258220 and CL 266018),
we can localize tests that need 'go get' but don't specifically depend
on module proxy semantics.

For #36460
For #37438

Change-Id: Ib37a6c170f251435399dfc23e60d96681a81eadc
Reviewed-on: https://go-review.googlesource.com/c/go/+/266369
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-30 18:06:01 +00:00
Bryan C. Mills
36d412f754 cmd/go/internal/modload: ensure that modRoot and targetPrefix are initialized in DirImportPath
For #37438

Change-Id: I2e1f47d567842ac5504b7b8ed0b3fba6f92d778b
Reviewed-on: https://go-review.googlesource.com/c/go/+/266340
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
2020-10-30 18:05:53 +00:00
Bryan C. Mills
34665c63ff cmd/go/internal/mvs: omit modules at version "none" in BuildList and Req
For #37438

Change-Id: Icb28035ae4027aa09d8959d4ac2f4b94a6c843a7
Reviewed-on: https://go-review.googlesource.com/c/go/+/266339
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
2020-10-30 18:05:46 +00:00
Than McIntosh
fb184a383e cmd/link: emit include directories in DWARF line table prologue
This patch changes the way the linker emits the DWARF line table
prologue, specifically the file table. Previously files were left
unmodified, and the directory table was empty. For each compilation
unit we now scan the unit file table and build up a common set of
directories, emit them into the directory table, and then emit file
entries that refer to the dirs. This provides a modest binary size
savings.

For kubernetes kubelet:

$ objdump -h /tmp/kubelet.old | fgrep debug_line
 36 .zdebug_line  019a55f5  0000000000000000  0000000000000000  084a5123  2**0
$ objdump -h /tmp/kubelet.new | fgrep debug_line
 36 .zdebug_line  01146fd2  0000000000000000  0000000000000000  084a510a  2**0

[where the value following the section name above is the section size
in hex, so roughly a 30% decrease in this case.]

The actual savings will depend on the length of the pathnames
involved, so it's hard to really pin down how much savings we'll see
here. In addition, emitting the files this way reduces the
"compressibility" of the line table, so there could even be cases
where we don't win at all.

Updates #6853, #19784, #36495.

Change-Id: I298d8561da5ed3ebc9d38aa772874851baa2f4f4
Reviewed-on: https://go-review.googlesource.com/c/go/+/263017
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Trust: Than McIntosh <thanm@google.com>
2020-10-30 18:01:54 +00:00
Ian Lance Taylor
e02ab89eb8 runtime: simplify nobarrierWakeTime
Also use the simplified nobarrierWakeTime in findrunnable, as it no
longer needs the current time.

Change-Id: I77b125d6a184dde0aeb517fc068164c274f0a046
Reviewed-on: https://go-review.googlesource.com/c/go/+/266304
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2020-10-30 17:54:57 +00:00
Than McIntosh
a313eec386 reflect,runtime: use internal ABI for selected ASM routines, attempt 2
[This is a roll-forward of CL 262319, with a fix for some Darwin test
failures].

Change the definitions of selected runtime assembly routines
from ABI0 (the default) to ABIInternal. The ABIInternal def is
intended to indicate that these functions don't follow the existing Go
runtime ABI. In addition, convert the assembly reference to
runtime.main (from runtime.mainPC) to ABIInternal. Finally, for
functions such as "runtime.duffzero" that are called directly from
generated code, make sure that the compiler looks up the correct
ABI version.

This is intended to support the register abi work, however these
changes should not have any issues even when GOEXPERIMENT=regabi is
not in effect.

Updates #27539, #40724.

Change-Id: Idf507f1c06176073563845239e1a54dad51a9ea9
Reviewed-on: https://go-review.googlesource.com/c/go/+/266638
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-30 17:41:35 +00:00
Alberto Donizetti
1af388f1c0 cmd/compile: replace int32(a.Off()) calls with a.Off32()
Change-Id: Ib833954e8400a63624359a81f5196ca9080199a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/266081
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-10-30 16:29:11 +00:00
Rob Findley
676ad56095 go/types: reorganize error codes into categories
In CL 264179, some reorganization of error codes was deferred in order
to minimize diffs between patch-sets.

This CL reorganizes the error codes as discussed. It is a pure
reordering, with no material changes other than the changing of internal
const values.

For #42290

Change-Id: I0e9b421a92e96b19e53039652f8de898c5255290
Reviewed-on: https://go-review.googlesource.com/c/go/+/266637
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-30 16:27:42 +00:00
Robert Griesemer
2b9b2720b8 spec: split shift examples into groups for 32- and 64-bit ints
In the current (pre-CL) version of the spec, the 2nd last shift
example appears to be using the array declared in the last example.
On a 32-bit platform, that array would have length 0, which would
lead to a panic in the 2nd last example. Also, if this code were
inside a function, it wouldn't compile (array declared after use).

Use an explicitly declared array for that specific shift example.
Also, split out all cases that produce different results for 32-
vs 64-bit ints.

Fixes #41835.

Change-Id: Ie45114224509e4999197226f91f7f6f934449abb
Reviewed-on: https://go-review.googlesource.com/c/go/+/260398
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-30 16:20:05 +00:00
Michael Pratt
256d729c0b runtime: simplify gcBgMarkWorker preemption
gcBgMarkWorker G's are primarily scheduled by findRunnableGCWorker, but
that no longer needs to be strictly enforced. Temporary preemption to a
runq is fine when the P is not in use.

We still releasem in gopark in the normal case for efficiency: if
gcDrain stops because gp.preempt is set, then gopark would always
preempt. That is fine, but inefficient, since it will reschedule simply
to park again. Thus, we keep releasem in unlockf to skip this extra
cycle.

Change-Id: I6d1a42e3ca41b76227142a6b5bfb376c9213e3c9
Reviewed-on: https://go-review.googlesource.com/c/go/+/262349
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Trust: Michael Pratt <mpratt@google.com>
2020-10-30 15:26:28 +00:00
Michael Pratt
e1faebe7b4 runtime: manage gcBgMarkWorkers with a global pool
Background mark workers perform per-P marking work. Currently each
worker is assigned a P at creation time. The worker "attaches" to the P
via p.gcBgMarkWorker, making itself (usually) available to
findRunnableGCWorker for scheduling GC work.

While running gcMarkDone, the worker "detaches" from the P (by clearing
p.gcBgMarkWorker), since it may park for other reasons and should not be
scheduled by findRunnableGCWorker.

Unfortunately, this design is complex and difficult to reason about. We
simplify things by changing the design to eliminate the hard P
attachment. Rather than workers always performing work from the same P,
workers perform work for whichever P they find themselves on. On park,
the workers are placed in a pool of free workers, which each P's
findRunnableGCWorker can use to run a worker for its P.

Now if a worker parks in gcMarkDone, a P may simply use another worker
from the pool to complete its own work.

The P's GC worker mode is used to communicate the mode to run to the
selected worker. It is also used to emit the appropriate worker
EvGoStart tracepoint. This is a slight change, as this G may be
preempted (e.g., in gcMarkDone). When it is rescheduled, the trace
viewer will show it as a normal goroutine again. It is currently a bit
difficult to connect to the original worker tracepoint, as the viewer
does not display the goid for the original worker (though the data is in
the trace file).

Change-Id: Id7bd3a364dc18a4d2b1c99c4dc4810fae1293c1b
Reviewed-on: https://go-review.googlesource.com/c/go/+/262348
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Trust: Michael Pratt <mpratt@google.com>
2020-10-30 15:25:49 +00:00
Rob Findley
733c4af41d go/types: add internal error codes
Tools using go/types sometimes need to implement special handling for
certain errors produced by the type-checker. They can offer suggested
fixes, expand the error position to surrounding syntax, highlight
related syntax (for example in the case of a declaration cycle), link to
additional documentation, group errors by category, or correlate errors
with signals produced by other static analysis tools.

All these require a notion of error identity. Tools need to be able to
reliably determine the nature of an error without re-implementing type
checking logic or parsing error messages. This CL is a first-pass at
adding such an identifier to types.Error: a (for the moment unexported)
field containing one of many declared errorCode constants.

A wide variety of error code constants are defined, and assigned to type
checker errors according to their 'functional equivalence', meaning that
they should be ideally be stable under refactoring.

With few exceptions, each error code is documented with an example that
produces it. This is enforced by tests.

When error codes are exported they will represent quite a large API
surface. For this reason, as well as the likelihood that error codes
will change at the start, both the code field and the codes themselves
are initially unexported. gopls will read these fields using reflection
during this experimental phase. Others can obviously do the same,
provided they accept the lack of forward compatibility.

For #42290

Change-Id: I15e3c2bffd2046c20297b1857057d421f633098a
Reviewed-on: https://go-review.googlesource.com/c/go/+/264179
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-10-30 14:13:03 +00:00
Cherry Zhang
f7e26467b4 runtime: allocate at desired address when race detector is on
Currently, on all supported platforms, the race detector (LLVM
TSAN) expects the Go heap is at 0xc000000000 - 0xe000000000.
Move the raceenabled condition first, so we always allocate
there.

This means on Linux/ARM64 when race detector is on we will
allocate to 0xc000000000 - 0xe000000000, instead of 0x4000000000.
The old address is meant for 39-bit VMA. But the race detector
only supports 48-bit VMA anyway. So this is fine.

Change-Id: I51ac8eff68297b37c8c651a93145cc94f83a939d
Reviewed-on: https://go-review.googlesource.com/c/go/+/266372
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-30 01:31:10 +00:00
Matthew Dempsky
e62adb1c0b cmd/compile: fix devirtualization of promoted interface methods
A method selector expression can pick out a method or promoted method
(represented by ODOTMETH), but it can also pick out an interface
method from an embedded interface-typed field (represented by
ODOTINTER).

In the case that we're picking out an interface method, we're not able
to fully devirtualize the method call. However, we're still able to
improve escape analysis somewhat. E.g., the included test case
demonstrates that we can optimize "i.M()" to "i.(T).I.M()", which
means the T literal can be stack allocated instead of heap allocated.

Fixes #42279.

Change-Id: Ifa21d19011e2f008d84f9624b7055b4676b6d188
Reviewed-on: https://go-review.googlesource.com/c/go/+/266300
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2020-10-30 00:47:37 +00:00
Robert Griesemer
faa4426811 strings: complete Reader doc string
Follow-up on https://golang.org/cl/247523.

Change-Id: I9e91a6d77271e640d84851f2e2a4c6d2150a2b43
Reviewed-on: https://go-review.googlesource.com/c/go/+/266438
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-30 00:23:50 +00:00
Ben Hoyt
60f42ea61c strconv: fix incorrect bit size in ParseComplex; add tests
In ParseComplex, the "size" passed to parseFloatPrefix should be 64 for
complex128, not 128. It still works because of how parseFloatPrefix
is forgiving about the size if it's not 32, but worth fixing anyway.

Make ParseComplex and ParseFloat return a bit size error for anything
other than 128 or 64 (for ParseComplex), or 64 or 32 (for ParseFloat).
Add "InvalidBitSize" tests for these cases.

Add tests for ParseComplex with bitSize==64: this is done in a similar
way to how the ParseFloat 32-bit tests work, re-using the tests for the
larger bit size.

Add tests for FormatComplex -- there were none before.

Fixes #40706

Change-Id: I16ddd546e5237207cc3b8c2181dd708eca42b04f
Reviewed-on: https://go-review.googlesource.com/c/go/+/248219
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Minux Ma <minux@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-30 00:13:25 +00:00
Norman B. Lancaster
01efc9a3c5 strings: complete documentation of strings.Reader
There is no documentation on a number of methods of the strings.Reader
struct, so this change adds documentation referring to the relevant
io.* interfaces implemented. This is consistent with pre-existing
documentation in this struct.

Fixes #40381

Change-Id: I3dec65ecafca5b79d85d30a676d297e5ee9ab47e
GitHub-Last-Rev: f42429946a
GitHub-Pull-Request: golang/go#40654
Reviewed-on: https://go-review.googlesource.com/c/go/+/247523
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
2020-10-30 00:03:40 +00:00
surechen
f588974a52 math/big: reduce allocations for building decimal strings
Append operations in the decimal String function may cause several allocations.
Use make to pre allocate slices in String that have enough capacity to avoid additional allocations in append operations.

name                 old time/op  new time/op  delta
DecimalConversion-8   139µs ± 7%   109µs ± 2%  -21.06%  (p=0.000 n=10+10)

Change-Id: Id0284d204918a179a0421c51c35d86a3408e1bd9
Reviewed-on: https://go-review.googlesource.com/c/go/+/233980
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Giovanni Bajo <rasky@develer.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Giovanni Bajo <rasky@develer.com>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Giovanni Bajo <rasky@develer.com>
Trust: Martin Möhrmann <moehrmann@google.com>
2020-10-29 22:45:29 +00:00
Rémy Oudompheng
f43e012084 strconv: make Eisel-Lemire handle long mantissas
In many cases, it is not necessary to parse long
decimal mantissas entirely to produce the correctly
rounded floating-point number. It is enough to parse
the short, rounded lower and upper bounds and in most cases
they round to the same floating point number because uint64
can hold 19 digits.

Previously this case was handled by the extFloat code path
(Grisu3 algorithm).

name                      old time/op  new time/op  delta
Atof64Big-4               1.07µs ± 2%  0.11µs ± 2%  -89.61%  (p=0.000 n=10+9)
Atof64RandomLongFloats-4  8.03µs ± 2%  0.14µs ± 7%  -98.24%  (p=0.000 n=10+10)
Atof32RandomLong-4         760ns ± 1%   156ns ± 0%  -79.46%  (p=0.000 n=10+8)

Benchmarks versus extFloat:

name                      old time/op  new time/op  delta
Atof64Big-4                121ns ± 3%   111ns ± 2%   -7.93%  (p=0.000 n=10+9)
Atof64RandomLongFloats-4   144ns ± 1%   142ns ± 7%     ~     (p=0.167 n=10+10)
Atof32RandomLong-4         129ns ± 1%   156ns ± 0%  +21.12%  (p=0.000 n=10+8)

Change-Id: Id734b8c11e74b49a444fda67ee72870ae9422e60
Reviewed-on: https://go-review.googlesource.com/c/go/+/264677
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2020-10-29 22:44:49 +00:00
Cherry Zhang
75789880a6 cmd/link: put C static symbols in the symbol table, attempt 2
We don't put Go static symbols in the symbol table, as they are
always compiler-generated (there is no way to define a static
symbol in user code in Go). We retain static symbols in assembly
code, as it may be user-defined. Also retain static symbols in C.

This is the second attempt of CL 263259, which was reverted
because it broke AIX tests in that it brought TOC.stmp symbols
in the symbol table. This time we use SymPkg(s) == "" to identify
non-Go symbols, instead of IsExternal(s), as the latter also
includes linker-modified Go symbols.

Change-Id: I5c752c54f0fc6ac4cde6a0e8161dac5b72a47d56
Reviewed-on: https://go-review.googlesource.com/c/go/+/266237
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2020-10-29 22:44:12 +00:00
Brad Fitzpatrick
fe70a3a0fd crypto/x509: add comment to blank imports done for init side effects
To educate future readers.

Change-Id: I1ef79178b6997cc96ca066c91b9fec822478674b
Reviewed-on: https://go-review.googlesource.com/c/go/+/266301
Reviewed-by: Katie Hockman <katie@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Katie Hockman <katie@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2020-10-29 21:46:54 +00:00
Russ Cox
9a1596689e go/build: remove two erroneous uses of os.Stat
go/build should use the ctxt routines, not os directly.
These snuck in.

Change-Id: I918d4de923eb485bfd524e4f1b1310a7a165ad03
Reviewed-on: https://go-review.googlesource.com/c/go/+/266357
Trust: Russ Cox <rsc@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-10-29 20:55:24 +00:00
Russ Cox
09d5e0d119 api: update next.txt
The output from all.bash has gotten big again.

Change-Id: Ia2399d78c1fd443fd8de03c25655e2f84bd89886
Reviewed-on: https://go-review.googlesource.com/c/go/+/266397
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-10-29 20:51:49 +00:00
Russ Cox
38d1ec8c9d cmd/internal/obj: use panic instead of log.Fatalf for two messages
These messages can happen if there are
duplicate body-less function declarations.
Using panic gives the panic handler
a chance to handle the panic by printing the
queued error messages instead of an internal error.

And if there are no queued error messages,
using panic pinpoints the stack trace leading
to the incorrect use of NewFuncInfo/NewFileInfo.

Change-Id: I7e7ea9822ff9a1e7140f5e5b7cfd6437ff9318a7
Reviewed-on: https://go-review.googlesource.com/c/go/+/266338
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-29 20:50:02 +00:00
Matthew Dempsky
aa4f48b751 cmd/compile: gracefully fail when devirtualization fails
We should still be able to devirtualize here, but I need to understand
the AST better. While I'm doing that, at least switch to a graceful
failure case (i.e., skip the optimization and print a warning message)
to fix the x/text builders.

Updates #42279.

Change-Id: Ie2b0b701fccf590d0cabfead703fc2fa999072cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/266359
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-29 20:19:24 +00:00
Matthew Dempsky
5cc43c51c9 cmd/compile: early devirtualization of interface method calls
After inlining, add a pass that looks for interface calls where we can
statically determine the interface value's concrete type. If such a
case is found, insert an explicit type assertion to the concrete type
so that escape analysis can see it.

Fixes #33160.

Change-Id: I36932c691693f0069e34384086d63133e249b06b
Reviewed-on: https://go-review.googlesource.com/c/go/+/264837
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2020-10-29 19:06:32 +00:00
Matthew Dempsky
f2c0c2b902 cmd/compile: improve inlining and static analysis
When inlining a function call "f()", if "f" contains exactly 1
"return" statement and doesn't name its result parameters, it's
inlined to declare+initialize the result value using the AST
representation that's compatible with staticValue.

Also, extend staticValue to skip over OCONVNOP nodes (often introduced
by inlining), and fix various bits of code related to handling method
expressions.

Updates #33160.

Change-Id: If8652e319f0a5700cf9d40a7a62e369a2a359229
Reviewed-on: https://go-review.googlesource.com/c/go/+/266199
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2020-10-29 19:03:09 +00:00
Joel Sing
0b798c46cd cmd/link: add loadelf support for riscv64
Update #36641

Change-Id: I8618da30d8940a56d6cc86a37a2f54b31ee029e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/263601
Trust: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-29 18:26:42 +00:00
Joel Sing
2e6f50020c Revert "cmd/compile,cmd/internal/sys: enable additional build modes on linux/riscv64"
This reverts CL 263457.

It turns out that this still missed changes to cmd/link/internal/ld/config.go
and some of these build modes also fail once cgo is enabled. Disable again for
now.

Change-Id: Iaf40d44e1551afd5b040d357f04af134f55a64a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/266317
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Trust: Joel Sing <joel@sing.id.au>
2020-10-29 18:26:18 +00:00
Andrew G. Morgan
3a819e8998 syscall: handle undefined r2 value on linux-ppc64x
This change fixes two failng tests on linux-ppc64x:

- TestAllThreadsSyscall() exposed a real bug in the ppc64x support:
  - It turns out that the r2 syscall return value is not defined
    on all architectures. Notably linux-ppc64x so address that by
    introducing a private architectural constant in the syscall
    package, archHonorsR2: true if r2 has a determanistic value.

- TestSetuidEtc() was sensitive to /proc/<PID>/status content:
  - The amount of padding space has changed with kernel vintage.
  - Stress testing revealed a race with /proc files disappearing.

Fixes #42178

Change-Id: Ie6fc0b8f2f94a409ac0e5756e73bfce113274709
Reviewed-on: https://go-review.googlesource.com/c/go/+/266202
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-29 17:53:57 +00:00
Branden J Brown
4fb4291388 cmd/compile: inline functions evaluated in go and defer statements
The inlining pass previously bailed upon encountering a go or defer statement, so it would not inline functions e.g. used to provide arguments to the deferred function. This change preserves the behavior of not inlining the
deferred function itself, but it allows the inlining walk to proceed into its arguments.

Fixes #42194

Change-Id: I4e82029d8dcbe69019cc83ae63a4b29af45ec777
Reviewed-on: https://go-review.googlesource.com/c/go/+/264997
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2020-10-29 16:47:10 +00:00
Russ Cox
25d28ec55a cmd/go: add //go:embed support
The final piece of //go:embed support: have the go command stitch
together parsing in go/build, low-level data initialization in cmd/compile,
and the new data structures in package embed, to make the //go:embed
feature actually function.

And test, now that all the pieces are available to work together.

For #41191.
(Issue not fixed: still need to add a tool for use by Bazel.)

Change-Id: Ib1d198345c3b4d557d340f292eda13b984b65d65
Reviewed-on: https://go-review.googlesource.com/c/go/+/243945
Trust: Russ Cox <rsc@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
Trust: Johan Brandhorst <johan.brandhorst@gmail.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Johan Brandhorst <johan.brandhorst@gmail.com>
2020-10-29 16:26:43 +00:00
Than McIntosh
ddc7e1d16f Revert "reflect,runtime: use internal ABI for selected ASM routines"
This reverts commit 50af50d136.

Reason for revert: Causes failures in the runtime package test on Darwin, apparently.

Change-Id: I006bc1b3443fa7207e92fb4a93e3fb438d4d3de3
Reviewed-on: https://go-review.googlesource.com/c/go/+/266257
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-10-29 15:58:40 +00:00
Bryan C. Mills
1524680709 cmd/go: allow 'go get' to downgrade to replacement-only versions
This fixes a case missed in CL 258220.

For #36460
Updates #26241
Updates #37438

Change-Id: I5e8c2ee1e08e41cc2eb34e54c617cb5e4bf69c5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/266018
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-10-29 15:56:41 +00:00
Katie Hockman
68e30af111 Revert "crypto/x509: fix duplicate import"
This reverts CL 250497. It also moves all blank identifier imports below the rest of the imports for clarity.

Reason for revert: The blank identifier import was intentional to show that it's needed for its registration side effect. The duplicate import should stay since it communicates that the side-effect is important to tools and to future developers updating this file.

Change-Id: I626e6329db50f47453aa71085a05d21bf6efe0ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/265078
Run-TryBot: Katie Hockman <katie@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-10-29 15:27:22 +00:00
Than McIntosh
50af50d136 reflect,runtime: use internal ABI for selected ASM routines
Change the definitions of selected runtime assembly routines
from ABI0 (the default) to ABIInternal. The ABIInternal def is
intended to indicate that these functions don't follow the existing Go
runtime ABI. In addition, convert the assembly reference to
runtime.main (from runtime.mainPC) to ABIInternal. Finally, for
functions such as "runtime.duffzero" that are called directly from
generated code, make sure that the compiler looks up the correct
ABI version.

This is intended to support the register abi work, however these
changes should not have any issues even when GOEXPERIMENT=regabi is
not in effect.

Updates #27539, #40724.

Change-Id: I9846f8dcaccc95718cf2e61a18b7e924a0677e4c
Reviewed-on: https://go-review.googlesource.com/c/go/+/262319
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-10-29 15:13:09 +00:00
Alberto Donizetti
ecb79e8afa cmd/compile: run rulegen to include missing condition
Rulegen was not run again between patchsets 2 and 3 of CL 264683, so
the rewritegeneric.go file is out of sync. Run rulegen.

Change-Id: I67d8d267c4f666943ed9bf8c33aac2ac6013336a
Reviewed-on: https://go-review.googlesource.com/c/go/+/266080
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rémy Oudompheng <remyoudompheng@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
2020-10-29 15:11:47 +00:00