]> Cypherpunks.ru repositories - gostls13.git/log
gostls13.git
15 months agoslices: new package
Ian Lance Taylor [Fri, 10 Feb 2023 21:52:37 +0000 (13:52 -0800)]
slices: new package

This copies parts of x/exp/slices into the standard library.
We omit all functions that depend on constraints.Ordered,
and the Func variants of all such functions. In particular this
omits the various Sort and Search functions.

Fixes #57433

Change-Id: I3c28f4c2e6bd1e3c9ad70e120a0dd68065388f77
Reviewed-on: https://go-review.googlesource.com/c/go/+/467417
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Eli Bendersky <eliben@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

15 months agocmd/link/internal/ld: fix text section splitting for ARM
Than McIntosh [Mon, 13 Feb 2023 15:13:57 +0000 (10:13 -0500)]
cmd/link/internal/ld: fix text section splitting for ARM

Fix a problem with trampoline generation for ARM that was causing link
failures when building selected k8s targets. Representative error
(this is coming from the external linker):

  go.go:(.text+...): relocation truncated to fit: R_ARM_CALL against `runtime.duffcopy'

The Go linker is supposed to be limiting text section size for ARM to
0x1c00000 bytes, however due to a problem in the tramp generation
phase this limit wasn't being enforced.

Updates #58428.
Fixes #58425.

Change-Id: I4e778bdcbebeab607a6e626b354ca5109e52a1aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/467715
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

15 months agoall: update vendored golang.org/x/net
Damien Neil [Mon, 13 Feb 2023 18:58:32 +0000 (10:58 -0800)]
all: update vendored golang.org/x/net

Pull in HTTP/2 fix to deflake builders:

    547e7edf38 http2: avoid referencing ResponseWrite.Write parameter after returning

For #58446

Change-Id: I7f3666bc1f20ee03a7ccf25f0e091033cbc635d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/467657
Auto-Submit: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

15 months agocmd/internal/cov: fix typo in readcovdata.go
Ikko Eltociear Ashimine [Sat, 11 Feb 2023 12:45:01 +0000 (12:45 +0000)]
cmd/internal/cov: fix typo in readcovdata.go

hte -> the

Change-Id: Ie81062997289d622756881acdd11af66611cd778
GitHub-Last-Rev: 5ef07542b47f243d5a66ef166c74db0348fd2c80
GitHub-Pull-Request: golang/go#58473
Reviewed-on: https://go-review.googlesource.com/c/go/+/467518
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>

15 months agocrypto/internal/edwards25519: reduce Point size by reordering fields
Jorropo [Mon, 13 Feb 2023 00:48:57 +0000 (01:48 +0100)]
crypto/internal/edwards25519: reduce Point size by reordering fields

Updates #58483

Tested on Linux amd64:
  type Element struct {
    l0, l1, l2, l3, l4 uint64
  }

  type PointAfter struct {
    x, y, z, t Element
    _          incomparable
  }

  type PointBefore struct {
    _          incomparable
    x, y, z, t Element
  }

  type incomparable [0]func()

  func main() {
    fmt.Println(unsafe.Sizeof(PointAfter{})) // 168
    fmt.Println(unsafe.Sizeof(PointBefore{})) // 160
  }

Change-Id: I6c4fcb586bbf3febf62b6e54608496ff81685e43
Reviewed-on: https://go-review.googlesource.com/c/go/+/467616
Reviewed-by: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>

15 months agocmd/dist: use a copy of platform.BuildModeSupported
Ian Lance Taylor [Fri, 10 Feb 2023 22:47:07 +0000 (14:47 -0800)]
cmd/dist: use a copy of platform.BuildModeSupported

The dist tool already includes a similar duplicate of BuildModeSupported.
Replace it with an exact copy, to make it easier to maintain going forward.

Change-Id: Id14a6c5a48f92d843e02218d87cc62c6b001923b
Reviewed-on: https://go-review.googlesource.com/c/go/+/467495
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>

15 months agointernal/bytealg: simplify and improve compare on riscv64
Joel Sing [Sat, 17 Sep 2022 15:43:20 +0000 (01:43 +1000)]
internal/bytealg: simplify and improve compare on riscv64

Remove some unnecessary loops and pull the comparison code out from the
compare/loop code. Add an unaligned 8 byte comparison, which reads 8 bytes
from each input before comparing them. This gives a reasonable gain in
performance for the large unaligned case.

Updates #50615

name                                 old time/op    new time/op    delta
CompareBytesEqual-4                     116ns _ 0%     111ns _ 0%   -4.10%  (p=0.000 n=5+5)
CompareBytesToNil-4                    34.9ns _ 0%    35.0ns _ 0%   +0.45%  (p=0.002 n=5+5)
CompareBytesEmpty-4                    29.6ns _ 1%    29.8ns _ 0%   +0.71%  (p=0.016 n=5+5)
CompareBytesIdentical-4                29.8ns _ 0%    29.9ns _ 1%   +0.50%  (p=0.036 n=5+5)
CompareBytesSameLength-4               66.1ns _ 0%    60.4ns _ 0%   -8.59%  (p=0.000 n=5+5)
CompareBytesDifferentLength-4          63.1ns _ 0%    60.5ns _ 0%   -4.20%  (p=0.000 n=5+5)
CompareBytesBigUnaligned/offset=1-4    6.84ms _ 3%    6.04ms _ 5%  -11.70%  (p=0.001 n=5+5)
CompareBytesBigUnaligned/offset=2-4    6.99ms _ 4%    5.93ms _ 6%  -15.22%  (p=0.000 n=5+5)
CompareBytesBigUnaligned/offset=3-4    6.74ms _ 1%    6.00ms _ 5%  -10.94%  (p=0.001 n=5+5)
CompareBytesBigUnaligned/offset=4-4    7.20ms _ 6%    5.97ms _ 6%  -17.05%  (p=0.000 n=5+5)
CompareBytesBigUnaligned/offset=5-4    6.75ms _ 1%    5.81ms _ 8%  -13.93%  (p=0.001 n=5+5)
CompareBytesBigUnaligned/offset=6-4    6.89ms _ 5%    5.75ms _ 2%  -16.58%  (p=0.000 n=5+4)
CompareBytesBigUnaligned/offset=7-4    6.91ms _ 6%    6.13ms _ 6%  -11.27%  (p=0.001 n=5+5)
CompareBytesBig-4                      2.75ms _ 5%    2.71ms _ 8%     ~     (p=0.651 n=5+5)
CompareBytesBigIdentical-4             29.9ns _ 1%    29.8ns _ 0%     ~     (p=0.751 n=5+5)

name                                 old speed      new speed      delta
CompareBytesBigUnaligned/offset=1-4   153MB/s _ 3%   174MB/s _ 6%  +13.40%  (p=0.003 n=5+5)
CompareBytesBigUnaligned/offset=2-4   150MB/s _ 4%   177MB/s _ 6%  +18.06%  (p=0.001 n=5+5)
CompareBytesBigUnaligned/offset=3-4   156MB/s _ 1%   175MB/s _ 5%  +12.39%  (p=0.002 n=5+5)
CompareBytesBigUnaligned/offset=4-4   146MB/s _ 6%   176MB/s _ 6%  +20.67%  (p=0.001 n=5+5)
CompareBytesBigUnaligned/offset=5-4   155MB/s _ 1%   181MB/s _ 7%  +16.35%  (p=0.002 n=5+5)
CompareBytesBigUnaligned/offset=6-4   152MB/s _ 5%   182MB/s _ 2%  +19.74%  (p=0.000 n=5+4)
CompareBytesBigUnaligned/offset=7-4   152MB/s _ 6%   171MB/s _ 6%  +12.70%  (p=0.001 n=5+5)
CompareBytesBig-4                     382MB/s _ 5%   388MB/s _ 9%     ~     (p=0.616 n=5+5)
CompareBytesBigIdentical-4           35.1TB/s _ 1%  35.1TB/s _ 0%     ~     (p=0.800 n=5+5)

Change-Id: I127edc376e62a2c529719a4ab172f481e0a81357
Reviewed-on: https://go-review.googlesource.com/c/go/+/431100
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
Run-TryBot: Joel Sing <joel@sing.id.au>

15 months agoruntime: Allow handling of EXCEPTION_IN_PAGE_ERROR
Max Altgelt [Fri, 10 Feb 2023 10:38:42 +0000 (11:38 +0100)]
runtime: Allow handling of EXCEPTION_IN_PAGE_ERROR

Currently, access faults on memory mapped files on Windows (e.g.
from the drive the memory mapped file is on being ejected) cause
a runtime fault that can not be caught by debug.SetPanicOnFault.

On Unix systems, on the other hand, this causes a SIGBUS signal,
which can be caught by debug.SetPanicOnFault. Given that the
documentation of debug.SetPanicOnFault mentions handling memory
mapped files, this is arguably the correct behaviour.

Add handling, analogous to SIGBUS, to EXCEPTION_IN_PAGE_ERROR
on Windows, to allow for users to handle this error.

Fixes #58457

Change-Id: Ic7695fc01271f3552782089ac75c403d5279811f
Reviewed-on: https://go-review.googlesource.com/c/go/+/467195
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
15 months agocmd/go: mod vendor: fixed checking for vendor directory
David Barshow [Tue, 7 Feb 2023 17:30:05 +0000 (17:30 +0000)]
cmd/go: mod vendor: fixed checking for vendor directory

In our case I was using a "vendor-replace" directory which was incorrectly flagged as being in the vendor directory.

Change-Id: I8208243ea8416ee7cb4de30e907bcfc25c2d3f27
GitHub-Last-Rev: d183a94d03225ee529c4906a64a289f02eaf7684
GitHub-Pull-Request: golang/go#58287
Reviewed-on: https://go-review.googlesource.com/c/go/+/465036
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>

15 months agoio: detect Writers that access io.Copy's buffer after returning
Damien Neil [Thu, 9 Feb 2023 22:41:42 +0000 (14:41 -0800)]
io: detect Writers that access io.Copy's buffer after returning

When the race detector is enabled, scribble over copy buffers with
garbage after Write returns.

For #58452

Change-Id: I25547684bcbef7d302d76736cb02e59c89a640ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/466865
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>

15 months agocmd/go: handle escapes in pkg-config ldflags output
zlasd [Thu, 9 Feb 2023 14:03:45 +0000 (14:03 +0000)]
cmd/go: handle escapes in pkg-config ldflags output

#16455 handled escapes in pkg-config output but only for cflags. The fix
for #41400 left a note that we don't need to parse quotes and unescapes,
but it is still necessary to handle spaces in pkg-config output. As cflags
has already been processed correctly, we apply the same logic to ldflags
here.

Fixes #35262

Change-Id: Id01d422b103780f67f89e99ff1df0d8f51a7a137
GitHub-Last-Rev: c67e5112130fa008397cfd0bc03e1de58201da86
GitHub-Pull-Request: golang/go#58429
Reviewed-on: https://go-review.googlesource.com/c/go/+/466875
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
15 months agocmd/trace: fix error message for bad goroutine state transition
Nick Ripley [Fri, 10 Feb 2023 19:08:27 +0000 (14:08 -0500)]
cmd/trace: fix error message for bad goroutine state transition

The error message when an invalid goroutine state transition is found in
a trace should show the current state, not the next state, when
comparing against the expected current state.

This CL also picks up a gofmt change to the file.

Change-Id: Ic0ce6c9ce79d8a784b73b115b5db76c311b8593d
Reviewed-on: https://go-review.googlesource.com/c/go/+/467416
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

15 months agovendor: add new vendored files from update
David Chase [Fri, 10 Feb 2023 20:01:40 +0000 (15:01 -0500)]
vendor: add new vendored files from update

fixes failing cmd/internal/moddeps TestAllDependencies

Change-Id: I70e081469f1aa3b795a5bd28adeb61b31d7f34fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/467415
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
15 months agonet: move context cancellation logic of blocking calls to a common function
Mateusz Poliwczak [Fri, 10 Feb 2023 09:01:29 +0000 (09:01 +0000)]
net: move context cancellation logic of blocking calls to a common function

Follow up of CL 464375 which reverted the CL 463231, because of a data race.

Change-Id: I1a52f23a68a6981b902fc59bda1437bd169ca22b
GitHub-Last-Rev: 0157bd01807a731239f3f2940d440e798be33d83
GitHub-Pull-Request: golang/go#58383
Reviewed-on: https://go-review.googlesource.com/c/go/+/465836
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

15 months agocmd/compile/internal/pgo: fix hard-coded PGO sample data position
Frederic Branczyk [Wed, 8 Feb 2023 17:59:27 +0000 (17:59 +0000)]
cmd/compile/internal/pgo: fix hard-coded PGO sample data position

This patch detects at which index position profiling samples that have
the value-type samples count are, instead of the previously hard-coded
position of index 1. Runtime generated profiles always generate CPU
profiling data with the 0 index being CPU nanoseconds, and samples count
at index 1, which is why this previously hasn't come up.

This is a redo of CL 465135, now allowing empty profiles. Note that
preprocessProfileGraph will already cause pgo.New to return nil for
empty profiles.

Fixes #58292

Change-Id: Ia6c94f0793f6ca9b0882b5e2c4d34f38e600c1e3
Reviewed-on: https://go-review.googlesource.com/c/go/+/466675
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

15 months agovendor, cmd/vendor: update standard library dependencies
David Chase [Thu, 9 Feb 2023 18:04:21 +0000 (13:04 -0500)]
vendor, cmd/vendor: update standard library dependencies

Change-Id: I6facfae14e850f6c9bf3bcb53489c8b475bbb860
Reviewed-on: https://go-review.googlesource.com/c/go/+/467297
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: David Chase <drchase@google.com>

15 months agobufio: permit r.Reset(r) without infinite recursion
Ian Lance Taylor [Thu, 9 Feb 2023 03:50:06 +0000 (19:50 -0800)]
bufio: permit r.Reset(r) without infinite recursion

This can happen in reasonable code because NewReader(r) can return r,
if r is already a Reader.

Similarly for Writer.

Fixes #58423

Change-Id: Iff9d9265410bee68fbaeb7175369847bd737eb2c
Reviewed-on: https://go-review.googlesource.com/c/go/+/466815
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>

15 months agocmd/internal/cov: fix misuse of bufio.Reader.Read in read helper
Than McIntosh [Wed, 8 Feb 2023 20:06:08 +0000 (15:06 -0500)]
cmd/internal/cov: fix misuse of bufio.Reader.Read in read helper

Fix a misuse of bufio.Reader.Read in the helper class
cmd/internal/cov.MReader; the MReader method in question should have
been using io.ReadFull (passing the bufio.Reader) instead of directly
calling Read.

Using the Read method instead of io.ReadFull will result in a "short"
read when processing a specific subset of counter data files, e.g.
those that are short enough to not trigger the mmap-based scheme we
use for larger files, but also with a large args section (something
large enough to exceed the default 4k buffer size used by
bufio.Reader).

Along the way, add some additional defered Close() calls for files
opened by the CovDataReader.visitPod, to enure we don't leave any open
file descriptor following a call to CovDataReader.Visit.

Fixes #58411.

Change-Id: Iea48dc25c0081be1ade29f3a633df02a681fd941
Reviewed-on: https://go-review.googlesource.com/c/go/+/466677
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
15 months agoRevert "math: add Compare and Compare32"
Than McIntosh [Fri, 10 Feb 2023 14:39:20 +0000 (14:39 +0000)]
Revert "math: add Compare and Compare32"

This reverts CL 459435.

Reason for revert: Tests failing on MIPS.

Change-Id: I9017bf718ba938df6d6766041555034d55d90b8a
Reviewed-on: https://go-review.googlesource.com/c/go/+/467255
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Akhil Indurti <aindurti@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
15 months agocmd/go: remove tests that assume lack of new versions of external modules
Bryan C. Mills [Thu, 9 Feb 2023 21:37:51 +0000 (16:37 -0500)]
cmd/go: remove tests that assume lack of new versions of external modules

In general it seems ok to assume that an open-source module that did
exist will continue to do so — after all, users of open-source modules
already do that all the time. However, we should not assume that those
modules do not publish new versions — that's really up to their
maintainers to decide.

Two existing tests did make that assumption for the module
gopkg.in/natefinch/lumberjack.v2. Let's remove those two tests.
If we need to replace them at some point, we can replace them with
hermetic test-only modules (#54503) or perhaps modules owned by the Go
project.

Fixes #58445.

Change-Id: Ica8fe587d86fc41f3d8445a4cd2b8820455ae45f
Reviewed-on: https://go-review.googlesource.com/c/go/+/466860
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
15 months agomath/rand: fix typo in Seed deprecation comment
Valentin Deleplace [Fri, 10 Feb 2023 14:51:11 +0000 (15:51 +0100)]
math/rand: fix typo in Seed deprecation comment

Change-Id: I37a9e4362953a711840087e1b7b8d7a25f1a83b7
Reviewed-on: https://go-review.googlesource.com/c/go/+/467275
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Bypass: Russ Cox <rsc@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>

15 months agoRevert "io: allocate copy buffers from a pool"
Damien Neil [Thu, 9 Feb 2023 22:24:46 +0000 (14:24 -0800)]
Revert "io: allocate copy buffers from a pool"

This reverts CL 456555.

Reason for revert: This seems too likely to exercise race conditions
in code where a Write call continues to access its buffer after
returning. The HTTP/2 ResponseWriter is one such example.

Reverting this change while we think about this some more.

For #57202

Change-Id: Ic86823f81d7da410ea6b3f17fb5b3f9a979e3340
Reviewed-on: https://go-review.googlesource.com/c/go/+/467095
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

15 months agocontext: reduce init-time allocations
Carlo Alberto Ferraris [Tue, 6 Dec 2022 05:45:04 +0000 (14:45 +0900)]
context: reduce init-time allocations

Small cleanup to remove a couple of needless global variables.
Instead of relying on two instances of emptyCtx having different
addresses, we use different types.

For #26775

Change-Id: I0bc4813e94226f7b3f52bf4b1b3c3a3bbbebcc9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/455455
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Sameer Ajmani <sameer@golang.org>
15 months agoruntime: skip darwin osinit_hack on ios
Russ Cox [Wed, 8 Feb 2023 19:02:55 +0000 (14:02 -0500)]
runtime: skip darwin osinit_hack on ios

Darwin needs the osinit_hack call to fix some bugs in the Apple libc
that surface when Go programs call exec. On iOS, the functions that
osinit_hack uses are not available, so signing fails. But on iOS exec
is also unavailable, so the hack is not needed. Disable it there,
which makes signing work again.

Fixes #58323.

Change-Id: I3f1472f852bb36c06854fe1f14aa27ad450c5945
Reviewed-on: https://go-review.googlesource.com/c/go/+/466516
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Dave Anderson <danderson@tailscale.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
15 months agocmd/dist: remove windows-amd64-2008 code path
qmuntal [Fri, 10 Feb 2023 09:36:16 +0000 (10:36 +0100)]
cmd/dist: remove windows-amd64-2008 code path

`windows-amd64-2008` builder does no longer exist on go1.20,
so it is safe to remove conditions checking for that name.

Updates #57003
Closes #56904

Change-Id: I941ccc64cda0af3b9356996c4b581700afa81987
Reviewed-on: https://go-review.googlesource.com/c/go/+/467175
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
15 months agocmd/link: try libssp_nonshared.a when looking for "__stack_chk_fail_local"
Than McIntosh [Thu, 9 Feb 2023 16:37:13 +0000 (11:37 -0500)]
cmd/link: try libssp_nonshared.a when looking for "__stack_chk_fail_local"

Update the code that tries to satisfy unresolved references to
"__stack_chk_fail_local" to look for "libssp_nonshared.a" in addition
to "libc_nonshared.a" (the former archive is the correct place on
Alpine).

Updates #52919.
Updates #54313.
Updates #57261.
Fixes #58385.

Change-Id: Id6cd3ebb4d5388df50a838e6efa5e5b683545b01
Reviewed-on: https://go-review.googlesource.com/c/go/+/466936
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

15 months agocmd/cgo: add -fno-stack-protector to CFLAGS (again)
Than McIntosh [Thu, 9 Feb 2023 16:31:57 +0000 (11:31 -0500)]
cmd/cgo: add -fno-stack-protector to CFLAGS (again)

Add -fno-stack-protector back to the default set of CFLAGS for cgo, so
as to avoid problems with internal linking locating the library
containing the "__stack_chk_fail_local" support function that some
compilers emit (the specific archive can vary based on GOOS).

Updates #52919.
Updates #54313.
Updates #57261.
Updates #58385.

Change-Id: I4591bfb15501f04b7afe1fcd50c4fb93c86db63d
Reviewed-on: https://go-review.googlesource.com/c/go/+/466935
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

15 months agocmd/link: improve error for missing SDYNIMPORT support on mips/mips64
Than McIntosh [Thu, 9 Feb 2023 14:08:44 +0000 (09:08 -0500)]
cmd/link: improve error for missing SDYNIMPORT support on mips/mips64

Issue an error (instead of crashing) when encountering a symbol that
requires dynamic relocations on mips/mips64. The dynimport support is
in progress, but is not done yet, so rather than crashing, print a
message indicating that the feature is not yet implemented and exit.

Fixes #58240.

Change-Id: I9ad64c89e4f7b4b180964b35ad1d72d375f2df7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/466895
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>

15 months agomath/rand: rewrite the math/rand package comment to say what it's good for
Rob Pike [Wed, 8 Feb 2023 03:19:59 +0000 (14:19 +1100)]
math/rand: rewrite the math/rand package comment to say what it's good for

It currently says only what it wasn't good for, which is not helpful.

Change-Id: I468c7f385c14eaca99788a94d53c30b729ed0944
Reviewed-on: https://go-review.googlesource.com/c/go/+/466276
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

15 months agogo/types, types2: remove need to store type parameter list in unifier
Robert Griesemer [Thu, 9 Feb 2023 17:23:41 +0000 (09:23 -0800)]
go/types, types2: remove need to store type parameter list in unifier

For unification we only need the handles map.
The type parameter list was stored for reproducible printing only,
but we can achieve the same effect with sorting.

This opens the door to adding type parameters from different
types/functions that we may want to infer together. They may
be added through separate "addTypeParams" calls in the future.
Printing (which is used for debugging only) will remain reproducible.

Change-Id: I23b56c63fa45a7d687761f2efcf558e61b004584
Reviewed-on: https://go-review.googlesource.com/c/go/+/466955
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

15 months agogo/types, types2: simplify unify.inferred signature
Robert Griesemer [Thu, 9 Feb 2023 00:51:58 +0000 (16:51 -0800)]
go/types, types2: simplify unify.inferred signature

Rather than referring back to the type parameter list stored with
the unifier, return inferred types for a given list of type parameters.
This decouples the unifier more and opens the door for inference to
consider type parameters from multiple types for inference.

While at it, introduce an internal flag to control whether
inference results of the two inference implementations should
be compared or not.

Change-Id: I23b254c6c1c750f5bd1360aa2bb088cc466434f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/466795
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

15 months agonet: remove unused cname return from cgoLookupIPCNAME
Mateusz Poliwczak [Wed, 8 Feb 2023 08:44:32 +0000 (08:44 +0000)]
net: remove unused cname return from cgoLookupIPCNAME

Change-Id: I4f9b84696f55c6b381de60682f8b242098b95b75
GitHub-Last-Rev: 74a6013a9e668119a0895c1250c3d4592bfd4072
GitHub-Pull-Request: golang/go#58402
Reviewed-on: https://go-review.googlesource.com/c/go/+/466335
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
15 months agomath: add Compare and Compare32
Akhil Indurti [Sat, 24 Dec 2022 14:22:30 +0000 (09:22 -0500)]
math: add Compare and Compare32

This change introduces the Compare and Compare32 functions
based on the total-ordering predicate in IEEE-754, section 5.10.

In particular,
* -NaN is ordered before any other value
* +NaN is ordered after any other value
* -0 is ordered before +0
* All other values are ordered the usual way

name         time/op
Compare-8    0.24ns ± 1%
Compare32-8  0.24ns ± 0%

Fixes #56491.

Change-Id: I9444fbfefe26741794c4436a26d403b8da97bdaf
Reviewed-on: https://go-review.googlesource.com/c/go/+/459435
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
15 months agonet/http: improve js fetch errors
Johan Brandhorst-Satzkorn [Sat, 28 Jan 2023 06:53:25 +0000 (22:53 -0800)]
net/http: improve js fetch errors

The Error type used in failed fetch invocations contain more
information than we're currently extracting. Optimistically
look for the cause field for extra context for errors.

Change-Id: I6c8e4b230a21ec684af2107707aa605fc2148fcf
Reviewed-on: https://go-review.googlesource.com/c/go/+/463978
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Evan Phoenix <evan@phx.io>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>

15 months agoruntime: skip trailing wrappers in runtime_expandFinalInlineFrame
Tolyan Korniltsev [Sat, 4 Feb 2023 06:53:34 +0000 (14:53 +0800)]
runtime: skip trailing wrappers in runtime_expandFinalInlineFrame

The existing runtime_expandFinalInlineFrame implementation doesn't skip trailing wrappers, but
gentraceback does skip wrapper functions.
This change makes runtime_expandFinalInlineFrame handling wrapper functions consistent to gentraceback.

Fixes #58288

Change-Id: I1b0e2c10b0a89bcb1e787b98d27730cb40a34406
Reviewed-on: https://go-review.googlesource.com/c/go/+/465097
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: David Chase <drchase@google.com>
15 months agocmd/compile: disable inline static init optimization
Cuong Manh Le [Thu, 9 Feb 2023 19:13:05 +0000 (02:13 +0700)]
cmd/compile: disable inline static init optimization

There are a plenty of regression in 1.20 with this optimization. This CL
disable inline static init, so it's safer to backport to 1.20 branch.

The optimization will be enabled again during 1.21 cycle.

Updates #58293
Updates #58339
For #58293

Change-Id: If5916008597b46146b4dc7108c6b389d53f35e95
Reviewed-on: https://go-review.googlesource.com/c/go/+/467015
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>

15 months agocmd/compile: remove reflectdata.AfterGlobalEscapeAnalysis
Cuong Manh Le [Wed, 8 Feb 2023 09:06:50 +0000 (16:06 +0700)]
cmd/compile: remove reflectdata.AfterGlobalEscapeAnalysis

This global variable was used by the old frontend to decide whether to
perform escape analysis during method wrapper generation.

The old frontend is gone now, the variable is not used anywhere else.

Change-Id: I448f2761ea608a9a2ec39a9920fcf7aa12d98799
Reviewed-on: https://go-review.googlesource.com/c/go/+/466278
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

15 months agocmd/compile/internal/staticinit: fix panic in interface conversion
Sung Yoon Whang [Wed, 8 Feb 2023 22:35:30 +0000 (22:35 +0000)]
cmd/compile/internal/staticinit: fix panic in interface conversion

This patch fixes a panic from incorrect interface conversion from
*ir.BasicLit to *ir.ConstExpr. This only occurs when nounified
GOEXPERIMENT is set, so ideally it should be backported to Go
1.20 and removed from master.

Fixes #58339

Change-Id: I357069d7ee1707d5cc6811bd2fbdd7b0456323ae
GitHub-Last-Rev: 641dedb5f9f95e6f8d46723d445a8c9609719ce4
GitHub-Pull-Request: golang/go#58389
Reviewed-on: https://go-review.googlesource.com/c/go/+/466175
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
15 months agocmd/go/internal/test: rewrite generate tests using the new maps package
Bryan C. Mills [Wed, 8 Feb 2023 20:49:03 +0000 (15:49 -0500)]
cmd/go/internal/test: rewrite generate tests using the new maps package

For #58415.

Change-Id: I13c00f28824087e1841a49ec35a3e2a990945137
Reviewed-on: https://go-review.googlesource.com/c/go/+/466695
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>

15 months agocmd/compile: remove constant arithmetic overflows during typecheck
Cuong Manh Le [Sat, 4 Feb 2023 05:00:20 +0000 (12:00 +0700)]
cmd/compile: remove constant arithmetic overflows during typecheck

Since go1.19, these errors are already reported by types2 for any user's
Go code. Compiler generated code, which looks like constant expression
should be evaluated as non-constant semantic, which allows overflows.

Fixes #58293

Change-Id: I6f0049a69bdb0a8d0d7a0db49c7badaa92598ea2
Reviewed-on: https://go-review.googlesource.com/c/go/+/465096
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
15 months agoruntime: fix signature for linked functions
Adin Scannell [Wed, 8 Feb 2023 19:15:23 +0000 (19:15 +0000)]
runtime: fix signature for linked functions

These functions are linked using go:linkname, but do not match the
original declarations. This change brings these in sync.

Change-Id: I16651304c3dba2f9897c2c42e30555d2f7805c2a
Reviewed-on: https://go-review.googlesource.com/c/go/+/466615
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Michael Pratt <mpratt@google.com>

15 months agocmd/go/internal/test: refresh flagdefs.go and fix test
Bryan C. Mills [Wed, 8 Feb 2023 19:36:47 +0000 (14:36 -0500)]
cmd/go/internal/test: refresh flagdefs.go and fix test

The tests for cmd/go/internal/test were not running at all due to a
missed call to m.Run in TestMain. That masked two missing vet
analyzers ("directive" and "timeformat") and a missed update to the
generator script in CL 355452.

Fixes #58415.

Change-Id: I7b0315952967ca07a866cdaa5903478b2873eb7a
Reviewed-on: https://go-review.googlesource.com/c/go/+/466635
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>

15 months agocmd/compile: use MakeResult in empty MakeSlice elimination
Jorropo [Tue, 31 Jan 2023 18:10:33 +0000 (19:10 +0100)]
cmd/compile: use MakeResult in empty MakeSlice elimination

This gets eliminated by thoses rules above:
  // for rewriting results of some late-expanded rewrites (below)
  (SelectN [0] (MakeResult x ___)) => x
  (SelectN [1] (MakeResult x y ___)) => y
  (SelectN [2] (MakeResult x y z ___)) => z

Fixes #58161

Change-Id: I4fbfd52c72c06b6b3db906bd9910b6dbb7fe8975
Reviewed-on: https://go-review.googlesource.com/c/go/+/463846
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
16 months agointernal/xcoff: use unsigned integers in file structs to avoid negative values
Alexander Yastrebov [Thu, 2 Feb 2023 19:33:01 +0000 (19:33 +0000)]
internal/xcoff: use unsigned integers in file structs to avoid negative values

Fixes #58137
Updates #54584

Change-Id: Ifeee1be22051b842e0707d1907dbfa58bfeb336b
GitHub-Last-Rev: 9768e7c4a4954824fa1a2c41c0ad72e496408f91
GitHub-Pull-Request: golang/go#58164
Reviewed-on: https://go-review.googlesource.com/c/go/+/464336
Reviewed-by: Ayappan Perumal <ayappanec@gmail.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

16 months agoRevert "cmd/compile/internal/pgo: fix hard-coded PGO sample data position"
Michael Pratt [Wed, 8 Feb 2023 18:48:17 +0000 (18:48 +0000)]
Revert "cmd/compile/internal/pgo: fix hard-coded PGO sample data position"

This reverts CL 465135.

Reason for revert: This broke cmd/go.TestScript/build_pgo on the linux-amd64-longtest builder: https://build.golang.org/log/8f8ed7bf576f891a06d295c4a5bca987c6e941d6

Change-Id: Ie2f2cc2731099eb28eda6b94dded4dfc34e29441
Reviewed-on: https://go-review.googlesource.com/c/go/+/466439
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>

16 months agocmd/cover: add newline to fix -covermode=atomic build error
Than McIntosh [Tue, 7 Feb 2023 16:11:45 +0000 (11:11 -0500)]
cmd/cover: add newline to fix -covermode=atomic build error

Fix a minor buglet in atomic mode fixup that would generate
non-compilable code for a package containing only the "package X"
clause with no trailing newline following the "X".

Fixes #58370.

Change-Id: I0d9bc4f2b687c6bd913595418f6db7dbe50cc5df
Reviewed-on: https://go-review.googlesource.com/c/go/+/466115
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agocmd/compile/internal/pgo: fix hard-coded PGO sample data position
Frederic Branczyk [Wed, 8 Feb 2023 17:59:27 +0000 (17:59 +0000)]
cmd/compile/internal/pgo: fix hard-coded PGO sample data position

This patch detects at which index position profiling samples that have the value-type samples count are, instead of the previously hard-coded position of index 1. Runtime generated profiles always generate CPU profiling data with the 0 index being CPU nanoseconds, and samples count at index 1, which is why this previously hasn't come up.

Fixes #58292

Change-Id: Idde761d53b02259f3076c4e5dcb4a96a9d53df0e
GitHub-Last-Rev: dabbf9f88c560286e150e9b136a27c3ac23c5ec1
GitHub-Pull-Request: golang/go#58294
Reviewed-on: https://go-review.googlesource.com/c/go/+/465135
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
16 months agoruntime: correct typos
Oleksandr Redko [Tue, 7 Feb 2023 09:09:24 +0000 (09:09 +0000)]
runtime: correct typos

- Fix typo in throw error message for arena.
- Correct typos in assembly and Go comments.
- Fix log message in TestTraceCPUProfile.

Change-Id: I874c9e8cd46394448b6717bc6021aa3ecf319d16
GitHub-Last-Rev: d27fad4d3cea81cc7a4ca6917985bcf5fa49b0e0
GitHub-Pull-Request: golang/go#58375
Reviewed-on: https://go-review.googlesource.com/c/go/+/465975
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agoruntime/internal/sys: remove Bswap{32|64} assembly for 386
Wayne Zuo [Mon, 6 Feb 2023 13:27:37 +0000 (21:27 +0800)]
runtime/internal/sys: remove Bswap{32|64} assembly for 386

CL 465515 instrinsify these functions, so that we can remove them.

Change-Id: I81c9eb62ecf56d5a292dc5aced542b36b53847dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/465516
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agocmd/compile: intrinsify math/bits/ReverseBytes{32|64} for 386
Wayne Zuo [Mon, 6 Feb 2023 13:21:52 +0000 (21:21 +0800)]
cmd/compile: intrinsify math/bits/ReverseBytes{32|64} for 386

The BSWAPL instruction is supported in i486 and newer.
https://github.com/golang/go/wiki/MinimumRequirements#386 says we
support "All Pentium MMX or later". The Pentium is also referred to as
i586, so that we are safe with these instructions.

Change-Id: I6dea1f9d864a45bb07c8f8f35a81cfe16cca216c
Reviewed-on: https://go-review.googlesource.com/c/go/+/465515
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@google.com>
16 months agocmd/compile: fix inline static init arguments substitued tree
Cuong Manh Le [Sun, 5 Feb 2023 07:33:32 +0000 (14:33 +0700)]
cmd/compile: fix inline static init arguments substitued tree

Blank node must be ignored when building arguments substitued tree.
Otherwise, it could be used to replace other blank node in left hand
side of an assignment, causing an invalid IR node.

Consider the following code:

type S1 struct {
s2 S2
}

type S2 struct{}

func (S2) Make() S2 {
return S2{}
}

func (S1) Make() S1 {
return S1{s2: S2{}.Make()}
}

var _ = S1{}.Make()

After staticAssignInlinedCall, the assignment becomes:

var _ = S1{s2: S2{}.Make()}

and the arg substitued tree is "map[*ir.Name]ir.Node{_: S1{}}". Now,
when doing static assignment, if there is any assignment to blank node,
for example:

_ := S2{}

That blank node will be replaced with "S1{}":

S1{} := S2{}

So constructing an invalid IR which causes the ICE.

Fixes #58325

Change-Id: I21b48357f669a7e02a7eb4325246aadc31f78fb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/465098
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
16 months agomath/rand: use fastrand64 if possible
Ian Lance Taylor [Fri, 3 Feb 2023 06:13:18 +0000 (22:13 -0800)]
math/rand: use fastrand64 if possible

Now that the top-level math/rand functions are auto-seeded by default
(issue #54880), use the runtime fastrand64 function when 1) Seed
has not been called; 2) the GODEBUG randautoseed=0 is not used.

The benchmarks run quickly and are relatively noisy, but they show
significant improvements for parallel calls to the top-level functions.

goos: linux
goarch: amd64
pkg: math/rand
cpu: 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
                           │  /tmp/foo.1   │              /tmp/foo.2               │
                           │    sec/op     │    sec/op      vs base                │
Int63Threadsafe-16            11.605n ± 1%    3.094n ±  1%  -73.34% (p=0.000 n=10)
Int63ThreadsafeParallel-16   67.8350n ± 2%   0.4000n ±  1%  -99.41% (p=0.000 n=10)
Int63Unthreadsafe-16           1.947n ± 3%    1.924n ±  2%        ~ (p=0.189 n=10)
Intn1000-16                    4.295n ± 2%    4.287n ±  3%        ~ (p=0.517 n=10)
Int63n1000-16                  4.379n ± 0%    4.192n ±  2%   -4.27% (p=0.000 n=10)
Int31n1000-16                  3.641n ± 3%    3.506n ±  0%   -3.69% (p=0.000 n=10)
Float32-16                     3.330n ± 7%    3.250n ±  2%   -2.40% (p=0.017 n=10)
Float64-16                     2.194n ± 6%    2.056n ±  4%   -6.31% (p=0.004 n=10)
Perm3-16                       43.39n ± 9%    38.28n ± 12%  -11.77% (p=0.015 n=10)
Perm30-16                      324.4n ± 6%    315.9n ± 19%        ~ (p=0.315 n=10)
Perm30ViaShuffle-16            175.4n ± 1%    143.6n ±  2%  -18.15% (p=0.000 n=10)
ShuffleOverhead-16             223.4n ± 2%    215.8n ±  1%   -3.38% (p=0.000 n=10)
Read3-16                       5.428n ± 3%    5.406n ±  2%        ~ (p=0.780 n=10)
Read64-16                      41.55n ± 5%    40.14n ±  3%   -3.38% (p=0.000 n=10)
Read1000-16                    622.9n ± 4%    594.9n ±  2%   -4.50% (p=0.000 n=10)
Concurrent-16                136.300n ± 2%    4.647n ± 26%  -96.59% (p=0.000 n=10)
geomean                        23.40n         12.15n        -48.08%

Fixes #49892

Change-Id: Iba75b326145512ab0b7ece233b98ac3d4e1fb504
Reviewed-on: https://go-review.googlesource.com/c/go/+/465037
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>

16 months agodoc: fix spec typo
Oleksandr Redko [Tue, 7 Feb 2023 08:21:05 +0000 (08:21 +0000)]
doc: fix spec typo

Change-Id: I5e3aca2b8fc78f38c9e2cdc67adf86d57ac85b1c
GitHub-Last-Rev: 0e5ddffe33f5677449d24e09bdb332e3d5c08aa3
GitHub-Pull-Request: golang/go#58353
Reviewed-on: https://go-review.googlesource.com/c/go/+/465615
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agocmd/go: honor user-specified -c=N
Xiangdong Ji [Thu, 2 Feb 2023 06:20:16 +0000 (14:20 +0800)]
cmd/go: honor user-specified -c=N

User-specified '-c=N' options should take precedence over the default one generated
by cmd/go.

Change-Id: I9021440b4a4286f8d6f92acb745a777cf234a82b
Reviewed-on: https://go-review.googlesource.com/c/go/+/465095
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agotest: add test for issue 58345
Cuong Manh Le [Mon, 6 Feb 2023 07:27:06 +0000 (14:27 +0700)]
test: add test for issue 58345

CL 458619 fixed the problem un-intentionally, so adding test to prevent
regression happening.

Updates #58345

Change-Id: I80cf60716ef85e142d769e8621fce19c826be03d
Reviewed-on: https://go-review.googlesource.com/c/go/+/465455
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
16 months agoruntime: use explicit NOFRAME on darwin/amd64
qmuntal [Tue, 7 Feb 2023 13:53:48 +0000 (14:53 +0100)]
runtime: use explicit NOFRAME on darwin/amd64

This CL marks some darwin assembly functions as NOFRAME to avoid relying
on the implicit amd64 NOFRAME heuristic, where NOSPLIT functions
without stack were also marked as NOFRAME.

This is a second attempt after CL 460235 was reverted.

Change-Id: I790f2108fc01ec193aa32b0bc82362c2344a9f3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/466055
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
16 months agocmd/compile: remove unused ISELB PPC64 ssa opcode
Paul E. Murphy [Thu, 13 Oct 2022 16:37:37 +0000 (11:37 -0500)]
cmd/compile: remove unused ISELB PPC64 ssa opcode

The usage of ISELB has been removed as part of changes
made to support Power10 SETBC instructions.

Change-Id: I2fce4370f48c1eeee65d411dfd1bea4201f45b45
Reviewed-on: https://go-review.googlesource.com/c/go/+/465575
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Archana Ravindar <aravind5@in.ibm.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
16 months agogo/token: delete a blank line
sslime336 [Mon, 6 Feb 2023 19:15:52 +0000 (19:15 +0000)]
go/token: delete a blank line

Change-Id: Ia46da0a6497452df76b770d3c0d16b4b4f135e89
GitHub-Last-Rev: 6a37858ea2de0cc5b89726225c29035a2287c7b9
GitHub-Pull-Request: golang/go#58360
Reviewed-on: https://go-review.googlesource.com/c/go/+/465616
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agoencoding/hex: fix Decode output check regression
Joe Tsai [Mon, 6 Feb 2023 22:48:19 +0000 (14:48 -0800)]
encoding/hex: fix Decode output check regression

CL 461958 fixed a potential panic,
but also introduced an observable regression where
invalid input could be detected before the panic occurs.
Adjust the check to preserve prior behavior,
while also preventing the panic.

Change-Id: I52819f88a6a64883fbc9fd512697c38c29ca0ccd
Reviewed-on: https://go-review.googlesource.com/c/go/+/465855
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
16 months agoruntime: fix cpu sample comment
Maksim Meshkov [Sun, 5 Feb 2023 13:01:19 +0000 (13:01 +0000)]
runtime: fix cpu sample comment

Fixes #58327

Change-Id: I15593e6ee42e04f2de13804ef26e0e66a2307db0
GitHub-Last-Rev: 7e0d04b503d2ba217b76b1ac668a67cd72ec6d7c
GitHub-Pull-Request: golang/go#58338
Reviewed-on: https://go-review.googlesource.com/c/go/+/465335
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agocrypto/ecdh: explicitly reject mismatched curves in ECDH
Roland Shoemaker [Tue, 31 Jan 2023 17:14:16 +0000 (09:14 -0800)]
crypto/ecdh: explicitly reject mismatched curves in ECDH

Return an explicit error when PrivateKey.ECDH is called with a PublicKey
which uses a different Curve. Also document this requirement, even
though it is perhaps obvious.

Fixes #58131

Change-Id: I739181a3f1283bed14fb5ee7eb78658b854d28d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/464335
Reviewed-by: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
Auto-Submit: Roland Shoemaker <roland@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>

16 months agocmd/link: linker portion of dead map removal
Than McIntosh [Wed, 25 Jan 2023 15:46:08 +0000 (10:46 -0500)]
cmd/link: linker portion of dead map removal

This patch contains the linker changes needed to enable deadcoding of
large unreferenced map variables, in combination with a previous
compiler change. We add a new cleanup function that runs just after
deadcode that looks for relocations in "init" funcs that are weak, of
type R_CALL (and siblings), and are targeting an unreachable function.
If we find such a relocation, after checking to make sure it targets a
map.init.XXX helper, we redirect the relocation to a point to a no-op
routine ("mapinitnoop") in the runtime.

Compilebench results for this change:

  │ out.base.txt │            out.wrap.txt            │
  │    sec/op    │   sec/op     vs base               │
 Template                   218.6m ±  2%   221.1m ± 1%       ~ (p=0.129 n=39)
 Unicode                    180.5m ±  1%   178.9m ± 1%  -0.93% (p=0.006 n=39)
 GoTypes                     1.162 ±  1%    1.156 ± 1%       ~ (p=0.850 n=39)
 Compiler                   143.6m ±  1%   142.6m ± 1%       ~ (p=0.743 n=39)
 SSA                         8.698 ±  1%    8.719 ± 1%       ~ (p=0.145 n=39)
 Flate                      142.6m ±  1%   143.9m ± 3%       ~ (p=0.287 n=39)
 GoParser                   247.7m ±  1%   248.8m ± 1%       ~ (p=0.265 n=39)
 Reflect                    588.0m ±  1%   590.4m ± 1%       ~ (p=0.269 n=39)
 Tar                        198.5m ±  1%   201.3m ± 1%  +1.38% (p=0.005 n=39)
 XML                        259.1m ±  1%   260.0m ± 1%       ~ (p=0.376 n=39)
 LinkCompiler               746.8m ±  2%   747.8m ± 1%       ~ (p=0.706 n=39)
 ExternalLinkCompiler        1.906 ±  0%    1.902 ± 1%       ~ (p=0.207 n=40)
 LinkWithoutDebugCompiler   522.4m ± 21%   471.1m ± 1%  -9.81% (p=0.000 n=40)
 StdCmd                      21.32 ±  0%    21.39 ± 0%  +0.32% (p=0.035 n=40)
 geomean                    609.2m         606.0m       -0.53%

  │ out.base.txt │            out.wrap.txt            │
  │ user-sec/op  │ user-sec/op  vs base               │
 Template                    401.9m ± 3%   406.9m ± 2%       ~ (p=0.291 n=39)
 Unicode                     191.9m ± 6%   196.1m ± 3%       ~ (p=0.052 n=39)
 GoTypes                      3.967 ± 3%    4.056 ± 1%       ~ (p=0.099 n=39)
 Compiler                    171.1m ± 3%   173.4m ± 3%       ~ (p=0.415 n=39)
 SSA                          30.04 ± 4%    30.25 ± 4%       ~ (p=0.106 n=39)
 Flate                       246.3m ± 3%   248.9m ± 4%       ~ (p=0.499 n=39)
 GoParser                    518.7m ± 1%   520.6m ± 2%       ~ (p=0.531 n=39)
 Reflect                      1.670 ± 1%    1.656 ± 2%       ~ (p=0.137 n=39)
 Tar                         352.7m ± 2%   360.3m ± 2%       ~ (p=0.117 n=39)
 XML                         528.8m ± 2%   521.1m ± 2%       ~ (p=0.296 n=39)
 LinkCompiler                 1.128 ± 2%    1.140 ± 2%       ~ (p=0.324 n=39)
 ExternalLinkCompiler         2.165 ± 2%    2.147 ± 2%       ~ (p=0.537 n=40)
 LinkWithoutDebugCompiler    484.2m ± 4%   490.7m ± 3%       ~ (p=0.897 n=40)
 geomean                     818.5m        825.1m       +0.80%

   │ out.base.txt │             out.wrap.txt              │
   │  text-bytes  │  text-bytes   vs base                 │
 HelloSize   766.0Ki ± 0%   766.0Ki ± 0%       ~ (p=1.000 n=40) ¹
 CmdGoSize   10.02Mi ± 0%   10.02Mi ± 0%  -0.03% (n=40)
 geomean     2.738Mi        2.738Mi       -0.01%
 ¹ all samples are equal

   │ out.base.txt │             out.wrap.txt              │
   │  data-bytes  │  data-bytes   vs base                 │
 HelloSize   14.17Ki ± 0%   14.17Ki ± 0%       ~ (p=1.000 n=40) ¹
 CmdGoSize   308.3Ki ± 0%   298.5Ki ± 0%  -3.19% (n=40)
 geomean     66.10Ki        65.04Ki       -1.61%
 ¹ all samples are equal

   │ out.base.txt │             out.wrap.txt              │
   │  bss-bytes   │  bss-bytes    vs base                 │
 HelloSize   197.3Ki ± 0%   197.3Ki ± 0%       ~ (p=1.000 n=40) ¹
 CmdGoSize   228.2Ki ± 0%   228.1Ki ± 0%  -0.01% (n=40)
 geomean     212.2Ki        212.1Ki       -0.01%
 ¹ all samples are equal

   │ out.base.txt │            out.wrap.txt             │
   │  exe-bytes   │  exe-bytes    vs base               │
 HelloSize   1.192Mi ± 0%   1.192Mi ± 0%  +0.00% (p=0.000 n=40)
 CmdGoSize   14.85Mi ± 0%   14.83Mi ± 0%  -0.09% (n=40)
 geomean     4.207Mi        4.205Mi       -0.05%

Also tested for any linker changes by benchmarking relink of k8s
"kubelet"; no changes to speak of there.

Updates #2559.
Updates #36021.
Updates #14840.

Change-Id: I4cc5370b3f20679a1065aaaf87bdf2881e257631
Reviewed-on: https://go-review.googlesource.com/c/go/+/463395
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agocmd/compile: enable deadcode of unreferenced large global maps
Than McIntosh [Tue, 10 Jan 2023 15:21:16 +0000 (10:21 -0500)]
cmd/compile: enable deadcode of unreferenced large global maps

This patch changes the compiler's pkg init machinery to pick out large
initialization assignments to global maps (e.g.

   var mymap = map[string]int{"foo":1, "bar":2, ... }

and extract the map init code into a separate outlined function, which is
then called from the main init function with a weak relocation:

   var mymap map[string]int   // KEEP reloc -> map.init.0

   func init() {
      map.init.0() // weak relocation
   }

   func map.init.0() {
     mymap = map[string]int{"foo":1, "bar":2}
   }

The map init outlining is done selectively (only in the case where the
RHS code exceeds a size limit of 20 IR nodes).

In order to ensure that a given map.init.NNN function is included when
its corresponding map is live, we add dummy R_KEEP relocation from the
map variable to the map init function.

This first patch includes the main compiler compiler changes, and with
the weak relocation addition disabled. Subsequent patch includes the
requred linker changes along with switching to the call to the
outlined routine to a weak relocation. See the later linker change for
associated compile time performance numbers.

Updates #2559.
Updates #36021.
Updates #14840.

Change-Id: I1fd6fd6397772be1ebd3eb397caf68ae9a3147e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/461315
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agocmd/compile: ensure first instruction in a function is not inlined
Keith Randall [Fri, 3 Feb 2023 17:59:55 +0000 (09:59 -0800)]
cmd/compile: ensure first instruction in a function is not inlined

People are using this to get the name of the function from a function type:

runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()

Unfortunately, this technique falls down when the first instruction
of the function is from an inlined callee. Then the expression above
gets you the name of the inlined function instead of the function itself.

To fix this, ensure that the first instruction is never from an inlinee.
Normally functions have prologs so those are already fine. In just the
cases where a function is a leaf with no local variables, and an instruction
from an inlinee appears first in the prog list, add a nop at the start
of the function to hold a non-inlined position.

Consider the nop a "mini-prolog" for leaf functions.

Fixes #58300

Change-Id: Ie37092f4ac3167fe8e5ef4a2207b14abc1786897
Reviewed-on: https://go-review.googlesource.com/c/go/+/465076
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: David Chase <drchase@google.com>
16 months agocmd/internal/obj: flag init functions in object file
Than McIntosh [Thu, 26 Jan 2023 20:12:00 +0000 (15:12 -0500)]
cmd/internal/obj: flag init functions in object file

Introduce a flag in the object file indicating whether a given
function corresponds to a compiler-generated (not user-written) init
function, such as "os.init" or "syscall.init". Add code to the
compiler to fill in the correct value for the flag, and add support to
the loader package in the linker for testing the flag. The new loader
API is currently unused, but will be needed in the next CL in this
stack.

Updates #2559.
Updates #36021.
Updates #14840.

Change-Id: Iea7ad2adda487e4af7a44f062f9817977c53b394
Reviewed-on: https://go-review.googlesource.com/c/go/+/463855
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agogo/types, types2: eliminate need to sort arguments for type inference
Robert Griesemer [Thu, 2 Feb 2023 04:03:17 +0000 (20:03 -0800)]
go/types, types2: eliminate need to sort arguments for type inference

When unifying types, we always consider underlying types if inference
would fail otherwise. If a type parameter has a (non-defined) type
inferred and later matches against a defined type, make sure to keep
that defined type instead.

For #43056.

Change-Id: I24e4cd2939df7c8069e505be10914017c1c1c288
Reviewed-on: https://go-review.googlesource.com/c/go/+/464348
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>

16 months agolog: fix and cleanup trailing newline logic
Joe Tsai [Sat, 4 Feb 2023 19:30:18 +0000 (11:30 -0800)]
log: fix and cleanup trailing newline logic

The intent was to always append a newline if a newline was missing.
The older logic accidentally only checked the payload for newlines
and forgot to check the prefix as well. Fix it to check both together.

This changes the output of Logger.Output in the situation where
the prefix contains a trailing newline and the output is empty.
This is a very rare combination and unlikely to occur in practice.

Change-Id: Ic04ded6c29a90383e29bf7f59223a808ee1cbdc0
Reviewed-on: https://go-review.googlesource.com/c/go/+/465316
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

16 months agocrypto/sha1: use math/bits.RotateLeft32
Alexander Yastrebov [Mon, 24 Oct 2022 15:46:18 +0000 (15:46 +0000)]
crypto/sha1: use math/bits.RotateLeft32

Updates #31456

Change-Id: I68e0abfb6771c9b1d1bfcbb642db9eb5540f9cab
GitHub-Last-Rev: 17ea697c5c0bbfdfb1ad91c2c60e22f6efc78b43
GitHub-Pull-Request: golang/go#49051
Reviewed-on: https://go-review.googlesource.com/c/go/+/356516
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
16 months agocmd/compile: replace os.MkdirTemp with T.TempDir
Oleksandr Redko [Thu, 2 Feb 2023 10:09:10 +0000 (10:09 +0000)]
cmd/compile: replace os.MkdirTemp with T.TempDir

Updates #45402

Change-Id: Ieffd1c8b0b5e4e63024b5be2e1f910fb4411eb94
GitHub-Last-Rev: fa7418c8eb977b7214311e774f9df7a1220a3dfd
GitHub-Pull-Request: golang/go#57940
Reviewed-on: https://go-review.googlesource.com/c/go/+/462896
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>

16 months agomath/big: add warning about using Int for cryptography
Filippo Valsorda [Mon, 5 Dec 2022 11:59:55 +0000 (12:59 +0100)]
math/big: add warning about using Int for cryptography

Change-Id: I31bec5d2b4a79a085942c7d380678379d99cf07b
Reviewed-on: https://go-review.googlesource.com/c/go/+/455135
Auto-Submit: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
16 months agocrypto/rand: replace shift with constant
Johan Brandhorst-Satzkorn [Sat, 4 Feb 2023 05:14:05 +0000 (21:14 -0800)]
crypto/rand: replace shift with constant

It was mentioned after CL 463993 was merged that it
is uncommon to use shifts for numbers other than
powers of ten. Replace the shift with a base 10 constant.

Change-Id: I11c90128740109a59add40ed7b680f7bcc9715ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/465275
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agocmd/asm: add RDTIME{L,H}.W, RDTIME.D support for loong64
Guoqi Chen [Thu, 4 Aug 2022 10:13:59 +0000 (18:13 +0800)]
cmd/asm: add RDTIME{L,H}.W, RDTIME.D support for loong64

Instruction formats: rdtime rd, rj

The RDTIME family of instructions are used to read constant frequency timer
information, the stable counter value is written into the general register
rd, and the counter id information is written into the general register rj.
(Note: both of its register operands are outputs).

Ref: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html

Change-Id: Ida5bbb28316ef70b5f616dac3e6fa6f2e77875b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/421655
Reviewed-by: xiaodong liu <teaofmoli@gmail.com>
Reviewed-by: WANG Xuerui <git@xen0n.name>
Reviewed-by: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Meidan Li <limeidan@loongson.cn>
16 months agocmd/compile: add rules to emit SETBC/R instructions on power10
Archana R [Fri, 11 Nov 2022 12:10:59 +0000 (06:10 -0600)]
cmd/compile: add rules to emit SETBC/R instructions on power10

This CL adds rules that replaces instances of ISEL that produce
a boolean result based on a condition register by SETBC/SETBCR
operations. On Power10 these are convereted to SETBC/SETBCR
instructions that use one register instead of 3 registers
conventionally used by ISEL and hence reduces register pressure.
On loops written specifically to exercise such instances of ISEL
extensively, a performance improvement of 2.5% is seen on Power10.
Also added verification tests to verify correct generation of
SETBC/SETBCR instructions on Power10.

Change-Id: Ib719897f09d893de40324440a43052dca026e8fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/449795
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Archana Ravindar <aravind5@in.ibm.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agoall: upgrade Unicode from 13.0.0 to 15.0.0
weebney [Mon, 12 Dec 2022 19:10:54 +0000 (19:10 +0000)]
all: upgrade Unicode from 13.0.0 to 15.0.0

Update unicode/tables.go to reflect changes in the Unicode Standard up to
Unicode 15.0.0, released 13 Sept 2022.

In order to accommodate this update, strconv/isPrint has been updated to
reflect changes in printable characters.

Also changed is template/exec_test.go for both text and html packages- in
the test "TestJSEscaping", rune U+FDFF was used as a placeholder for an
unprintable character. This codepoint was assigned and made printable in
Unicode 14.0.0, breaking this test. It has been replaced with the assigned
and never-printable U+FFFE to fix the test and provide resiliency in the
future.

This upgrade bypasses Unicode 14.0.0, but is compatible.

Updates https://github.com/golang/go/issues/48621
Fixes https://github.com/golang/go/issues/55079

Change-Id: I40efd097eb746db0727ebf7437280916d1242e47
GitHub-Last-Rev: c8885cab7a0c23632e1e5a433b1e8d5634a45a30
GitHub-Pull-Request: golang/go#57265
Reviewed-on: https://go-review.googlesource.com/c/go/+/456837
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Rob Pike <r@golang.org>
16 months agolog: make use of fmt.Append functionality
Joe Tsai [Thu, 2 Feb 2023 02:18:57 +0000 (18:18 -0800)]
log: make use of fmt.Append functionality

Since log is already responsible for managing its own buffers
it is unfortunate that it calls fmt.Sprintf, which allocates,
only to append that intermediate string to another buffer.
Instead, use the new fmt.Append variants and avoid the allocation.

We modify Logger.Output to wrap an internal Logger.output,
which can be configured to use a particular append function.
Logger.output is called from all the other functionality instead.

This has the further advantage of simplifying the isDiscard check,
which occurs to avoid the costly fmt.Print call.
We coalesce all 6 checks as just 1 check in Logger.output.

Also, swap the declaration order of Logger.Print and Logger.Printf
to match the ordering elsewhere in the file.

Performance:
name               old time/op    new time/op    delta
Println            188ns ± 2%     172ns ± 4%    -8.39%  (p=0.000 n=10+10)
PrintlnNoFlags     139ns ± 1%     116ns ± 1%   -16.71%  (p=0.000 n=9+9)

name               old allocs/op  new allocs/op  delta
Println             1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
PrintlnNoFlags      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)

Change-Id: I79d0ee404df848beb3626fe863ccc73a3e2eb325
Reviewed-on: https://go-review.googlesource.com/c/go/+/464345
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agocmd/compile: use ONAME node directly from generated hash func
Cuong Manh Le [Fri, 30 Sep 2022 05:24:46 +0000 (12:24 +0700)]
cmd/compile: use ONAME node directly from generated hash func

Same as CL 436436, but for hashfor.

However, this passes toolstash-check, because the order of compiling
functions do not change.

Change-Id: Icc7d042e9c28b0fe4bb40a2b98b7f60cf3549bd1
Reviewed-on: https://go-review.googlesource.com/c/go/+/436961
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>

16 months agocmd/compile: factor out code to generate hash func
Cuong Manh Le [Fri, 30 Sep 2022 04:01:43 +0000 (11:01 +0700)]
cmd/compile: factor out code to generate hash func

Passes toolstash-check.

Change-Id: I86a078ffc5948cbcbec84ce8012f3dfb1c2269b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/436960
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
16 months agocmd/compile: use runtime hash func for known types
Cuong Manh Le [Fri, 30 Sep 2022 05:04:46 +0000 (12:04 +0700)]
cmd/compile: use runtime hash func for known types

Those functions are defined in package runtime already, so just use them
instead of creating ONAME nodes with nil Func.

Change-Id: If29814a5254793c578c15b70f9c194b7414911d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/436959
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
16 months agocmd/compile: use memhash from package runtime
Cuong Manh Le [Fri, 30 Sep 2022 04:51:48 +0000 (11:51 +0700)]
cmd/compile: use memhash from package runtime

Simplify the code, and prevent creating ONAME node with nil Func.

Passes toolstash-check.

Change-Id: I5e5be660510dc0ef5521d278c6b9214a80b994eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/436958
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
16 months agocmd/compile: generate type equal func during walk
Cuong Manh Le [Wed, 28 Sep 2022 05:30:46 +0000 (12:30 +0700)]
cmd/compile: generate type equal func during walk

So we don't generate ONAME node with nil Func.

Do not pass toolstash-check because the CL changes the order of
compiling functions.

Change-Id: Ib967328f36b8c59a5525445667103c0c80ccdc82
Reviewed-on: https://go-review.googlesource.com/c/go/+/436436
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>

16 months agocmd/compile: factor out code to generate equal func
Cuong Manh Le [Wed, 28 Sep 2022 03:20:25 +0000 (10:20 +0700)]
cmd/compile: factor out code to generate equal func

So next CL can use it for generating equal func during walk compare.

Passes toolstash-check.

Change-Id: I76545c1d471eb496be352908db1b05feae83fc33
Reviewed-on: https://go-review.googlesource.com/c/go/+/436435
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
16 months agonet/http/httputil: fix syntax in ReverseProxy example comment
Ethan Lowman [Fri, 3 Feb 2023 18:35:28 +0000 (13:35 -0500)]
net/http/httputil: fix syntax in ReverseProxy example comment

Change-Id: I7e71626246af94047fbd1abb9bb77f2cd9b281fb
Reviewed-on: https://go-review.googlesource.com/c/go/+/465195
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>

16 months agotime: add /etc/zoneinfo as valid path for tzdata for NixOS
David Anderson [Thu, 2 Feb 2023 20:13:46 +0000 (20:13 +0000)]
time: add /etc/zoneinfo as valid path for tzdata for NixOS

NixOS has no /usr/share, but does have tzdata at /etc/zoneinfo.

Change-Id: Ic7d7f42a215e06c2e4f5c54ee11db82240f27167
GitHub-Last-Rev: 9969dd3e2cc49b30c3cd6b0858cb60b00bcbdf60
GitHub-Pull-Request: golang/go#58267
Reviewed-on: https://go-review.googlesource.com/c/go/+/464995
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
16 months agocontext: remove one allocation in timerCtx
Carlo Alberto Ferraris [Thu, 2 Feb 2023 02:07:34 +0000 (11:07 +0900)]
context: remove one allocation in timerCtx

Embed the cancelCtx into timerCtx, instead of allocating both separately.

name                               old time/op    new time/op    delta
WithTimeout/concurrency=40-16        2.21µs ±11%    2.08µs ± 5%   -5.76%  (p=0.011 n=10+10)
WithTimeout/concurrency=4000-16      1.94µs ± 6%    1.86µs ±10%     ~     (p=0.099 n=9+10)
WithTimeout/concurrency=400000-16    1.86µs ± 7%    1.83µs ±10%     ~     (p=0.353 n=10+10)

name                               old alloc/op   new alloc/op   delta
WithTimeout/concurrency=40-16        2.56kB ± 0%    2.40kB ± 0%   -6.25%  (p=0.001 n=8+9)
WithTimeout/concurrency=4000-16      2.56kB ± 0%    2.40kB ± 0%   -6.25%  (p=0.000 n=9+10)
WithTimeout/concurrency=400000-16    2.56kB ± 0%    2.40kB ± 0%   -6.26%  (p=0.000 n=9+9)

name                               old allocs/op  new allocs/op  delta
WithTimeout/concurrency=40-16          50.0 ± 0%      40.0 ± 0%  -20.00%  (p=0.000 n=10+10)
WithTimeout/concurrency=4000-16        50.0 ± 0%      40.0 ± 0%  -20.00%  (p=0.000 n=10+10)
WithTimeout/concurrency=400000-16      50.0 ± 0%      40.0 ± 0%  -20.00%  (p=0.000 n=10+10)

Change-Id: Ia0460db3b8412fbaa6f1539fd6b4fb1b873896c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/463999
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

16 months agolog: reduce lock contention
Joe Tsai [Wed, 1 Feb 2023 21:23:02 +0000 (13:23 -0800)]
log: reduce lock contention

Logger.Log methods are called in a highly concurrent manner in many servers.
Acquiring a lock in each method call results in high lock contention,
especially since each lock covers a non-trivial amount of work
(e.g., formatting the header and outputting to the writer).

Changes made:
* Modify the Logger to use atomics so that the header formatting
  can be moved out of the critical lock section.
  Acquiring the flags does not occur in the same critical section
  as outputting to the underlying writer, so this introduces
  a very slight consistency instability where concurrently calling
  multiple Logger.Output along with Logger.SetFlags may cause
  the older flags to be used by some ongoing Logger.Output calls
  even after Logger.SetFlags has returned.
* Use a sync.Pool to buffer the intermediate buffer.
  This approach is identical to how fmt does it,
  with the same max cap mitigation for #23199.
* Only protect outputting to the underlying writer with a lock
  to ensure serialized ordering of output.

Performance:
name           old time/op  new time/op  delta
Concurrent-24  19.9µs ± 2%   8.3µs ± 1%  -58.37%  (p=0.000 n=10+10)

Updates #19438

Change-Id: I091beb7431d8661976a6c01cdb0d145e37fe3d22
Reviewed-on: https://go-review.googlesource.com/c/go/+/464344
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
16 months agocmd/compile: intrinsify math/bits/ReverseBytes{16|32|64} for ppc64/power10
Archana R [Mon, 31 Oct 2022 16:47:17 +0000 (11:47 -0500)]
cmd/compile: intrinsify math/bits/ReverseBytes{16|32|64} for ppc64/power10

This change intrinsifies ReverseBytes{16|32|64} by generating the
corresponding new instructions in Power10: brh, brd and brw and
adds a verification test for the same.
On Power 9 and 8, the .go code performs optimally as it is.

Performance improvement seen on Power10:
ReverseBytes32  1.38ns ± 0%  1.18ns ± 0%  -14.2
ReverseBytes64  1.52ns ± 0%  1.11ns ± 0%  -26.87
ReverseBytes16  1.41ns ± 1%  1.18ns ± 0%  -16.47

Change-Id: I88f127f3ab9ba24a772becc21ad90acfba324b37
Reviewed-on: https://go-review.googlesource.com/c/go/+/446675
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
16 months agomaps: new package
Ian Lance Taylor [Wed, 1 Feb 2023 21:47:48 +0000 (13:47 -0800)]
maps: new package

This copies x/exp/maps into the standard library (except for the Clear
function which is now available as the clear builtin.)

Fixes #57436

Change-Id: I30dd470c2f7ae34c7c82b4c1025a7582d61fabaa
Reviewed-on: https://go-review.googlesource.com/c/go/+/464343
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Eli Bendersky <eliben@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
16 months agocmd/dist: do not include runtime/internal/sys in cmd staleness checks
Bryan C. Mills [Fri, 3 Feb 2023 14:59:16 +0000 (09:59 -0500)]
cmd/dist: do not include runtime/internal/sys in cmd staleness checks

Since CL 454836, cmd/dist has built the packages in 'cmd' with
different settings than those in 'std': namely, for' cmd' we disable
the use of cgo, and (since CL 463740) if GO_BUILDER_NAME is non-empty
or the VERSION file indicates a release version we also set
GOFLAGS=-trimpath.

However, since at least CL 73212 the staleness checks performed by
cmd/dist for the “toolchain” targets (a subset of 'cmd') have included
the package "runtime/internal/sys" (which is in 'std', not 'cmd').
At that time, cmd/go did not have a separate build cache, so it would
not have been possible to check staleness for a 'cmd' build differently
from 'std'. However, now that is possible, and most of the time
"runtime/internal/sys" lives *only* in the build cache (and so is
essentially never stale after building anything that imports it).

But there is one more wrinkle: if GODEBUG=installgoroot=all is set,
the packages in 'std' are still installed to GOROOT/pkg, and can once
again become stale. Since the install with the 'std' configuration does
not match the configuration used to build 'cmd', the staleness check
fails for "runtime/internal/sys" under the 'cmd' configuration.

Since we intentionally build the toolchain with a different
"runtime/internal/sys" stored only in the build cache, there is no
longer a point in checking that package for staleness: if it is stale,
then the toolchain itself will be reported as stale anyway.
So we can simply remove the package from that staleness check,
and unbreak bootstrapping with GODEBUG=installgoroot=all.

I tested this manually using the sequence:

export GODEBUG=installgoroot=all
export GO_BUILDER_NAME=linux-amd64-bcmills
./make.bash

It fails the staleness check before this change, and successfully
builds after.

For #24904.

Change-Id: I376e93e35129694a093c6675e20905a097a8b64b
Reviewed-on: https://go-review.googlesource.com/c/go/+/465155
Reviewed-by: Russ Cox <rsc@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>

16 months agocmd/go/internal/par: use generic Cache
Roger Peppe [Mon, 30 Jan 2023 17:27:42 +0000 (17:27 +0000)]
cmd/go/internal/par: use generic Cache

Using generics here makes the code easier to understand,
as the contract is clearly specified. It also makes the
code a little more concise, as it's easy to write a wrapper
for the cache that adds an error value, meaning that
a bunch of auxilliary types no longer need to be defined
for this common case.

The load.cachingRepo code has been changed to use a separate
cache for each key-value type combination, which seems a bit less
sleazy, but might have some knock-on effect on memory usage,
and could easily be changed back if desired.

Because there's no longer an unambiguous way to find out
whether there's an entry in the cache, the Cache.Get method
now returns a bool as well as the value itself.

Change-Id: I28443125bab0b3720cc95d750e72d28e9b96257d
Reviewed-on: https://go-review.googlesource.com/c/go/+/463843
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: roger peppe <rogpeppe@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
16 months agodebug/elf: add DT_FLAGS_1 constants
Florin Papa [Mon, 21 Nov 2022 18:07:58 +0000 (10:07 -0800)]
debug/elf: add DT_FLAGS_1 constants

Add constants for all ELF dynamic flags (pertaining to DT_FLAGS_1). This will help, for example, determining whether an object is a position-independent executable (PIE). The constants are defined according to Table 15-10 in https://docs.oracle.com/en/operating-systems/solaris/oracle-solaris/11.4/linkers-libraries/dynamic-section.html.

Fixes #56887

Change-Id: I6cd501af50d9dbcc2aa8a9a002e12c6fb6726761
Reviewed-on: https://go-review.googlesource.com/c/go/+/452496
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agogo/types, types2: enable new type inference
Robert Griesemer [Wed, 1 Feb 2023 18:00:29 +0000 (10:00 -0800)]
go/types, types2: enable new type inference

Enable new type inference and compare result with old inference
implementation - the result must be identical in a correct program.

Change-Id: Ic802d29fcee744f6f826d5e433a3d0c0e73b68e3
Reviewed-on: https://go-review.googlesource.com/c/go/+/464341
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
16 months agogo/types, types2: implement simpler type inference (infer2)
Robert Griesemer [Mon, 30 Jan 2023 23:54:10 +0000 (15:54 -0800)]
go/types, types2: implement simpler type inference (infer2)

This change implements infer2 which is a drop-in replacement for
infer; it can be enabled by setting the useNewTypeInference flag
in infer2.go. It is currently disabled (but tested manually).

infer2 uses the same machinery like infer but in a simpler approach
that is more amenable to precise description and future extensions.

The goal of type inference is to determine a set of (missing) type
arguments from a set of other given facts. Currently, these other
facts are function arguments and type constraints.

In the following, when we refer to "type parameters", we mean the
type parameters defined by the generic function to which we apply
type inference. More precisely, in the algorithm, these are the
type parameters recorded with the unifier.

The approach is as follows:

- A single unifier is set up which tracks all type parameters and
  corresponding inferred types.

- The unifier is then fed all the facts we have. The order is not
  relevant (*) except that we use default types of untyped constant
  arguments only as a last resort, at the end.

- We start with all function arguments: for each generic function
  parameter with a typed function argument, we unify the parameter
  and function type.

- We then unify each type parameter with its type constraint.
  This step is iterated until nothing changes anymore, because
  each unification may enable further unification.

- If there are any type parameters left without inferred types,
  and which are used as function parameters with untyped constant
  arguments, unify them with the default types of those arguments.

Because of unification with constraints which themselves may contain
type parameters, inferred types may contain type parameters. Thus,
in a final step we substitute type parameters for their inferred types
until there are no type parameters left in the inferred types.

All these individual steps are the same as in infer, but there is no
need to do constraint type inference twice (all the facts have already
been used for inference). Also, we only need a single unifier which
serves as the holder for the inferred type parameter types.

Type inference fails if any unification step fails or if not all
type arguments could be inferred. By always using all available
facts (**) we ensure that order doesn't matter.

By using more facts, type inference can now be extended to become
more powerful.

The code can be split up into smaller components that are more
easily digestable. Because we forsee more simplifications, we
defer such cleanups to later CLs.

(*) We currently have a sorting phase in the beginning such that
    function argument types that are named types are used before
    any other type. We believe this step can be eliminated by
    modifying the unifier slightly.

(**) When unifying constraints, in some cases we don't report
    an error if unification fails. We believe we can modify the
    unifier and then consistently report an inference failure
    in this case as well.

Change-Id: If1640a5461bc102fa7fd31dc6e741be667c97e7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/463746
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agogo/types, types2: simplify symmetric code
Robert Griesemer [Thu, 2 Feb 2023 18:14:58 +0000 (10:14 -0800)]
go/types, types2: simplify symmetric code

Because unification is symmetric, in cases where we have symmetric
code for x and y depending on some property we can swap x and y as
needed and simplify the code.

Also, change u.depth increment/decrement position for slightly
nicer tracing ooutput.

Change-Id: I2e84570d463d1c32f6556108f3cb54062b57c718
Reviewed-on: https://go-review.googlesource.com/c/go/+/464896
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
16 months agogo/types, types2: use a comparer struct to control the identical predicate
Robert Griesemer [Thu, 2 Feb 2023 22:16:23 +0000 (14:16 -0800)]
go/types, types2: use a comparer struct to control the identical predicate

This makes it easier to configure the behavior of identical: we can
simply add fields to the comparer instead of adding more parameters
to identical.

Change-Id: I9a6f5451b3ee5c37e71486060653c5a6e8f24304
Reviewed-on: https://go-review.googlesource.com/c/go/+/464937
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
16 months agocmd/go/internal/test: scale the WaitDelay for test subprocesses
Bryan C. Mills [Wed, 1 Feb 2023 21:44:21 +0000 (16:44 -0500)]
cmd/go/internal/test: scale the WaitDelay for test subprocesses

Prior to CL 456116 we had an arbitrary 5-second delay after a test
times out before we kill the test. In CL 456116, I reused that
arbitrary 5-second delay as the WaitDelay as well, but on slower
builders it does not seem to be generous enough.

Instead of hard-coding the delay, for tests with a finite timout we
now use a hard-coded fraction of the overall timeout. That will
probably give delays that are longer than strictly necessary for very
long timeouts, but if the user is willing to wait for a very long
timeout they can probably wait a little longer for I/O too.

Fixes #58230.
Updates #24050.

Change-Id: Ifbf3e576c034c721aa00cd17bf88563474b09955
Reviewed-on: https://go-review.googlesource.com/c/go/+/464555
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>

16 months agoruntime: eliminate arbitrary timeout in TestCgoLockOSThreadExit
Bryan C. Mills [Thu, 2 Feb 2023 15:09:39 +0000 (10:09 -0500)]
runtime: eliminate arbitrary timeout in TestCgoLockOSThreadExit

This test previously failed if running a new pthread took longer than
a hard-coded 100ms. On some slow or heavily-loaded builders, that
scheduling latency is too short.

Since the point of this test is to verify that the background thread
is not reused after it terminates (see #20395), the arbitrary time
limit does not seem helpful: if the background thread fails to
terminate the test will time out on its own, and if the main goroutine
is scheduled on the background thread the test will fail regardless of
how long it takes.

Fixes #58247.

Change-Id: I626af52aac55af7a4c0e7829798573c479750c20
Reviewed-on: https://go-review.googlesource.com/c/go/+/464735
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

16 months agomath/big: add Int.Float64 conversion
Alan Donovan [Tue, 27 Dec 2022 19:10:18 +0000 (14:10 -0500)]
math/big: add Int.Float64 conversion

This operation converts a big.Int to float64,
reporting the accuracy of the result, with
a fast path in hardware.

Fixes #56984

Change-Id: I86d0fb0e105a06a4009986f2f5fd87a4d446f6f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/453115
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>

16 months agointernal/testenv: avoid rebuilding all of std in WriteImportcfg
Bryan C. Mills [Thu, 2 Feb 2023 15:42:46 +0000 (10:42 -0500)]
internal/testenv: avoid rebuilding all of std in WriteImportcfg

Instead, have the caller pass in an explicit list of the packages
(if any) they need.

After #47257, a builder running a test does not necessarily have the
entire standard library already cached, especially when running tests
in sharded mode. testenv.WriteImportcfg used to write an importcfg for
the entire standard library — which required rebuilding the entire
standard library — even though most tests need only a tiny subset.

This reduces the time to test internal/abi with a cold build cache on
my workstation from ~16s to ~0.05s.

It somewhat increases the time for 'go test go/internal/gcimporter'
with a cold cache, from ~43s to ~54s, presumably due to decreased
parallelism in rebuilding the standard library and increased overhead
in re-resolving the import map. However, 'go test -short' running time
remains stable (~5.5s before and after).

Fixes #58248.

Change-Id: I9be6b61ae6e28b75b53af85207c281bb93b9346f
Reviewed-on: https://go-review.googlesource.com/c/go/+/464736
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>

16 months agogo/token: add (*File).Lines method
Alan Donovan [Wed, 1 Feb 2023 19:15:41 +0000 (14:15 -0500)]
go/token: add (*File).Lines method

This method returns the array updated by SetLines, for
use in exporter packages.

Fixes #57708

Change-Id: I12ed5e7e1bae7517f40cb25e76e51997c25d84f4
Reviewed-on: https://go-review.googlesource.com/c/go/+/464515
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Alan Donovan <adonovan@google.com>

16 months agosrc/cmd/compile: clarify //go:linkname documentation
Alan Donovan [Mon, 23 Jan 2023 16:21:27 +0000 (11:21 -0500)]
src/cmd/compile: clarify //go:linkname documentation

Change-Id: I0407950bfc84082683012944b2051e46dc682ba0
Reviewed-on: https://go-review.googlesource.com/c/go/+/463136
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>