encoding/json: reduce allocated space in Unmarshal
The decodeState type is a large part of the allocated space during Unmarshal.
The errorContext field is infrequently used, and only on error.
Extract it into a pointer and allocate it separate when necessary.
This test contained a data race.
On line 437, db.BeginTx starts a goroutine that runs tx.awaitDone,
which reads tx.keepConnOnRollback.
On line 445, the test writes to tx.keepConnOnRollback.
tx.awaitDone waits on ctx, but because ctx is timeout-based,
there's no ordering guarantee between the write and the read.
The race detector never caught this before
because the context package implementation of Done
contained enough synchronization to make it safe.
That synchronization is not package of the context API or guarantees,
and the first several releases it was not present.
Another commit soon will remove that synchronization,
exposing the latent data race.
To fix the race, emulate a time-based context
using an explicit cancellation-based context.
This gives us enough control to avoid the race.
Rob Findley [Tue, 23 Feb 2021 17:01:26 +0000 (12:01 -0500)]
go/types: review of call.go
The changes from the (reviewed) dev.regabi copy of call.go can be seen
by comparing patchset 1 and 4. The actual changes are removing the
"// REVIEW INCOMPLETE" marker, deleting some leftover handling of type
instantiation in Checker.call, and adding a comment that exprOrTypeList
should be refactored.
I started to refactor exprOrTypeList, but thought it best to mark this
code as reviewed before diverging from types2.
Change-Id: Icf7fbff5a8def49c5f1781472fd7ba7b73dd9a9c
Reviewed-on: https://go-review.googlesource.com/c/go/+/295531
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
DQNEO [Wed, 10 Feb 2021 13:34:09 +0000 (22:34 +0900)]
spec: improve sentence structure for passing a slice
Change-Id: I453d06da2f596eb0b99905aec46a05547d73c62c
Reviewed-on: https://go-review.googlesource.com/c/go/+/290872
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Robert Griesemer <gri@golang.org>
Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Rob Pike <r@golang.org>
David Benjamin [Fri, 25 Dec 2020 17:02:55 +0000 (12:02 -0500)]
unicode: correctly handle negative runes
Is and isExcludingLatin did not handle negative runes when dispatching
to is16. TestNegativeRune covers this along with the existing uint32
casts in IsGraphic, etc. (For tests, I picked the smallest non-Latin-1
code point in each range.)
Updates #43254
Change-Id: I17261b91f0d2b5b5125d19219411b45c480df74f
Reviewed-on: https://go-review.googlesource.com/c/go/+/280493
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Andy Pan [Tue, 10 Nov 2020 09:56:33 +0000 (17:56 +0800)]
image: resolve the TODO of doc comment style
Change-Id: Ic7701a9e4635fe1a331c9a1df776ed580759eb9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/268758 Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Trust: Nigel Tao <nigeltao@golang.org>
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Trust: Rob Pike <r@golang.org>
Rob Findley [Tue, 23 Feb 2021 16:48:15 +0000 (11:48 -0500)]
go/types: minor updates to comments to align with types2
Change-Id: Ic4fcd67cd9222eae6b72d9e91e37f3b0293b0b8d
Reviewed-on: https://go-review.googlesource.com/c/go/+/295530 Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Daniel S. Fava [Fri, 12 Feb 2021 08:54:50 +0000 (09:54 +0100)]
testing/race: fixing intermittent test failure
Test NoRaceMutexPureHappensBefore in runtime/race/testdata/mutex_test.go
expects the second spawned goroutine to run after the first. The test
attempts to force this scheduling with a 10 millisecond wait. Following
a suggestion by Bryan Mills, we force this scheduling using a shared
variable whose access take place within the existing mutex.
Fixes #35745.
Change-Id: Ib23ec51492ecfeed4752e020401dd25755a669ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/291292 Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Robert Griesemer [Tue, 23 Feb 2021 20:47:08 +0000 (12:47 -0800)]
go/types, types2: constraints may be parenthesized and that includes "any"
Change-Id: I9a234cc1f04ca762375b51ec8ef009fb264c7ed1
Reviewed-on: https://go-review.googlesource.com/c/go/+/295689
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Dmitri Shuralyov [Mon, 22 Feb 2021 22:21:10 +0000 (17:21 -0500)]
doc: start draft go1.17 release notes, move go1.16 to x/website
This template is based on CL 248198 and previous ones like it.
Continue to eagerly include often-used sections, and clarify that
the TODO is about completing the section, or removing if it turns
out not to be needed.
Move the Go 1.16 release notes to x/website, since that's the new
home for past Go release notes as of CL 291711. They're added to
x/website in CL 295249.
'relnote -html' does not report any CLs with RELNOTE annotations
since 2021/02/01.
For #44513.
Updates #40700.
Change-Id: Idd389335500ec4dec2764cbbaa385918cc8a79ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/295209
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Alexander Rakoczy <alex@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org>
Keith Randall [Wed, 3 Feb 2021 20:25:46 +0000 (12:25 -0800)]
runtime: use BX instead of R15 in race detector
If the race detector were runnable in dynamic linking mode,
then R15 would get clobbered. I don't think it is, so maybe
not a problem, but can't hurt to clean it up.
It also lets CL 283474 pass cleanly when checking the whole stdlib
(together with CL 288452).
Change-Id: I5a5021ecc7e7b8bed1cd3a7067c39b24c09e0783
Reviewed-on: https://go-review.googlesource.com/c/go/+/289270
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Keith Randall [Mon, 1 Feb 2021 08:45:41 +0000 (00:45 -0800)]
runtime: save R15 before checking AVX state
When in dynlink mode, reading a global can clobber R15.
Just to be safe, save R15 before checking the AVX state to see
if we need to VZEROUPPER or not.
This could cause a problem in buildmodes that aren't supported yet.
Keith Randall [Wed, 9 Dec 2020 22:59:40 +0000 (14:59 -0800)]
cmd/compile: fold MOV*nop and MOV*const
MOV*nop and MOV*reg seem superfluous. They are there to keep type
information around that would otherwise get thrown away. Not sure
what we need it for. I think our compiler needs a normalization of
how types are represented in SSA, especially after lowering.
MOV*nop gets in the way of some optimization rules firing, like for
load combining.
For now, just fold MOV*nop and MOV*const. It's certainly safe to
do that, as the type info on the MOV*const isn't ever useful.
R=go1.17
Change-Id: I3630a80afc2455a8e9cd9fde10c7abe05ddc3767
Reviewed-on: https://go-review.googlesource.com/c/go/+/276792
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
zhengjianxun [Tue, 23 Feb 2021 03:12:56 +0000 (03:12 +0000)]
runtime: clarify GC fractional mode description
nowdays, in runtime/mgc.go,we can see the comment descrition : The fractional worker is necessary when GOMAXPROCS*gcBackgroundUtilization is not an integer.
but it not true such as GOMAXPROCS=5.
in the implemet of startCycle() , Fractional Mode happend only when
GOMAXPROCS<=3 or GOMAXPROCS=6. so utilization can closest to 25%.
Fixes #44380
Joel Sing [Mon, 30 Nov 2020 12:47:27 +0000 (23:47 +1100)]
cmd/compile: change riscv64 Eq32/Neq32 to zero extend before subtraction
As done with other equality tests, zero extend before subtraction rather than
after (or in this case, at the same time). While at face value this appears to
require more instructions, in reality it allows for most sign extensions to
be completely eliminated due to correctly typed loads. Existing optimisations
(such as subtraction of zero) then become more effective.
This removes more than 10,000 instructions from the Go binary and in particular,
a writeBarrier check only requires three instructions (AUIPC, LWU, BNEZ) instead
of the current four (AUIPC, LWU, NEGW, BNEZ).
Change-Id: I7afdc1921c4916ddbd414c3b3f5c2089107ec016
Reviewed-on: https://go-review.googlesource.com/c/go/+/274066
Trust: Joel Sing <joel@sing.id.au> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Russ Cox [Tue, 23 Feb 2021 16:38:24 +0000 (11:38 -0500)]
runtime: fix usleep on windows/arm
Changed calling convention to pre-multiply the argument by -100,
and then deleted the * 100 but not the negation in the windows/arm assembly.
Delete the negation.
Fixes the current all.bash breakage on windows/arm builder.
(Maybe that will uncover more.)
This is partial plumbing recycled from the original register abi test work;
these are the parts that translate easily. Some other bits are deferred till
later when they are ready to be used.
Keith Randall [Fri, 12 Feb 2021 23:55:25 +0000 (15:55 -0800)]
cmd/compile: improve bit test code
Some bit test instruction generation stopped triggering after
the change to addressing modes. I suspect this was just because
ANDQload was being generated before the rewrite rules could discover
the BTQ. Fix that by decomposing the ANDQload when it is surrounded
by a TESTQ (thus re-enabling the BTQ rules).
Jason A. Donenfeld [Mon, 15 Feb 2021 19:20:15 +0000 (20:20 +0100)]
cmd/go: recognize DLL magic from llvm binaries
When using LLD with c-shared, the magic in the output DLL is slightly
different than for EXEs.
Change-Id: Icc5f34f7bb61f11a9d75494236b7797cc1988b40
Reviewed-on: https://go-review.googlesource.com/c/go/+/291638
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
Cherry Zhang [Tue, 23 Feb 2021 00:45:21 +0000 (19:45 -0500)]
cmd/compile: guard special register usage with GOEXPERIMENT=regabi
Previously, some special register uses are only guarded with ABI
wrapper generation (-abiwrap). This CL makes it also guarded with
the GOEXPERIMENT. This way we can enable only the wrapper
generation without fully the new ABI, for benchmarking purposes.
Change-Id: I90fc34afa1dc17c9c73e7b06e940e79e4c4bf7f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/295289
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
Andy Pan [Tue, 10 Nov 2020 13:02:18 +0000 (21:02 +0800)]
runtime: optimize the memory padding in p struct
Since allocation for p struct will be rounded up to the next size class,
the two relevant adjacent classes for this case are 9728 bytes and 10240 bytes.
A p is currently 10072 bytes, so it gets rounded up to 10240 bytes when we allocate one,
So the pad in p struct is unnecessary, eliminate it and add comments for
warning the false sharing.
Change-Id: Iae8b32931d1beddbfff1f58044d8401703da6407
Reviewed-on: https://go-review.googlesource.com/c/go/+/268759 Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
Jason A. Donenfeld [Sun, 14 Feb 2021 18:43:31 +0000 (19:43 +0100)]
runtime/cgo: use correct lean and mean macro
WIN64_LEAN_AND_MEAN is not the correct macro to use and doesn't ever
exist.
Change-Id: I32a5523cc0f7cc3f3a4d022071cf81f88db39aa9
Reviewed-on: https://go-review.googlesource.com/c/go/+/291634
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Change-Id: I8766104508f7acd832088a590ee7d68afa0d6065
Reviewed-on: https://go-review.googlesource.com/c/go/+/291633
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
Change-Id: Iffd2345d757f23dd737e63bd464cd412527077c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/291632
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
Jason A. Donenfeld [Sat, 13 Feb 2021 23:04:48 +0000 (00:04 +0100)]
cmd/link: set SizeOfRawData rather than VirtualSize in COFF files for .bss section
GCC and Clang both set the SizeOfRawData field rather than the
VirtualSize field for communicating the size of the .bss section. As a
consequence, LLD does not look at VirtualSize and collapses the .bss
section into whatever is around it, resulting in runtime crashes. This
commit changes the logic so that if the requested "file size" is 0, then
the SizeOfRawData field is set rather than the VirtualSize field as the
sole length marker.
Change-Id: Ied89ddaa0a717fed840238244c6e4848845aeeb6
Reviewed-on: https://go-review.googlesource.com/c/go/+/291630
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
Than McIntosh [Wed, 6 Jan 2021 18:27:17 +0000 (13:27 -0500)]
cmd/internal/dwarf: minor cleanups
Remove a stale comment, demote PutInlinedFunc from public to private,
and remove an unused interface originally used for sorting vars.
No change in functionality.
Change-Id: I5ee1ad2b10b78b158e2223c6979bab830202db95
Reviewed-on: https://go-review.googlesource.com/c/go/+/295009
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Joel Sing [Mon, 7 Dec 2020 17:14:34 +0000 (04:14 +1100)]
runtime: enable race detector on openbsd/amd64
Now that this commit[1] has landed in LLVM the .syso file can be generated for
OpenBSD.
With the changes to src/runtime running the sample race[2] detects the data
race as expected.
Based on golang/go#39464 (https://go-review.googlesource.com/c/go/+/237057) from
Aaron Bieber <deftly@gmail.com>, however the race_openbsd_amd64.syso file has
been built on OpenBSD 6.4 and necessary changes added to race.bash.
Change-Id: Ic2479ccfa91d6b2cb4585346a11d813d96450f68
Reviewed-on: https://go-review.googlesource.com/c/go/+/275892
Trust: Joel Sing <joel@sing.id.au>
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Joel Sing [Wed, 17 Feb 2021 10:03:59 +0000 (21:03 +1100)]
cmd/internal/obj/riscv: prevent constant loads that do not target registers
Check that the target of a constant load is a register and add test coverage
for this error condition. While here, rename the RISC-V testdata and tests
to be consistent with other platforms.
Change-Id: I7fd0bfcee8cf9df0597d72e65cd74a2d0bfd349a
Reviewed-on: https://go-review.googlesource.com/c/go/+/292895
Trust: Joel Sing <joel@sing.id.au> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Cuong Manh Le [Wed, 17 Feb 2021 04:38:14 +0000 (11:38 +0700)]
cmd/compile: remove selectnbrecv2
Previous CL did remove selectnbrecv2 in runtime, the compiler now only
call selectnbrecv, so remove this. Make this as separated CL because it
adds much of noise to git stat.
Change-Id: I06e89c823c0403e9bd66f2633409c455a46d6e79
Reviewed-on: https://go-review.googlesource.com/c/go/+/292891
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Cuong Manh Le [Wed, 17 Feb 2021 04:36:58 +0000 (11:36 +0700)]
cmd/compile,runtime: make selectnbrecv return two values
The only different between selectnbrecv and selectnbrecv2 is the later
set the input pointer value by second return value from chanrecv.
So by making selectnbrecv return two values from chanrecv, we can get
rid of selectnbrecv2, the compiler can now call only selectnbrecv and
generate simpler code.
Change-Id: Ifaf6cf1314c4f47b06ed9606b1578319be808507
Reviewed-on: https://go-review.googlesource.com/c/go/+/292890
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Cuong Manh Le [Fri, 27 Nov 2020 19:46:00 +0000 (02:46 +0700)]
cmd/compile: use transitive relations for slice len/cap in poset
Currently, we keep track of slice len by mapping from slice ID to
len/cap SSA value. However, slice len/cap can have multiple SSA values,
so when updating fact table for slice len/cap, we only update in one
place.
Instead, we can take advantage of the transitive relations provided by
poset. So all duplicated slice lens are set as equal to one another.
When updating fact table for one, that fact will be reflected to all
others. The same mechanism is applied for slice cap.
Removes 15 bounds checks from std/cmd.
Fixes #42603
Change-Id: I32c07968824cc33765b1e441b3ae2c4b5f5997c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/273670
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Robert Griesemer [Sat, 20 Feb 2021 04:06:24 +0000 (20:06 -0800)]
cmd/compile/internal/types2: review of sanitize.go
Remove the "// UNREVIEWED" marker and add guards (as in go/types)
to prevent data races. To see the added guards, see compare patch
sets 3 and 4. The equivalent changes for go/types were done in
https://golang.org/cl/294411.
Change-Id: Ibef07eaae400bd32bff32b102cc743580290d135
Reviewed-on: https://go-review.googlesource.com/c/go/+/294510
Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Robert Griesemer [Tue, 23 Feb 2021 01:02:46 +0000 (17:02 -0800)]
go/types, cmd/compile/internal/types2: use regular type printing for unsafe.Pointer
Type string printing special-cased printing of unsafe.Pointer because
it's a built-in type; yet it's declared in a package like any other
imported or used-defined type (unlike built-in types such as int).
Use the same mechanism for printing unsafe.Pointer like any other
(non-basic) type. This will make it possible to use the package
Qualifier if so desired.
Fixes #44515.
Change-Id: I0dd1026f850737ecfc4bb99135cfb8e3c18be9e7
Reviewed-on: https://go-review.googlesource.com/c/go/+/295271
Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Robert Griesemer [Sat, 20 Feb 2021 04:00:33 +0000 (20:00 -0800)]
cmd/compile/internal/types2: review of conversions.go
The changes between (equivalent, and reviewed) go/types/conversions.go
and conversions.go can be seen by comparing patchset 1 and 2. The actual
change is just removing the "// UNREVIEWED" marker.
Change-Id: I86d20d8100ec29fe3be996b975c9b4aff01be85e
Reviewed-on: https://go-review.googlesource.com/c/go/+/294509
Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Robert Griesemer [Sat, 20 Feb 2021 00:58:24 +0000 (16:58 -0800)]
cmd/compile/internal/types2: review of issues_test.go
The changes between (equivalent, and reviewed) go/types/issues_test.go
and issues_test.go can be seen by comparing patchset 1 and 3. The actual
change is just removing the "// UNREVIEWED" marker and making making
some minor code adjustments to match go/types's version more closely.
Change-Id: I26f3f700d12db69fc68161a6b0dc081a0e9cd0d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/294473
Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Dan Scales [Fri, 19 Feb 2021 17:40:35 +0000 (09:40 -0800)]
cmd/compile: fix import of functions of multiple nested closure
For import of functions with closures, the connections among closure
variables are constructed on-the-fly via CaptureName(). For multiple
nested closures, we need to temporarily set r.curfn to each closure we
construct, so that the processing of closure variables will be correct
for any nested closure inside that closure.
Fixes #44335
Change-Id: I34f99e2822250542528ff6b2232bf36756140868
Reviewed-on: https://go-review.googlesource.com/c/go/+/294212
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Dan Scales <danscales@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
yangwenmai [Fri, 25 Dec 2020 01:36:41 +0000 (09:36 +0800)]
all: faster midpoint computation in binary search
On my machine (3.1 GHz Quad-Core Intel Core i7, macOS 10.15.7 10.15.7), go 1.15.6
benchstat:
name old time/op new time/op delta
SearchInts-8 20.3ns ± 1% 16.6ns ± 6% -18.37% (p=0.000 n=9+10)
Change-Id: I346e5955fd6df6ce10254b22267dbc8d5a2b16c0
Reviewed-on: https://go-review.googlesource.com/c/go/+/279439 Reviewed-by: Ben Shi <powerman1st@163.com> Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Rob Findley [Mon, 22 Feb 2021 20:39:00 +0000 (15:39 -0500)]
go/parser: return ast.BadExpr for missing index operands
The parser was returning the indexed operand when a slice or index or
instance expression was missing any index arguments (as in the
expression `a[]`). This can result in returning an *ast.Ident for the
LHS of the (invalid) assignment `a[] = ...` -- in this case parsing the
LHS as just `a`. Unfortunately, as the indexed operand `a` has already
been resolved, this results in a panic for duplicate resolution.
Fix this by instead returning an ast.BadExpr. This can suppress some
subsequent errors from the typechecker, but those errors may or may not
be correct anyway. Other interpretations, such as an *ast.IndexExpr with
bad or missing X, run into potential misinterpretations downstream (both
caused errors in go/types and/or gopls).
Fixes #44504
Change-Id: I5ca8bed4a1861bcc7db8898770b08937110981d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/295151
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Cherry Zhang [Mon, 22 Feb 2021 22:43:08 +0000 (17:43 -0500)]
cmd/compile: correctly use X15 to zero frame
In CL 288093 we reserve X15 as the zero register and use that to
zero values. It only covered zeroing generated in SSA but missed
zeroing the frame generated late in the compilation. The latter
still uses X0, but now DUFFZERO expects X15, so it doesn't
actually zero the frame. Change it to use X15.
Should fix #44333.
Change-Id: I239d2b78a5f6468bc86b70aecdd294045311759f
Reviewed-on: https://go-review.googlesource.com/c/go/+/295210
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
cmd/compile: reject some rare looping CFGs in shortcircuit
One CFGs that shortcircuit looks for is:
p q
\ /
b
/ \
t u
The test case creates a CFG like that in which p == t.
That caused the compiler to generate a (short-lived) invalid phi value.
Fix this with a relatively big hammer: Disallow single-length loops entirely.
This is probably overkill, but it such loops are very rare.
This doesn't change the generated code for anything in std.
It generates worse code for the test case:
It no longer compiles the entire function away.
Than McIntosh [Fri, 19 Feb 2021 15:34:55 +0000 (10:34 -0500)]
go/internal/gccgoimporter: fix up gccgo installation test
Change the TestInstallationImporter testpoint to query type
information for sort.Search instead of sort.Ints. The latter function
changed recently (1.16 timeframe), parameter "a" is now "x". A better
candidate for this sort of query is sort.Search, which has been stable
for a while.
Fixes #44425.
Change-Id: I314476eac0b0802f86f5cbce32195cab2926db83
Reviewed-on: https://go-review.googlesource.com/c/go/+/294290
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Than McIntosh [Fri, 19 Feb 2021 15:09:15 +0000 (10:09 -0500)]
cmd/compile: fix panic in DWARF-gen handling obfuscated code
DWARF generation uses variable source positions (file/line/col) as a
way to uniquely identify locals and parameters, as part of the process
of matching up post-optimization variables with the corresponding
pre-optimization versions (since the DWARF needs to be in terms of the
original source constructs).
This strategy can run into problems when compiling obfuscated or
machine-generated code, where you can in some circumstances wind up
with two local variables that appear to have the same name, file,
line, and column. This patch changes DWARF generation to skip over
such duplicates as opposed to issuing a fatal error (if an
obfuscation tool is in use, it is unlikely that a human being will be
able to make much sense of DWARF info in any case).
Fixes #44378.
Change-Id: I198022d184701aa9ec3dce42c005d29b72d2e321
Reviewed-on: https://go-review.googlesource.com/c/go/+/294289
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
Ian Lance Taylor [Sat, 20 Feb 2021 19:25:15 +0000 (11:25 -0800)]
syscall: add explicit ios build tag
This permits analysis of the syscall package by tools built with
older versions of Go that do not recognize ios as a GOOS.
Fixes #44459
Change-Id: I79cec2ffe0dbcbc2dc45a385e556dc9e62033125
Reviewed-on: https://go-review.googlesource.com/c/go/+/294634
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Alberto Donizetti [Sat, 20 Feb 2021 16:53:43 +0000 (17:53 +0100)]
doc/1.16: fix link to fs.FileInfo
Updates #40700
Change-Id: Ifff622ccadaa31c0c0684c3c695aadcaa2305623
Reviewed-on: https://go-review.googlesource.com/c/go/+/294669
Trust: Alberto Donizetti <alb.donizetti@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Russ Cox [Fri, 26 Jun 2020 20:22:35 +0000 (16:22 -0400)]
go/printer: canonicalize //go:build and // +build lines while formatting
Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild
Gofmt and any other go/printer-using program will now:
- move //go:build and //+build lines to the appropriate file location
- if there's no //go:build line, add one derived from the // +build lines
- if there is a //go:build line, recompute and replace any // +build lines
to match what the //go:build line says
For Go 1.17.
Change-Id: Ide5cc3b4a07507ba9ed6f8b0de846e840876f49f
Reviewed-on: https://go-review.googlesource.com/c/go/+/240608
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>
Russ Cox [Mon, 22 Jun 2020 17:27:10 +0000 (13:27 -0400)]
go/build: prefer //go:build over // +build lines
Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild
- Reject files with multiple //go:build lines.
- If a file has both //go:build and // +build lines, only use the //go:build line.
- Otherwise fall back to // +build lines
- Use go/build/constraint for parsing both //go:build and // +build lines.
For Go 1.17.
Change-Id: I32e2404d8ce266230f767718dc7cc24e77b425e8
Reviewed-on: https://go-review.googlesource.com/c/go/+/240607
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Robert Griesemer [Wed, 17 Feb 2021 05:05:08 +0000 (21:05 -0800)]
spec: every type has a method set (minor clarification)
The spec states that a type "may" have a method set associated with it.
Yet every type has a method set, which may be empty. This is clarified
later in the same paragraph. Be clear in the first sentence as well.
Per the suggestion from https://github.com/DQNEO.
Fixes #44318.
Change-Id: I6097b1c7062853e404b7fead56d18a7f9c576fc3
Reviewed-on: https://go-review.googlesource.com/c/go/+/292853
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Rob Findley [Fri, 19 Feb 2021 22:37:17 +0000 (17:37 -0500)]
go/types: don't write during sanitizeInfo if nothing has changed
In its final phase, the typechecker walks the types it produces to
ensure that no unexpanded type instances leak through the API. However,
this also walks shared types (such as those in the universe scope),
resulting in a potential data race during concurrent typechecking
passes.
Fix this by being careful not to write if nothing needs to be changed.
Since any shared types should already be sanitized, this should
eliminate data races.
For #44434
Change-Id: Iadb2e78863efe0e974e69a00e255f26cfaf9386a
Reviewed-on: https://go-review.googlesource.com/c/go/+/294411
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Dan Scales [Fri, 19 Feb 2021 02:07:09 +0000 (18:07 -0800)]
cmd/compile: fix check to avoid creating new closure function when typechecking inline body
By default, when typechecking a closure, tcClosure() creates a new
closure function. This should really be done separate from typechecking.
For now, we explicitly avoid creating a new closure function when
typechecking an inline body (in ImportedBody). However, the heuristic
for determining when we are typechecking an inline body was not correct
for double nested closures in an inline body, since CurFunc will then be
the inner closure, which has a body.
So, use a simple global variable to indicate when we typechecking an
inline body. The global variable is fine (just like ir.CurFunc), since
the front-end runs serially.
Fixes #44325
Change-Id: If2829fe1ebb195a7b1a240192b57fe6f04d1a36b
Reviewed-on: https://go-review.googlesource.com/c/go/+/294211
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
Russ Cox [Fri, 19 Feb 2021 18:39:43 +0000 (13:39 -0500)]
codereview.cfg: add codereview.cfg for master branch
The codereview sync-branch command wants all involved
branches to have codereview.cfg, and this will help us when
we transition from master to main later this year.
Russ Cox [Fri, 19 Feb 2021 11:01:25 +0000 (06:01 -0500)]
runtime: ignore SPWRITE in syscall functions
netbsd/amd64's Syscall9 changes SP using ADD and SUB,
which are treated as SPWRITEs (they are not accounted for
in the sp-adjust tracking, and there are too many functions that
would report mismatched stack adjustments at RET if they were).
A traceback starting in Syscall9 as saved by entersyscall complains
about the SPWRITE-ness unnecessarily, since the PC/SP are saved
at the start of the function. Ignore SPWRITE in that case.
netbsd/arm's Syscall6 also changes SP (R13), using a direct write.
So even if we could handle the ADD/SUB in the amd64 case or
rewrote that assembly, we'd still be stuck with a more difficult
problem in this case. Ignoring the SPWRITE fixes it.
Russ Cox [Fri, 19 Feb 2021 10:42:20 +0000 (05:42 -0500)]
runtime/pprof: disable TestMorestack on macOS under race detector
This is failing but only under the race detector.
It doesn't really seem fair to expect pprof to find
specific profile events with the race detector slowing
everything down anyway.
Russ Cox [Fri, 19 Feb 2021 10:22:35 +0000 (05:22 -0500)]
runtime: fix spurious stack overflow detection
The regabi builders are unhappy about badctxt calling throw
calling systemstack calling gosave_systemstack_switch calling
badctxt, all nosplit, repeating. This wouldn't actually happen
since after one systemstack we'd end up on the system stack
and the next one wouldn't call gosave_systemstack_switch at all.
The badctxt call itself is in a very unlikely assertion failure
inside gosave_systemstack_switch.
Keep the assertion check but call runtime.abort instead on failure,
breaking the detected (but not real) cycle.
Than McIntosh [Wed, 17 Feb 2021 20:51:05 +0000 (15:51 -0500)]
cmd/compile: fix buglet in inlined info abstract function dwarf-gen
When generating DWARF inlined info records, it's possible to have a
local function whose only callsites are inlined away, meaning that we
emit an abstract function DIE but no regular subprogram DIE. When
emitting DWARF scope info we need to handle this case (specifically
when scoping PCs, check for the case that the func in question has
been entirely deleted).
Fixes #44344.
Change-Id: I9f5bc692f225aa4c5c23f7bd2e50bcf7fe4fc5f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/293309
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
An embedded struct field is embedded by mentioning its type.
The fact that the field name may be different and derived
from the type doesn't matter for the struct type.
Do print the embedded type rather than the derived field
name, as we have always done in the past. Remove the fancy
new code which was just plain wrong.
The struct output printing is only relevant for debugging
and test cases. Reverting to the original code (pre-generics)
fixes a couple of x/tools tests.
Unfortunately, the original code is (also) not correct for
embedded type aliases. Adjusted a gccgoimporter test
accordingly and filed issue #44410.
This is a follow-up on https://golang.org/cl/293961 which
addressed the issue only partially and left the incorrect
code in place.
Change-Id: Icb7a89c12ef7929c221fb1a5792f144f7fcd5855
Reviewed-on: https://go-review.googlesource.com/c/go/+/293962
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Rob Findley [Fri, 19 Feb 2021 01:08:42 +0000 (20:08 -0500)]
go/parser: improve error recovery from invalid selector exprs
Before this CL, the parser consumed the next token following an invalid
selector expr no matter what it was. This leads to poor error recovery
when this next token is a closing delimiter or other reasonable element
of a stop set. As a side-effect, x/tools tests broke when parser logic
for type parameters was introduced, as they threw off the parser
synchronization to the point where the x/tools test bailed out.
This CL introduces a targeted fix that allows the x/tools tests to pass.
More general improvement for parser error recovery should be done for
go1.17.
Change-Id: I44d73d34b6063e62d16a23d24ab7cbce6500239d
Reviewed-on: https://go-review.googlesource.com/c/go/+/293792
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Prior to 1.16, go/types printed an embedded struct field by simply
printing its type, which may have included a package qualification.
Just printing the type is not useful with generic types and we now
must print the actual field name derived from the type - this leads
to different output for non-generic imported embedded types. Fix by
printing a package qualification in that case.
Change-Id: I2cb2484da7732428d13fdfb5fe4ec1fa1ee813a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/293961
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Bryan C. Mills [Tue, 9 Feb 2021 20:38:18 +0000 (15:38 -0500)]
cmd/go/internal/mvs: split Reqs into narrower per-function interfaces
Reqs currently combines requirements with upgrades and downgrades.
However, only Upgrade needs the Upgrade method, and only Downgrade
needs the Previous method.
When we eventually add lazy loading, the lazily-loaded module graph
will not be able to compute upgrades and downgrades, so the
implementation work from here to there will be clearer if we are
explicit about which are still needed.
For #36460
Change-Id: I7bf8c2a84ce6bc4ef493a383e3d26850e9a6a6c0
Reviewed-on: https://go-review.googlesource.com/c/go/+/290771
Trust: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Bryan C. Mills [Thu, 4 Feb 2021 14:42:48 +0000 (09:42 -0500)]
cmd/go/internal/modget: split resolveCandidates into two methods
It turns out that the existing call sites of the resolveCandidates
method pass only *either* a slice of queries or a slice of upgrades
(never both), and the behaviors triggered by the two parameters don't
overlap much at all. To clarify the two different operations, split
them into two separate methods.
For #36460
Change-Id: I64651637734fd44fea68740a3cdfbacfb73c19b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/289697
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>
Russ Cox [Thu, 18 Feb 2021 16:47:47 +0000 (11:47 -0500)]
net: disable Windows netsh tests when netsh won't run
On my Surface Pro X running the insider preview,
running "netsh help" from Powershell started from the task bar works.
But running "powershell" at a cmd.exe prompt and then running
"netsh help" produces missing DLL errors.
These aren't our fault, so just skip the netsh-based tests if this happens.
Russ Cox [Mon, 15 Feb 2021 22:02:30 +0000 (17:02 -0500)]
runtime/pprof: expect tests to pass on macOS
macOS tests have been disabled since CL 12429045 (Aug 2013).
At the time, macOS required a kernel patch to get a working profiler
(https://research.swtch.com/macpprof), which we didn't want
to require, of course.
macOS has improved - it no longer requires the kernel patch - but
we never updated the list of exceptions.
As far as I can tell, the builders have no problem passing the pprof test now.
(It is possible that the iOS builders have trouble, but that is now a different GOOS.)
Remove the exception for macOS. The test should now pass.
Russ Cox [Thu, 11 Feb 2021 04:41:23 +0000 (23:41 -0500)]
math: remove most 387 implementations
The Surface Pro X's 386 simulator is not completely faithful to a real 387.
The most egregious problem is that it computes Log2(8) as 2.9999999999999996,
but it has some other subtler problems as well. All the problems occur in
routines that we don't even bother with assembly for on amd64.
If the speed of Go code is OK on amd64 it should be OK on 386 too.
Just remove all the 386-only assembly functions.
This leaves Ceil, Floor, Trunc, Hypot, and Sqrt in 386 assembly,
all of which are also in assembly on amd64 and all of which pass
their tests on Surface Pro X.
Compared to amd64, the 386 port omits assembly for Min, Max, and Log.
It never had Min and Max, and this CL deletes Log because Log2 wasn't
even correct. (None of the other architectures have assembly Log either.)
This CL adds a few small files - defs, os, and rt0 - to start
on windows/arm64 support for the runtime.
It also copies sys_windows_arm.s to sys_windows_arm64.s,
with the addition of "#ifdef NOT_PORTED" around the entire file.
This is meant to make future CLs easier to review, since the
general pattern is to translate the 32-bit ARM assembly into
64-bit ARM assembly.
This CL is part of a stack adding windows/arm64
support (#36439), intended to land in the Go 1.17 cycle.
Change-Id: I922037eb3890e77bac48281ecaa8e489595675be
Reviewed-on: https://go-review.googlesource.com/c/go/+/288827
Trust: Russ Cox <rsc@golang.org>
Trust: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>