]> Cypherpunks.ru repositories - gostls13.git/log
gostls13.git
21 months agomisc: use strings.Builder
cuiweixie [Sun, 4 Sep 2022 09:21:08 +0000 (17:21 +0800)]
misc: use strings.Builder

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

21 months agoRevert "runtime: convert local var stop,ready at TestDebugCallUnsafePoint to atomic...
Daniel Martí [Mon, 5 Sep 2022 08:30:02 +0000 (08:30 +0000)]
Revert "runtime: convert local var stop,ready at TestDebugCallUnsafePoint to atomic type"

This reverts https://go.dev/cl/427135.

Reason for revert: broke the test it modified on linux-amd64-noopt.

    --- FAIL: TestDebugCallUnsafePoint (0.00s)
        debug_test.go:265: want "call not at safe point", got %!s(<nil>)

Change-Id: I044c9720aed2d5e48b56bd7ab2781462270dcae9
Reviewed-on: https://go-review.googlesource.com/c/go/+/428395
Reviewed-by: xie cui <523516579@qq.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: hopehook <hopehook@golangcn.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
21 months agointernal/trace: use strings.Builder
cuiweixie [Sun, 4 Sep 2022 10:02:51 +0000 (18:02 +0800)]
internal/trace: use strings.Builder

Change-Id: Ic7f827b8ee758c991ed76be65026b0330207deea
Reviewed-on: https://go-review.googlesource.com/c/go/+/428262
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
21 months agoRevert "internal/poll: drop redundant ENOSYS and EXDEV error checks in CopyFileRange()"
Daniel Martí [Mon, 5 Sep 2022 08:37:48 +0000 (08:37 +0000)]
Revert "internal/poll: drop redundant ENOSYS and EXDEV error checks in CopyFileRange()"

This reverts https://go.dev/cl/425881.

Reason for revert: broke make.bash on linux/amd64 with Linux 5.19.6.

[...]
Building Go toolchain2 using go_bootstrap and Go toolchain1.
go install internal/unsafeheader: copying /tmp/go-build4206185186/b007/_pkg_.a to /home/mvdan/tip/pkg/linux_amd64/internal/unsafeheader.a: write /home/mvdan/tip/pkg/linux_amd64/internal/unsafeheader.a: copy_file_range: invalid cross-device link
go install internal/goarch: copying /tmp/go-build4206185186/b006/_pkg_.a to /home/mvdan/tip/pkg/linux_amd64/internal/goarch.a: write /home/mvdan/tip/pkg/linux_amd64/internal/goarch.a: copy_file_range: invalid cross-device link
[...]

Change-Id: I793856935d4315a870c2d31da46be00cc342b5f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/428396
Reviewed-by: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: hopehook <hopehook@golangcn.org>
Reviewed-by: Andy Pan <panjf2000@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
21 months agointernal/syscall/unix: KernelVersion nitpicks
Kir Kolyshkin [Thu, 1 Sep 2022 21:50:26 +0000 (14:50 -0700)]
internal/syscall/unix: KernelVersion nitpicks

A few minor improvements for KernelVersion for the sake of readability.

Change-Id: I06d2df60ecee8ee0ae603952470fb73e7dcd5d74
Reviewed-on: https://go-review.googlesource.com/c/go/+/427676
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>

21 months agointernal/syscall/unix: simplify KernelVersion
Kir Kolyshkin [Thu, 1 Sep 2022 21:43:39 +0000 (14:43 -0700)]
internal/syscall/unix: simplify KernelVersion

Since values[2] elements are initialized with 0, the switch statement
doesn't do anything. Remove it.

Change-Id: I41176692cdf0c01fe8e85315f0c0dc8b0f3d41fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/427675
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
21 months agoruntime: refactor finalizer goroutine status
Leonard Wang [Wed, 13 Apr 2022 13:14:22 +0000 (21:14 +0800)]
runtime: refactor finalizer goroutine status

Use an atomic.Uint32 to represent the state of finalizer goroutine.
fingStatus will only be changed to fingWake in non fingWait state,
so it is safe to set fingRunningFinalizer status in runfinq.

name            old time/op  new time/op  delta
Finalizer-8      592µs ± 4%   561µs ± 1%  -5.22%  (p=0.000 n=10+10)
FinalizerRun-8   694ns ± 6%   675ns ± 7%    ~     (p=0.059 n=9+8)

Change-Id: I7e4da30cec98ce99f7d8cf4c97f933a8a2d1cae1
Reviewed-on: https://go-review.googlesource.com/c/go/+/400134
Reviewed-by: Joedian Reid <joedian@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Michael Pratt <mpratt@google.com>
21 months agogo/ast: add Range token.Pos to RangeStmt
cuiweixie [Sat, 27 Aug 2022 07:21:29 +0000 (15:21 +0800)]
go/ast: add Range token.Pos to RangeStmt

For #50429

Change-Id: Idb027244f901d9f482c894b5b979a054d0f07de5
Reviewed-on: https://go-review.googlesource.com/c/go/+/426091
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>

21 months agointernal/poll: drop redundant ENOSYS and EXDEV error checks in CopyFileRange()
Andy Pan [Sat, 27 Aug 2022 02:44:25 +0000 (10:44 +0800)]
internal/poll: drop redundant ENOSYS and EXDEV error checks in CopyFileRange()

The initial CL 229101 didn't limit the kernel version, but relies on error checking to
ensure the kernel version >= 4.5 or >= 5.3 when it's calling copy_file_range(2) to copy data across file systems.

Since we have now put the kernel version checking at the beginning of the function, introduced by CL 268338,
which returns early instead of going forward to the code behind when the kernel verion is older than 5.3,
therefore, those subsequent related error checks are no longer needed.

Change-Id: Ifc4a530723e21f0bde91d6420cde9cb676081922
Reviewed-on: https://go-review.googlesource.com/c/go/+/425881
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: hopehook <hopehook@golangcn.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agoruntime: convert local var stop at TestAfterStress to atomic type
cuiweixie [Fri, 2 Sep 2022 02:53:13 +0000 (10:53 +0800)]
runtime: convert local var stop at TestAfterStress to atomic type

For #53821

Change-Id: I7e86dac34691f7752f68879ff379061f3435cd45
Reviewed-on: https://go-review.googlesource.com/c/go/+/427139
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: xie cui <523516579@qq.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agoruntime: convert local var started,progress at TestStackGrowth to atomic type
cuiweixie [Fri, 2 Sep 2022 02:44:46 +0000 (10:44 +0800)]
runtime: convert local var started,progress at TestStackGrowth to atomic type

For #53821

Change-Id: I9c777ff642ea4b70073335279551cea6a2394569
Reviewed-on: https://go-review.googlesource.com/c/go/+/427138
Run-TryBot: xie cui <523516579@qq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agoruntime: convert local var cunlock at doTestParallelReaders to atomic type
cuiweixie [Fri, 2 Sep 2022 02:37:16 +0000 (10:37 +0800)]
runtime: convert local var cunlock at doTestParallelReaders to atomic type

For #53821

Change-Id: I17440ea30827976a8d3755851a2496f26aea13b1
Reviewed-on: https://go-review.googlesource.com/c/go/+/427137
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: xie cui <523516579@qq.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agoruntime: convert local var ready at TestMemmoveAtomicity to atomic type
cuiweixie [Fri, 2 Sep 2022 02:31:34 +0000 (10:31 +0800)]
runtime: convert local var ready at TestMemmoveAtomicity to atomic type

For #53821

Change-Id: I2487b8d18a4cd3fc6e64fbbb531419812bfe0f08
Reviewed-on: https://go-review.googlesource.com/c/go/+/427136
Run-TryBot: xie cui <523516579@qq.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agoruntime: convert local var stop,ready at TestDebugCallUnsafePoint to atomic type
cuiweixie [Fri, 2 Sep 2022 02:18:51 +0000 (10:18 +0800)]
runtime: convert local var stop,ready at TestDebugCallUnsafePoint to atomic type

For #53821

Change-Id: Id972d4ccadc72de69dea46f8be146c9843d1d095
Reviewed-on: https://go-review.googlesource.com/c/go/+/427135
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: xie cui <523516579@qq.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

21 months agonet/http: don't time out idle server connections after ReadHeaderTimeout
Eliza Weisman [Wed, 31 Aug 2022 19:16:18 +0000 (19:16 +0000)]
net/http: don't time out idle server connections after ReadHeaderTimeout

Consistently wait for idle connections to become readable before
starting the ReadHeaderTimeout timer. Previously, connections with no
idle timeout skipped directly to reading headers, so the
ReadHeaderTimeout also included time spent idle.

Fixes #54784

Change-Id: Iff1a876f00311d03dfa0fbef5b577506c62f7c41
GitHub-Last-Rev: 09332743ad6d5a9eb1137adaade2810c583d38ca
GitHub-Pull-Request: golang/go#54785
Reviewed-on: https://go-review.googlesource.com/c/go/+/426895
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
21 months agonet: precompute rfc6724policyTable in addrselect
Tomasz Jezierski [Sun, 24 Jul 2022 21:02:53 +0000 (23:02 +0200)]
net: precompute rfc6724policyTable in addrselect

As net package has one of the biggest init time in standard library, I have tried to improve performance by doing two things in net/addrselect.go:
1. Precompute slice with RFC rules. Currently the rules are computed and sorted in init() function. We could save the time and allocations by using prepopulated values in sorted manner. The rules haven't changed since 2015. To be extra safe we could move order validation as test case. It should slightly speed up startup of each binary with "net" package and go dns resolver. It also saves 38 allocations, ~50% of allocations in init phase of `net` module.
2. Replace internal net.IP usage with netip.Addr in `sortByRFC6724` function. It results in ~40% performance improvement on samples from tests.

The only risk is the difference between net.IP and netip.Addr behaviour.

Init benchmark:
Init-8               1.89µs ± 2%    0.12µs ± 3%  -93.79%  (p=0.000 n=5+5)

name               old alloc/op   new alloc/op   delta
Init-8               1.05kB ± 0%    0.38kB ± 0%     ~     (zero variance)

name               old allocs/op  new allocs/op  delta
Init-8                 39.0 ± 0%       1.0 ± 0%     ~     (zero variance)

Whole sortByRFC6724 function benchmark:
name               old time/op    new time/op    delta
SortByRFC6724/0-8     463ns ± 3%     303ns ± 4%  -34.72%  (p=0.000 n=5+5)
SortByRFC6724/1-8     481ns ± 8%     306ns ± 1%  -36.46%  (p=0.000 n=5+5)
SortByRFC6724/2-8     470ns ± 4%     307ns ± 4%  -34.77%  (p=0.000 n=5+5)
SortByRFC6724/3-8     567ns ± 3%     367ns ± 3%  -35.28%  (p=0.000 n=5+5)
SortByRFC6724/4-8     918ns ± 3%     560ns ± 2%  -38.93%  (p=0.000 n=5+5)

Updates #54032

Change-Id: Ic18df1ea73805cb184c6ceb73470ca7f0b922032
Reviewed-on: https://go-review.googlesource.com/c/go/+/419356
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
21 months agoruntime: convert g.atomicstatus to internal atomic type
Andy Pan [Wed, 24 Aug 2022 19:27:02 +0000 (03:27 +0800)]
runtime: convert g.atomicstatus to internal atomic type

Note that this changes some unsynchronized operations of g.atomicstatus to synchronized operations.

Updates #53821

Change-Id: If249d62420ea09fbec39b570942f96c63669c333
Reviewed-on: https://go-review.googlesource.com/c/go/+/425363
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agocmd/go: make cfg.BuildContext.ToolTags same order with build.Default.ToolTags
Cuong Manh Le [Wed, 10 Aug 2022 15:52:58 +0000 (22:52 +0700)]
cmd/go: make cfg.BuildContext.ToolTags same order with build.Default.ToolTags

So it's consistent when running "go list -f '{{context.ToolTags}}'" and
printing the content of "build.Default.ToolTags".

Updates #45454

Change-Id: I7a3cbf3cdf9a6ce2b8c89e9bcf5fc5e9086d48e8
Reviewed-on: https://go-review.googlesource.com/c/go/+/422615
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>

21 months agoruntime: fast clock_gettime on FreeBSD, use physical/virtual ARM timer
Yuval Pavel Zholkover [Fri, 12 Aug 2022 18:57:28 +0000 (21:57 +0300)]
runtime: fast clock_gettime on FreeBSD, use physical/virtual ARM timer

as setup by the kernel on GOARCH=arm64.

Update #50947

Change-Id: I2f44be9b36e9ce8d264eccc0aa3df10825c5f4f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/422977
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Dmitri Goutnik <dgoutnik@gmail.com>
Run-TryBot: Yuval Pavel Zholkover <paulzhol@gmail.com>

21 months agointernal/syscall/unix: consolidate kernelVersion implementations
Kir Kolyshkin [Thu, 18 Aug 2022 20:43:47 +0000 (13:43 -0700)]
internal/syscall/unix: consolidate kernelVersion implementations

Currently, there are 3 functions returning Linux kernel version numbers.

Two of them are identical:
 - in net, initially added by commit 0a9dd47dd817904e;
 - in internal/poll, initially added by commit 1c7650aa93bd53;

(both were later fixed by commit 66c02645062561a).

The third one is a more complex, regexp-based implementation in
runtime/pprof, which is only used for a test.

Instead of adding one more, let's consolidate existing ones.

Remove the complex implementation, and move the simple one into
internal/syscall/unix. Use it from all the three places mentioned above.

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

21 months agogo/types, types2: use strings.Builder instead of bytes.Buffer where possible
Robert Griesemer [Fri, 2 Sep 2022 19:10:24 +0000 (12:10 -0700)]
go/types, types2: use strings.Builder instead of bytes.Buffer where possible

Also, consistently use declaration: var buf strings.Builder.
We don't change exported signatures to match go/types (where we
can't change the exported signatures for backward-compatibility).

Change-Id: I75350886aa231889ae2fd5c4008dd4be9ed6e09f
Reviewed-on: https://go-review.googlesource.com/c/go/+/428094
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
21 months agoall: use strings.Builder instead of bytes.Buffer
Sasha Melentyev [Fri, 2 Sep 2022 07:54:43 +0000 (07:54 +0000)]
all: use strings.Builder instead of bytes.Buffer

Change-Id: I6d7213d29ade591b8366d5640833bd5a20474165
GitHub-Last-Rev: 94195832873fe6764d45ffdd6efa1ca49e57a743
GitHub-Pull-Request: golang/go#54834
Reviewed-on: https://go-review.googlesource.com/c/go/+/427814
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
21 months agosyscall: fix skipping some tests on Linux
Kir Kolyshkin [Fri, 15 Jul 2022 02:40:23 +0000 (19:40 -0700)]
syscall: fix skipping some tests on Linux

The kernel knob /proc/sys/kernel/unprivileged_userns_clone is
only available in Debian (and Ubuntu) kernels, so if the tests
are run on e.g. Fedora, skipUnprivilegedUserClone() skips a lot
of tests.

Modify it to treat ENOENT as "it should work".

Change-Id: I959201ede139ede989cc8ab646c9bf51e0539ada
Reviewed-on: https://go-review.googlesource.com/c/go/+/417694
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Kirill Kolyshkin <kolyshkin@gmail.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
21 months agonet: skip TestLookupPTR when LookupAddr fails with "DNS server failure"
Bryan C. Mills [Fri, 2 Sep 2022 15:36:46 +0000 (11:36 -0400)]
net: skip TestLookupPTR when LookupAddr fails with "DNS server failure"

For #38111.

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

21 months agofmt: recycle printers with large buffers
Carlo Alberto Ferraris [Thu, 1 Sep 2022 05:06:55 +0000 (14:06 +0900)]
fmt: recycle printers with large buffers

Previously when a printer had a large buffer we dropped both
the buffer and the printer. There is no need to drop the printer
in this case, as a printer with a nil buffer is valid. So we
just drop the buffer and recycle the printer anyway.
This saves one allocation in case the buffer is over the limit.

Also tighten some of the tests for other unrelated cases.

Change-Id: Iba1b6a71ca4691464b8c68ab0b6ab0d4d5d6168c
Reviewed-on: https://go-review.googlesource.com/c/go/+/427395
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Rob Pike <r@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

21 months agocmd/compile/internal/noder: optimize itabs section of runtime dicts
Matthew Dempsky [Thu, 1 Sep 2022 23:58:15 +0000 (16:58 -0700)]
cmd/compile/internal/noder: optimize itabs section of runtime dicts

Currently, the itabs section for runtime dictionaries includes its own
redundant *runtime._type pointers for typ and iface, which were
sometimes necessary. This simplified the initial implementation, but
is a little wasteful of space when the same type or interface appeared
across multiple (typ, iface) pairs.

This CL instead reuses the pointers from the rtypes section.

Change-Id: I48448515c319c0403c1a8e7706794d443176f0a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/427754
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
21 months agocmd/compile: optimise subtraction with const on riscv64
Joel Sing [Sat, 27 Aug 2022 19:23:28 +0000 (05:23 +1000)]
cmd/compile: optimise subtraction with const on riscv64

Convert subtraction from const to a negated ADDI with negative const
value, where possible. At worst this avoids a register load and uses
the same number of instructions. At best, this allows for further
optimisation to occur, particularly where equality is involved.

For example, this sequence:

   li      t0,-1
   sub     t1,t0,a0
   snez    t1,t1

Becomes:

   addi    t0,a0,1
   snez    t0,t0

Removes more than 2000 instructions from the Go binary on linux/riscv64.

Change-Id: I68f3be897bc645d4a8fa3ab3cef165a00a74df19
Reviewed-on: https://go-review.googlesource.com/c/go/+/426263
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Joel Sing <joel@sing.id.au>

21 months agocmd/compile: negate comparision with FNES/FNED on riscv64
Joel Sing [Sat, 27 Aug 2022 16:32:06 +0000 (02:32 +1000)]
cmd/compile: negate comparision with FNES/FNED on riscv64

The FNES and FNED instructions are pseudo-instructions, which the
assembler expands to FEQS/NEG or FEQD/NEG - if we're comparing the
result via a branch instruction, we can avoid an instruction by
negating both the branch comparision and the floating point
comparision.

This only removes a handful of instructions from the Go binary,
however, it will provide benefit to floating point intensive code.

Change-Id: I4e3124440b7659acc4d9bc9948b755a4900a422f
Reviewed-on: https://go-review.googlesource.com/c/go/+/426261
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Joel Sing <joel@sing.id.au>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months ago.github: add quotations around label
Julie Qiu [Fri, 2 Sep 2022 19:38:45 +0000 (15:38 -0400)]
.github: add quotations around label

Change-Id: I69eaf470ba2c241a99e3693a0a93d9b24c78a2af
Reviewed-on: https://go-review.googlesource.com/c/go/+/427959
Reviewed-by: Tatiana Bradley <tatiana@golang.org>
Reviewed-by: Julie Qiu <julieqiu@google.com>
21 months agoruntime: document implicit fields at the end of _func
Michael Pratt [Fri, 2 Sep 2022 14:10:54 +0000 (10:10 -0400)]
runtime: document implicit fields at the end of _func

Currently these are only implicitly documented by the code that
generates and consumes them. Add explicit documentation.

Change-Id: I25a1294f04dc11785242643bec83370c66ff7a20
Reviewed-on: https://go-review.googlesource.com/c/go/+/427954
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>

21 months ago.github: change label for vulndb and vulndb issues
Julie Qiu [Fri, 2 Sep 2022 18:32:36 +0000 (14:32 -0400)]
.github: change label for vulndb and vulndb issues

Change-Id: Ie384bfb366abc4005e9333b24dbbb70d66b74c0c
Reviewed-on: https://go-review.googlesource.com/c/go/+/427956
Reviewed-by: Tatiana Bradley <tatiana@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Julie Qiu <julieqiu@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Julie Qiu <julieqiu@google.com>

21 months agocmd/internal/obj/riscv: fix comment typo
Wayne Zuo [Fri, 2 Sep 2022 14:26:05 +0000 (22:26 +0800)]
cmd/internal/obj/riscv: fix comment typo

Change-Id: Ica74977898f0af8c9abf42a003d8f02dbdc03d34
Reviewed-on: https://go-review.googlesource.com/c/go/+/427994
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joel Sing <joel@sing.id.au>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agogo/types, types2: consistently write "x | y" rather than "x|y" for unions
Robert Griesemer [Fri, 2 Sep 2022 17:24:53 +0000 (10:24 -0700)]
go/types, types2: consistently write "x | y" rather than "x|y" for unions

Use the same spacing convention ("x | y") for union terms everythere,
matching the gofmt precedent.

Fixes #53279.

Change-Id: Ic3ccd7433b5f62402ba41cf05a75f9a1d99a8086
Reviewed-on: https://go-review.googlesource.com/c/go/+/410955
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
21 months agoruntime: simplify stkframe.argMapInternal
Austin Clements [Fri, 26 Aug 2022 18:38:19 +0000 (14:38 -0400)]
runtime: simplify stkframe.argMapInternal

Use an early return to reduce indentation and clarify flow.

For #54466.

Change-Id: I12ce810bea0f22b8707a175dc5ba66241c0a9a21
Reviewed-on: https://go-review.googlesource.com/c/go/+/425936
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Austin Clements <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

21 months agoruntime: consolidate stkframe and its methods into stkframe.go
Austin Clements [Wed, 17 Aug 2022 13:06:14 +0000 (09:06 -0400)]
runtime: consolidate stkframe and its methods into stkframe.go

The stkframe struct and its methods are strewn across different source
files. Since they actually have a pretty coherent theme at this point,
migrate it all into a new file, stkframe.go. There are no code changes
in this CL.

For #54466, albeit rather indirectly.

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

21 months agoruntime: make getStackMap a method of stkframe
Austin Clements [Wed, 17 Aug 2022 13:02:41 +0000 (09:02 -0400)]
runtime: make getStackMap a method of stkframe

This places getStackMap alongside argBytes and argMapInternal as
another method of stkframe.

For #54466, albeit rather indirectly.

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

21 months agoruntime: replace stkframe.arglen/argmap with methods
Austin Clements [Sun, 14 Aug 2022 01:39:56 +0000 (21:39 -0400)]
runtime: replace stkframe.arglen/argmap with methods

Currently, stkframe.arglen and stkframe.argmap are populated by
gentraceback under a particular set of circumstances. But because they
can be constructed from other fields in stkframe, they don't need to
be computed eagerly at all. They're also rather misleading, as they're
only part of computing the actual argument map and most callers should
be using getStackMap, which does the rest of the work.

This CL drops these fields from stkframe. It shifts the functions that
used to compute them, getArgInfoFast and getArgInfo, into
corresponding methods stkframe.argBytes and stkframe.argMapInternal.
argBytes is expected to be used by callers that need to know only the
argument frame size, while argMapInternal is used only by argBytes and
getStackMap.

We also move some of the logic from getStackMap into argMapInternal
because the previous split of responsibilities didn't make much sense.
This lets us return just a bitvector from argMapInternal, rather than
both a bitvector, which carries a size, and an "actually use this
size".

The getArgInfoFast function was inlined before (and inl_test checked
this). We drop that requirement from stkframe.argBytes because the
uses of this have shifted and now it's only called from heap dumping
(which never happens) and conservative stack frame scanning (which
very, very rarely happens).

There will be a few follow-up clean-up CLs.

For #54466. This is a nice clean-up on its own, but it also serves to
remove pointers from the traceback state that would eventually become
troublesome write barriers once we stack-rip gentraceback.

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

21 months agoruntime: switch gp when jumping stacks during traceback
Austin Clements [Tue, 12 Jul 2022 20:35:26 +0000 (16:35 -0400)]
runtime: switch gp when jumping stacks during traceback

Currently, when traceback jumps from the system stack to a user stack
(e.g., during profiling tracebacks), it leaves gp pointing at the g0.
This is currently harmless since it's only used during profiling, so
the code paths in gentraceback that care about gp aren't used, but
it's really confusing and would certainly break if _TraceJumpStack
were ever used in a context other than profiling.

Fix this by updating gp to point to the user g when we switch stacks.

For #54466.

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

21 months agoruntime: document stkframe
Austin Clements [Wed, 13 Jul 2022 17:36:23 +0000 (13:36 -0400)]
runtime: document stkframe

The meaning of some of the fields in stkframe is actually quite
subtle.

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

21 months agoruntime: drop redundant argument to getArgInfo
Austin Clements [Tue, 16 Aug 2022 17:04:16 +0000 (13:04 -0400)]
runtime: drop redundant argument to getArgInfo

The f funcInfo argument is always the same as frame.fn, so we don't
need to pass it. I suspect that was there to make the signatures of
getArgInfoFast and getArgInfo more similar, but it's not necessary.

For #54466.

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

21 months agoruntime: drop function context from traceback
Austin Clements [Mon, 15 Aug 2022 14:41:03 +0000 (10:41 -0400)]
runtime: drop function context from traceback

Currently, gentraceback tracks the closure context of the outermost
frame. This used to be important for "unstarted" calls to reflect
function stubs, where "unstarted" calls are either deferred functions
or the entry-point of a goroutine that hasn't run. Because reflect
function stubs have a dynamic argument map, we have to reach into
their closure context to fetch to map, and how to do this differs
depending on whether the function has started. This was discovered in
issue #25897.

However, as part of the register ABI, "go" and "defer" were made much
simpler, and any "go" or "defer" of a function that takes arguments or
returns results gets wrapped in a closure that provides those
arguments (and/or discards the results). Hence, we'll see that closure
instead of a direct call to a reflect stub, and can get its static
argument map without any trouble.

The one case where we may still see an unstarted reflect stub is if
the function takes no arguments and has no results, in which case the
compiler can optimize away the wrapper closure. But in this case we
know the argument map is empty: the compiler can apply this
optimization precisely because the target function has no argument
frame.

As a result, we no longer need to track the closure context during
traceback, so this CL drops all of that mechanism.

We still have to be careful about the unstarted case because we can't
reach into the function's locals frame to pull out its context
(because it has no locals frame). We double-check that in this case
we're at the function entry.

I would prefer to do this with some in-code PCDATA annotations of
where to find the dynamic argument map, but that's a lot of mechanism
to introduce for just this. It might make sense to consider this along
with #53609.

Finally, we beef up the test for this so it more reliably forces the
runtime down this path. It's fundamentally probabilistic, but this
tweak makes it better. Scheduler testing hooks (#54475) would make it
possible to write a reliable test for this.

For #54466, but it's a nice clean-up all on its own.

Change-Id: I16e4f2364ba2ea4b1fec1e27f971b06756e7b09f
Reviewed-on: https://go-review.googlesource.com/c/go/+/424254
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Austin Clements <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
21 months agonet: rfc number typo
Mateusz Poliwczak [Fri, 2 Sep 2022 08:58:16 +0000 (08:58 +0000)]
net: rfc number typo

Change-Id: I9cde2a82a395546d7620b5138cf922b2ac1c94b5
GitHub-Last-Rev: 25b8e972b044848da1a1f94cbd943702952102c0
GitHub-Pull-Request: golang/go#54835
Reviewed-on: https://go-review.googlesource.com/c/go/+/427834
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agocmd/compile: rewrite >>c<<c to &^(1<<c-1)
Keith Randall [Wed, 17 Aug 2022 20:09:12 +0000 (13:09 -0700)]
cmd/compile: rewrite >>c<<c to &^(1<<c-1)

Fixes #54496

Change-Id: I3c2ed8cd55836d5b07c8cdec00d3b584885aca79
Reviewed-on: https://go-review.googlesource.com/c/go/+/424856
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Martin Möhrmann <martin@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Martin Möhrmann <martin@golang.org>
21 months agocmd/compile/internal/noder: allow OCONVNOP for identical iface conversions
Matthew Dempsky [Thu, 1 Sep 2022 23:06:11 +0000 (16:06 -0700)]
cmd/compile/internal/noder: allow OCONVNOP for identical iface conversions

In go.dev/cl/421821, I included a hack to force OCONVNOP back to
OCONVIFACE for conversions involving shape types and non-empty
interfaces. The comment correctly noted that this was only needed for
conversions between non-identical types, but the code was conservative
and applied to even conversions between identical types.

This CL adds an extra bool to record whether the conversion is between
identical types, so we can keep OCONVNOP instead of forcing back to
OCONVIFACE. This has a small improvement to generated code, because we
no longer need a convI2I call (as demonstrated by codegen/ifaces.go).

But more usefully, this is relevant to pruning unnecessary itab slots
in runtime dictionaries (next CL).

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

21 months agocmd/compile/internal/noder: refactor exprConvert code
Matthew Dempsky [Thu, 1 Sep 2022 23:02:49 +0000 (16:02 -0700)]
cmd/compile/internal/noder: refactor exprConvert code

This CL deduplicates the explicit and implicit exprConvert code paths
to have a single common function, so they're easier to keep in sync.

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

21 months agocmd/compile: remove go:notinheap pragma
Cuong Manh Le [Wed, 10 Aug 2022 13:01:48 +0000 (20:01 +0700)]
cmd/compile: remove go:notinheap pragma

Updates #46731

Change-Id: I247fa9c7ca97feb9053665da7ff56e7f5b571f74
Reviewed-on: https://go-review.googlesource.com/c/go/+/422815
Reviewed-by: Keith Randall <khr@golang.org>
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: Joedian Reid <joedian@golang.org>
21 months agocmd/compile: make runtime/internal/sys.NotInHeap intrinsic
Cuong Manh Le [Wed, 10 Aug 2022 11:17:42 +0000 (18:17 +0700)]
cmd/compile: make runtime/internal/sys.NotInHeap intrinsic

So next CL can get rid of go:notinheap pragma.

Updates #46731

Change-Id: Ib2e2f2d381767e11cec10f76261b516188ddaa6a
Reviewed-on: https://go-review.googlesource.com/c/go/+/422814
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

21 months agocmd/compile/internal/abt: use strings.Builder
Cuong Manh Le [Wed, 31 Aug 2022 17:16:32 +0000 (00:16 +0700)]
cmd/compile/internal/abt: use strings.Builder

Since go1.17 is now used for bootstrapping.

Change-Id: I5692ff4b38b7d9a279b20662ce5348ff34a2dde6
Reviewed-on: https://go-review.googlesource.com/c/go/+/427134
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
21 months agodebug/macho: use saferio to allocate load command slice
Tobias Klauser [Thu, 1 Sep 2022 08:48:58 +0000 (10:48 +0200)]
debug/macho: use saferio to allocate load command slice

Avoid allocating large amounts of memory for corrupt input.

No test case because the problem can only happen for invalid data.
Let the fuzzer find cases like this.

Fixes #54780

Change-Id: Icdacb16bef7d29ef431da52e6d1da4e883a3e050
Reviewed-on: https://go-review.googlesource.com/c/go/+/427434
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>

21 months agocmd/compile: new inline heuristic for struct compares
Derek Parker [Tue, 30 Aug 2022 21:48:17 +0000 (21:48 +0000)]
cmd/compile: new inline heuristic for struct compares

This CL changes the heuristic used to determine whether we can inline a
struct equality check or if we must generate a function and call that
function for equality.

The old method was to count struct fields, but this can lead to poor
in lining decisions. We should really be determining the cost of the
equality check and use that to determine if we should inline or generate
a function.

The new benchmark provided in this CL returns the following when compared
against tip:

```
name         old time/op  new time/op  delta
EqStruct-32  2.46ns ± 4%  0.25ns ±10%  -89.72%  (p=0.000 n=39+39)
```

Fixes #38494

Change-Id: Ie06b80a2b2a03a3fd0978bcaf7715f9afb66e0ab
GitHub-Last-Rev: e9a18d93893cc6493794683bf75b9848478a4de6
GitHub-Pull-Request: golang/go#53326
Reviewed-on: https://go-review.googlesource.com/c/go/+/411674
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agoruntime: support MADV_DONTNEED on the BSDs and Solaris/Illumos
Tobias Klauser [Mon, 29 Aug 2022 11:29:43 +0000 (13:29 +0200)]
runtime: support MADV_DONTNEED on the BSDs and Solaris/Illumos

Like on Linux, use GODEBUG=madvdontneed=1 to enable madvise with
MADV_DONTNEED instead of MADV_FREE.

Based on previous work by Marcelo Araujo in CL 181498.

Fixes #32519

Change-Id: Ib49faf05c42a65591b90e75f663146f213030529
Reviewed-on: https://go-review.googlesource.com/c/go/+/266937
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agocmd/compile: optimize RotateLeft8/16 on arm64
ruinan [Wed, 13 Jul 2022 09:00:57 +0000 (09:00 +0000)]
cmd/compile: optimize RotateLeft8/16 on arm64

This CL optimizes RotateLeft8/16 on arm64.

For 16 bits, we form a 32 bits register by duplicating two 16 bits
registers, then use RORW instruction to do the rotate shift.

For 8 bits, we just use LSR and LSL instead of RORW because the code is
simpler.

Benchmark          Old          ThisCL       delta
RotateLeft8-46     2.16 ns/op   1.73 ns/op   -19.70%
RotateLeft16-46    2.16 ns/op   1.54 ns/op   -28.53%

Change-Id: I09cde4383d12e31876a57f8cdfd3bb4f324fadb0
Reviewed-on: https://go-review.googlesource.com/c/go/+/420976
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Keith Randall <khr@golang.org>

21 months agogo/types,types2: move notinheap tests to fixedbugs directory
Cuong Manh Le [Fri, 2 Sep 2022 06:32:40 +0000 (13:32 +0700)]
go/types,types2: move notinheap tests to fixedbugs directory

So they can be added to ignored list, since the tests now require
cgo.Incomplete, which is not recognized by go/types and types2.

Updates #46731

Change-Id: I9f24e3c8605424d1f5f42ae4409437198f4c1326
Reviewed-on: https://go-review.googlesource.com/c/go/+/427142
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agocmd/compile/internal/base: use runtime.KeepAlive in MapFile
Tobias Klauser [Wed, 31 Aug 2022 17:05:55 +0000 (19:05 +0200)]
cmd/compile/internal/base: use runtime.KeepAlive in MapFile

Go 1.17 will be used instead of Go 1.4 as minimum required version for
bootstrap, so runtime.KeepAlive introduced in Go 1.7 can be used in
cmd/compile.

For #44505

Change-Id: I96bd6619c4476e36ee1d93ca049da622a3a78f97
Reviewed-on: https://go-review.googlesource.com/c/go/+/427114
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

21 months agocmd/compile: optimize shift ops on arm64 when the shift value is v&63
ruinan [Mon, 8 Aug 2022 04:17:19 +0000 (04:17 +0000)]
cmd/compile: optimize shift ops on arm64 when the shift value is v&63

For the following code case:

  var x uint64
  x >> (shift & 63)

We can directly genereta `x >> shift` on arm64, since the hardware will
only use the bottom 6 bits of the shift amount.

Benchmark               old time/op  new time/op    delta
ShiftArithmeticRight-8  0.40ns       0.31ns        -21.7%

Change-Id: Id58c8a5b2f6dd5c30c3876f4a36e11b4d81e2dc9
Reviewed-on: https://go-review.googlesource.com/c/go/+/425294
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agogo/types: use function name position for init errors
Robert Griesemer [Fri, 2 Sep 2022 03:47:41 +0000 (20:47 -0700)]
go/types: use function name position for init errors

This seems more sensible than the func keyword. With this change,
go/types uses the same error position as types2 and we can narrow
the error tolerance a bit.

(The types2 change doesn't change its position, but it makes the
code clearer and symmetric to go/types.)

Change-Id: Iedea7c80caa7239a4343c8748cb779ec545e84d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/427775
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: 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>

21 months agocmd/link: only add dummy XCOFF reference if the symbol exists
Cherry Mui [Thu, 1 Sep 2022 23:31:04 +0000 (19:31 -0400)]
cmd/link: only add dummy XCOFF reference if the symbol exists

On AIX when external linking, for some symbols we need to add
dummy references to prevent the external linker from discarding
them. Currently we add the reference unconditionally. But if the
symbol doesn't exist, the linking fails in a later stage for
generating external relocation of a nonexistent symbol. The
symbols are special symbols that almost always exist, except that
go:buildid may not exist if the linker is invoked without the
-buildid flag. The go command invokes the linker with the flag, so
this can only happen with manual linker invocation. Specifically,
test/run.go does this in some cases.

Fix this by checking the symbol existence before adding the
reference. Re-enable tests on AIX.

Perhaps the linker should always emit a dummy buildid even if the
flag is not set...

Fixes #54814.

Change-Id: I43d81587151595309e189e38960cbda9a1c5ca32
Reviewed-on: https://go-review.googlesource.com/c/go/+/427620
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
21 months agoencoding/asn1: fix doc for BitString.At's return value
RenKanai [Wed, 8 Jun 2022 16:42:26 +0000 (01:42 +0900)]
encoding/asn1: fix doc for BitString.At's return value

Fixes #53287

Change-Id: If983ae34850d9b1b29764156a38628fa53897573
Reviewed-on: https://go-review.googlesource.com/c/go/+/411134
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: hopehook <hopehook@golangcn.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Reviewed-by: Subham <sarkar.subhams2@gmail.com>
21 months agocmd/compile: restrict //go:notinheap to runtime/internal/sys
Cuong Manh Le [Sun, 7 Aug 2022 18:10:18 +0000 (01:10 +0700)]
cmd/compile: restrict //go:notinheap to runtime/internal/sys

So it won't be visible outside of runtime package. There are changes to
make tests happy:

 - For test/directive*.go files, using "go:noinline" for testing misplaced
 directives instead.
 - Restrict test/fixedbugs/bug515.go for gccgo only.
 - For test/notinheap{2,3}.go, using runtime/cgo.Incomplete for marking
 the type as not-in-heap. Though it's somewhat clumsy, it's the easiest
 way to keep the test errors for not-in-heap types until we can cleanup
 further.
 - test/typeparam/mdempsky/11.go is about defined type in user code marked
 as go:notinheap, which can't happen after this CL, though.

Fixes #46731

Change-Id: I869f5b2230c8a2a363feeec042e7723bbc416e8e
Reviewed-on: https://go-review.googlesource.com/c/go/+/421882
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
21 months agohash: convert haveCastagnoli to atomic type
cuiweixie [Sat, 27 Aug 2022 03:11:08 +0000 (11:11 +0800)]
hash: convert haveCastagnoli to atomic type

Change-Id: I313fff5684d89ee737572d11b1b697c5575866a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/426083
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
21 months agomath/rand: document that Source returned by NewSource implements Source64
Jonathan FOng [Fri, 26 Aug 2022 19:10:32 +0000 (12:10 -0700)]
math/rand: document that Source returned by NewSource implements Source64

Fixes #44488

Change-Id: I570950799788678b9dc6e9ddad894973b4611e09
Reviewed-on: https://go-review.googlesource.com/c/go/+/425974
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: David Chase <drchase@google.com>
21 months agointernal/types: add a test for empty string import path
Robert Griesemer [Fri, 2 Sep 2022 01:47:57 +0000 (18:47 -0700)]
internal/types: add a test for empty string import path

Follow-up on comment in CL 427154.

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

21 months agogo/types, types2: move shared tests into internal/types/testdata
Robert Griesemer [Fri, 2 Sep 2022 01:38:08 +0000 (18:38 -0700)]
go/types, types2: move shared tests into internal/types/testdata

This CL moves the directories check, examples, fixedbugs, and spec
from inside go/types/testdata to internal/types/testdata. Except
for the directory adjustments to check_test.go files, this is a
pure file move.

With this CL, both type checkers now share identical tests in an
independent location.

Fixes #54511.

Change-Id: Ib335692d927e93867a158b338f105c2b87e74dbe
Reviewed-on: https://go-review.googlesource.com/c/go/+/427674
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

21 months agogo/types: test shifts that are disabled in shared test file
Robert Griesemer [Thu, 1 Sep 2022 00:40:21 +0000 (17:40 -0700)]
go/types: test shifts that are disabled in shared test file

CL 425735 consolidated the testdata/check/shifts.go files between
go/types and types2. Because some shifts don't work correctly with
types2, the corresponding tests were disabled in the shared file.
Make sure we keep testing those shifts for go/types by adding a
local test file.

For #52080.
For #54511.

Change-Id: I53507e535bf83b204eaf18fc6c2efefcebf5ebf7
Reviewed-on: https://go-review.googlesource.com/c/go/+/426661
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>
21 months agogo/types, types2: establish type-checker specific local tests
Robert Griesemer [Thu, 1 Sep 2022 00:29:28 +0000 (17:29 -0700)]
go/types, types2: establish type-checker specific local tests

Establish testdata/local directory for tests that are not (yet)
shared between the go/types and types2. Move issue47996.go into
that directory.

For #54511.

Change-Id: I274b119990a93cc3657bdddc5246948699226c21
Reviewed-on: https://go-review.googlesource.com/c/go/+/426660
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
21 months agocmd/compile/internal/types2: use go/types/testdata/fixedbugs tests
Robert Griesemer [Thu, 1 Sep 2022 00:06:29 +0000 (17:06 -0700)]
cmd/compile/internal/types2: use go/types/testdata/fixedbugs tests

Since the fixedbugs tests are now identical between the two type checkers,
remove the local copy of the fixedbugs tests and (for now) use the tests
in go/types/testdata/fixedbugs instead. Eventually we may decide to move
all tests out of the type checker directories and place them in a
shared space (e.g. internal/types/testdata).

For #54511.

Change-Id: I451c20c784710c36fa50b1d24ac97af554c572af
Reviewed-on: https://go-review.googlesource.com/c/go/+/426658
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
21 months agogo/types, types2: consolidate testdata/fixedbugs test files
Robert Griesemer [Wed, 31 Aug 2022 23:56:17 +0000 (16:56 -0700)]
go/types, types2: consolidate testdata/fixedbugs test files

Use the go/types version of testdata/fixedbugs tests where diffs
are only in the error positions (the types2 test harness allows
for some position tolerance). Consolidate files where there are
other minor differences.

Add files to respective directories if they only existed for
one of the type checkers.

Move types2-only test issue47996.go out of testdata/fixedbugs
into testdata. Making it work for both type checkers requires
some more work.

With this CL, the testdata/fixedbugs files are identical between
the two type checkers.

For #54511.

Change-Id: I0d67f0db75ad1743c62da9181a6d0032c8bdb728
Reviewed-on: https://go-review.googlesource.com/c/go/+/427236
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
21 months agocmd/compile/internal/syntax: more strict parsing of type instances
Robert Griesemer [Wed, 31 Aug 2022 22:54:28 +0000 (15:54 -0700)]
cmd/compile/internal/syntax: more strict parsing of type instances

Report a syntax error if the first element of a type instance is
not actually a type (but some other expression), rather then relying
on the type checker error in this case. This matches the behavior of
go/parser. Adjust the corresponding types2 test case.

For #54511.

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

21 months agogo/types, types2: consolidate testdata/fixedbugs/issue46404.go
Robert Griesemer [Wed, 31 Aug 2022 22:05:23 +0000 (15:05 -0700)]
go/types, types2: consolidate testdata/fixedbugs/issue46404.go

Rename .../issue46404.go1 to .../issue46404.go so that it is
not skipped anymore when running tests, and copy for types2.

Disable the code for now due to a difference in error
reporting due to the slightly different handling of index
expressions. This allows us to make progress with test
consolidation.

For #54511.

Change-Id: Ib5c9ffa49b1b24ec680ddb5001bc3dcb1df7eb1f
Reviewed-on: https://go-review.googlesource.com/c/go/+/426656
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
21 months agogo/parser: match syntax parser error for unnamed type parameters
Robert Griesemer [Wed, 31 Aug 2022 21:23:07 +0000 (14:23 -0700)]
go/parser: match syntax parser error for unnamed type parameters

For #54511.

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

21 months agogo/parser: more tolerant parsing of import declarations
Robert Griesemer [Wed, 31 Aug 2022 20:43:28 +0000 (13:43 -0700)]
go/parser: more tolerant parsing of import declarations

This is a port of CL 427156 from the syntax package's parser
to go/parser.

While at it, remove an unused token.Pos parameter from
parseSpecFunction and dependent declarations.

Also, consolidate the respective test file.

For #54511.

Change-Id: Id6a28eb3d23a46fa5fa1d85d2c4e634b7015513c
Reviewed-on: https://go-review.googlesource.com/c/go/+/427157
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
21 months agocmd/compile/internal/syntax: more tolerant parsing of import declarations
Robert Griesemer [Wed, 31 Aug 2022 19:14:58 +0000 (12:14 -0700)]
cmd/compile/internal/syntax: more tolerant parsing of import declarations

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

21 months agogo/parser: parse import specs the same way as the syntax parser
Robert Griesemer [Wed, 31 Aug 2022 18:26:43 +0000 (11:26 -0700)]
go/parser: parse import specs the same way as the syntax parser

This results in better error recovery and allows us to use the
same tests for go/types and types2.

For #54511.

Change-Id: Ic11a9dafb8c62e0cb952b3924d55a28b438241c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/427154
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
21 months agogo/types, types2: consolidate a test file with different syntax errors
Robert Griesemer [Tue, 30 Aug 2022 00:27:22 +0000 (17:27 -0700)]
go/types, types2: consolidate a test file with different syntax errors

For #54511.

Change-Id: I317c5f9beed7f1de4979ec12c6ec8d5de71bac1c
Reviewed-on: https://go-review.googlesource.com/c/go/+/426554
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>
Auto-Submit: Robert Griesemer <gri@google.com>

21 months agocmd/compile/internal/types2: match go/types error for invalid instantiations
Robert Griesemer [Mon, 29 Aug 2022 23:40:31 +0000 (16:40 -0700)]
cmd/compile/internal/types2: match go/types error for invalid instantiations

Also: add a missing test.

For #54511.

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

21 months agogo/types: use singular in version error messages
Robert Griesemer [Mon, 29 Aug 2022 23:10:03 +0000 (16:10 -0700)]
go/types: use singular in version error messages

This matches the majority use case as well as types2.

For #54511.

Change-Id: If800afc35db8d32cca8329ed9d6a80b4a15c4878
Reviewed-on: https://go-review.googlesource.com/c/go/+/426477
Reviewed-by: 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>
Auto-Submit: Robert Griesemer <gri@google.com>

21 months agotypes2: use strings.Builder in infer.go
hopehook [Thu, 1 Sep 2022 13:44:11 +0000 (21:44 +0800)]
types2: use strings.Builder in infer.go

Permissible now because go1.17 is used for bootstrapping.

Change-Id: Ic97b0706190c3eb907da69003bc94448c90e5af7
Reviewed-on: https://go-review.googlesource.com/c/go/+/427556
Run-TryBot: Robert Griesemer <gri@google.com>
Run-TryBot: hopehook <hopehook@golangcn.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
21 months agotypes2: use strings.Builder in errors.go
hopehook [Thu, 1 Sep 2022 13:40:08 +0000 (21:40 +0800)]
types2: use strings.Builder in errors.go

Permissible now because go1.17 is used for bootstrapping.

Change-Id: Ia6f314f9314eda1cc42002dcbdfa551196df76f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/427554
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: hopehook <hopehook@golangcn.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
21 months agogo/parser: leave checking of LHS in short var decls to type checker
Robert Griesemer [Mon, 29 Aug 2022 22:45:35 +0000 (15:45 -0700)]
go/parser: leave checking of LHS in short var decls to type checker

Instead of checking at parse-time that the LHS of a short variable
declaration contains only identifiers, leave the check to the the
type checker which tests this already.

This removes a duplicate error and matches the behavior of the
syntax package.

For #54511.

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

21 months agogo/parser: check that go/defer expressions are not parenthesized
Robert Griesemer [Fri, 26 Aug 2022 04:10:36 +0000 (21:10 -0700)]
go/parser: check that go/defer expressions are not parenthesized

Logic matches the code in the syntax package.
This error was missing from go/parser and go/types.
Added some tests.

For #54511.

Change-Id: I418de4bd4c7169457b424366caae70227a92a761
Reviewed-on: https://go-review.googlesource.com/c/go/+/425795
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
21 months agocmd/compile: avoid "not used" errors due to bad go/defer statements
Robert Griesemer [Fri, 26 Aug 2022 03:32:27 +0000 (20:32 -0700)]
cmd/compile: avoid "not used" errors due to bad go/defer statements

The syntax for go and defer specifies an arbitrary expression, not
a call; the call requirement is spelled out in prose. Don't to the
call check in the parser; instead move it to the type checker. This
is simpler and also allows the type checker to check expressions that
are not calls, and avoid "not used" errors due to such expressions.

We would like to make the same change in go/parser and go/types
but the change requires Go/DeferStmt nodes to hold an ast.Expr
rather than an *ast.CallExpr. We cannot change that for backward-
compatibility reasons. Since we don't test this behavior for the
type checkers alone (only for the compiler), we get away with it
for now.

Follow-up on CL 425675 which introduced the extra errors in the
first place.

Change-Id: I90890b3079d249bdeeb76d5673246ba44bec1a7b
Reviewed-on: https://go-review.googlesource.com/c/go/+/425794
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
21 months agocmd/compile/internal/types2: use go/types/testdata/check tests
Robert Griesemer [Fri, 26 Aug 2022 00:43:18 +0000 (17:43 -0700)]
cmd/compile/internal/types2: use go/types/testdata/check tests

Since the check tests are now identical between the two type checkers,
remove the local copy of the check tests and (for now) use the tests
in go/types/testdata/check instead. Eventually we may decide to move
all tests out of the type checker directories and place them in a
shared space (e.g. internal/types/testdata).

For #54511.

Change-Id: Id3a97593f6c705c5eda4566089ddc7aeb7b47337
Reviewed-on: https://go-review.googlesource.com/c/go/+/425736
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
21 months agogo/types, types2: consolidate testdata/check test files
Robert Griesemer [Fri, 26 Aug 2022 00:20:07 +0000 (17:20 -0700)]
go/types, types2: consolidate testdata/check test files

Use the go/types version of testdata/check tests where the diffs
are only in the error positions (the types2 test harness allows
for some position tolerance). Consolidate files where there are
other minor differences.

Comment out a couple of tests that are different between the two
type checkers.

With this CL, the testdata/check files are identical between the
two type checkers.

For #54511.

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

21 months agogo/parser: adjustments to error messages
Robert Griesemer [Thu, 25 Aug 2022 23:41:35 +0000 (16:41 -0700)]
go/parser: adjustments to error messages

- Use "expected X" rather then "expecting X".
- Report a better error when a type argument list is expected.
- Adjust various tests.

For #54511.

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

21 months agocmd/compile/internal/syntax: use BadExpr instead of fake CallExpr in bad go/defer
Robert Griesemer [Thu, 25 Aug 2022 23:14:43 +0000 (16:14 -0700)]
cmd/compile/internal/syntax: use BadExpr instead of fake CallExpr in bad go/defer

If the go/defer syntax is bad, using a fake CallExpr may produce
a follow-on error in the type checker. Instead store a BadExpr
in the syntax tree (since an error has already been reported).

Adjust various tests.

For #54511.

Change-Id: Ib2d25f8eab7d5745275188d83d11620cad6ef47c
Reviewed-on: https://go-review.googlesource.com/c/go/+/425675
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
21 months agogo/parser: remove validation of expression syntax, leave to type checker
Robert Griesemer [Thu, 25 Aug 2022 22:28:52 +0000 (15:28 -0700)]
go/parser: remove validation of expression syntax, leave to type checker

Remove the code that verifies that an expression is a type or non-type
expression. For one, it cannot be done perfectly accurate
(e.g., consider *p which could be an indirection or a pointer type),
it also unnecessarily slows down parsing. It's simpler to leave the
verification to the type checker which has all the information needed.

Remove short compiler tests that tested the expression/type property.
Adjust a couple of go/types tests which now trigger because the parser
doesn't complain anymore.

Change file for benchmark from "parser.go" to "../printer/nodes.go"
to avoid a moving target when benchmarking.

The parser may be marginally faster when tested on nodes.go:

name          old time/op    new time/op    delta
ParseOnly-12    1.35ms ± 0%    1.31ms ± 0%   ~     (p=0.100 n=3+3)

name          old speed      new speed      delta
ParseOnly-12  39.9MB/s ± 0%  41.0MB/s ± 0%   ~     (p=0.100 n=3+3)

For #54511.

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

21 months agosyscall: Faccessat: use faccessat2 on linux
Kir Kolyshkin [Thu, 30 Jun 2022 22:19:59 +0000 (15:19 -0700)]
syscall: Faccessat: use faccessat2 on linux

Linux kernel 5.8 added the faccessat2 syscall taking a flags argument.
Attempt to use it in Faccessat and fall back to the existing
implementation mimicking glibc faccessat.

Do not export the new syscall value so we keep syscall API intact.

Part of this commit is generated by:

GOOS=linux ./mkall.sh -syscalls zsyscall_linux_*.go

This is similar to [1] amended by [2]. Required for [3].

[1] https://go-review.googlesource.com/c/sys/+/246537
[2] https://go-review.googlesource.com/c/sys/+/246817
[3] https://go-review.googlesource.com/c/go/+/414824

Co-authored-by: Tobias Klauser <tklauser@distanz.ch>
Change-Id: Ib7fe5ba853c15d92e869df9a16b56b79b96e43a6
Reviewed-on: https://go-review.googlesource.com/c/go/+/416115
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
21 months agosyscall: make mkall.sh accept file list
Kir Kolyshkin [Sat, 13 Aug 2022 19:53:37 +0000 (12:53 -0700)]
syscall: make mkall.sh accept file list

Amend the "mkall.sh -syscalls" implementation to
 - prepend ./ before mksyscalls.pl;
 - accept the optional file list argument.

This is a preparation for CL 416115.

Change-Id: Ib4dc2b4aa0d2dd22a256414864e92f2d2fd957a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/423676
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
21 months agocmd/compile,runtime: redo growslice calling convention
Keith Randall [Thu, 14 Jul 2022 03:22:53 +0000 (20:22 -0700)]
cmd/compile,runtime: redo growslice calling convention

Instead of passing the original length and the new length, pass
the new length and the length increment. Also use the new length
in all the post-growslice calculations so that the original length
is dead and does not need to be spilled/restored around the growslice.

old: growslice(typ, oldPtr, oldLen, oldCap, newLen) (newPtr, newLen, newCap)
new: growslice(oldPtr, newLen, oldCap, inc, typ) (newPtr, newLen, newCap)

where inc = # of elements added = newLen-oldLen

Also move the element type to the end of the call. This makes register
allocation more efficient, as oldPtr and newPtr can often be in the
same register (e.g. AX on amd64) and thus the phi takes no instructions.

Makes the go binary 0.3% smaller.

Change-Id: I7295a60227dbbeecec2bf039eeef2950a72df760
Reviewed-on: https://go-review.googlesource.com/c/go/+/418554
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
21 months agocmd/compile: use (*strings.Reader).Reset
hopehook [Thu, 1 Sep 2022 14:59:05 +0000 (22:59 +0800)]
cmd/compile: use (*strings.Reader).Reset

Since when go1.17 is now used for bootstraping.

Change-Id: If28338fc82e6c61f057d7eb3a4c2ed77846167df
Reviewed-on: https://go-review.googlesource.com/c/go/+/427558
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: hopehook <hopehook@golangcn.org>

21 months agocmd/internal/pkgpath: use strings.Builder
hopehook [Thu, 1 Sep 2022 13:53:22 +0000 (21:53 +0800)]
cmd/internal/pkgpath: use strings.Builder

Since when go1.17 is now used for bootstraping.

Change-Id: I5f763dec1cb152f94ab1c677d3fa26da17abf097
Reviewed-on: https://go-review.googlesource.com/c/go/+/427557
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Run-TryBot: hopehook <hopehook@golangcn.org>
Reviewed-by: Keith Randall <khr@google.com>
21 months agocmd/internal/objabi: use strings.Builder
hopehook [Thu, 1 Sep 2022 13:42:25 +0000 (21:42 +0800)]
cmd/internal/objabi: use strings.Builder

Since when go1.17 is now used for bootstraping.

Change-Id: I5ee65aff72500a04e243238cffeae92ea659627b
Reviewed-on: https://go-review.googlesource.com/c/go/+/427555
Auto-Submit: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: hopehook <hopehook@golangcn.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
21 months agoRevert "runtime: convert ncgocall to atomic type"
Michael Pratt [Thu, 1 Sep 2022 18:07:33 +0000 (18:07 +0000)]
Revert "runtime: convert ncgocall to atomic type"

This reverts CL 426075.

Reason for revert: Import missing from cgocall.go.

Change-Id: Iac17e914045b83da30484dbe2a624cde526fb175
Reviewed-on: https://go-review.googlesource.com/c/go/+/427614
Reviewed-by: Heschi Kreinick <heschi@google.com>
21 months agoruntime: convert ncgocall to atomic type
cuiweixie [Sat, 27 Aug 2022 01:45:15 +0000 (09:45 +0800)]
runtime: convert ncgocall to atomic type

For #53821

Change-Id: Ib0d62ee36487b3ed68e063976968f3cac6499e4b
Reviewed-on: https://go-review.googlesource.com/c/go/+/426075
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: xie cui <523516579@qq.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

21 months agocmd/compile: reorder rotate lowering rules in AMD64.rules
Wayne Zuo [Wed, 31 Aug 2022 01:06:41 +0000 (09:06 +0800)]
cmd/compile: reorder rotate lowering rules in AMD64.rules

These rules should belong to lowering rules not optimizations.

Change-Id: I964d2c4b1d9bef0ede572978aff01cb11bf050ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/426197
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>

21 months agocrypto/internal/boring/fipstls: convert required to atomic type
cuiweixie [Sat, 27 Aug 2022 03:43:39 +0000 (11:43 +0800)]
crypto/internal/boring/fipstls: convert required to atomic type

Change-Id: I73081b85e763122be1f5c0dbab25cecc9cf809df
Reviewed-on: https://go-review.googlesource.com/c/go/+/426087
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: xie cui <523516579@qq.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
21 months agocmd/go: support long commands in asm and cgo
Daniel Martí [Wed, 31 Aug 2022 13:25:11 +0000 (14:25 +0100)]
cmd/go: support long commands in asm and cgo

We have supported passing lists of arguments to the compiler and linker
for some time, since https://go.dev/issue/18468 was fixed.
The reason behind it is that some systems like Windows have relatively
small limits for commands, and some Go packages contain many source files.

This wasn't done for other Go toolchain programs like cgo and asm,
as there wasn't an initial need for it. A TODO was left for them.
The need has now arisen in the form of a bug report for a build of a
large Go package involving cgo.

Do asm as well, which could be triggered by lots of asm files.

I rebuilt Go itself with some basic logging to tell if any other
commands were being run with moderately large command lengths.
I only found one other: gcc being invoked with 300-500 bytes.

I didn't spot any length close to 1KiB, and we can't safely assume that
a user's CC compiler supports these "response files", so leave that as
another TODO for the future. Just like cgo and asm, we can revisit this
if any user reports a bug on the issue tracker.

Fixes #47235.

Change-Id: Ifcc099d7c0dfac3ed2c4e9e7a2d6e3d69b0ccb63
Reviewed-on: https://go-review.googlesource.com/c/go/+/427015
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

21 months agogo/types,types2: exclude tests that need cgo.Incomplete
Cuong Manh Le [Thu, 1 Sep 2022 03:32:20 +0000 (10:32 +0700)]
go/types,types2: exclude tests that need cgo.Incomplete

Since when go/types,types2 do not know about build constraints, and
runtime/cgo.Incomplete is only available on platforms that support cgo.

These tests are also failing on aix with failure from linker, so disable
them on aix to make builder green. The fix for aix is tracked in #54814

Updates #46731
Updates #54814

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

21 months agoreflect: fix Value.SetIterXXX to check for the read-only bit
Joe Tsai [Wed, 24 Aug 2022 02:10:45 +0000 (19:10 -0700)]
reflect: fix Value.SetIterXXX to check for the read-only bit

v.SetIterXXX(i) is semantically identical to v.Set(i.XXX()).
If the latter panics for unexported values, so should the former.

This change may breaking some programs, but the change is justified
under the "Go 1 and the Future of Go Programs" document because
the "library has a bug that violates the specification".
In this case, the "reflect" package does not accurately match
the behavior of the Go language specification.
Also, this API was recently released, so the number of users
who could be depending on this behavior is hopefully lower.

Fixes #54628

Change-Id: If86ede51f286e38093f6697944c089f616525115
Reviewed-on: https://go-review.googlesource.com/c/go/+/425184
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: David Chase <drchase@google.com>
21 months agotest: use cgo.Incomplete instead of go:notinheap for "run" tests
Cuong Manh Le [Sun, 7 Aug 2022 17:14:43 +0000 (00:14 +0700)]
test: use cgo.Incomplete instead of go:notinheap for "run" tests

Same as CL 421880, but for test directory.

Updates #46731

Change-Id: If8d18df013a6833adcbd40acc1a721bbc23ca6b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/421881
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>