]> Cypherpunks repositories - gostls13.git/log
gostls13.git
3 years agogo/types, types2: don't crash in selectors referring to the type being declared
Robert Griesemer [Sun, 6 Mar 2022 23:44:42 +0000 (15:44 -0800)]
go/types, types2: don't crash in selectors referring to the type being declared

In Checker.typInternal, the SelectorExpr case was the only case that
didn't either set or pass along the incoming def *Named type.

Handle this by passing it along to Checker.selector and report a
cycle if one is detected.

Fixes #51509.

Change-Id: I6c2d46835f225aeb4cb25fe0ae55f6180cef038b
Reviewed-on: https://go-review.googlesource.com/c/go/+/390314
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agogo/types, types2: correctly include comparable in type set intersection
Robert Griesemer [Fri, 4 Mar 2022 23:07:17 +0000 (15:07 -0800)]
go/types, types2: correctly include comparable in type set intersection

The comparable bit was handled incorrectly. This CL establishes
a clear invariant for a type set's terms and its comparable bit
and correctly uses the bit when computing term intersections.

Relevant changes:

- Introduce a new function intersectTermLists that does the
  correct intersection computation.

Minor:

- Moved the comparable bit after terms in _TypeSet to make it
  clearer that they belong together.

- Simplify and clarify _TypeSet.IsAll predicate.

- Remove the IsTypeSet predicate which was only used for error
  reporting in union.go, and use the existing predicates instead.

- Rename/introduce local variables in computeInterfaceTypeSet
  for consistency and to avoid confusion.

- Update some tests whose output has changed because the comparable
  bit is now only set if we have have the set of all types.
  For instance, for interface{comparable; int} the type set doesn't
  set the comparable bit because the intersection of comparable and
  int is just int; etc.

- Add many more comments to make the code clearer.

Fixes #51472.

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

3 years agocmd/compile: remove duplicate const logic from typecheck
Matthew Dempsky [Mon, 7 Mar 2022 16:54:28 +0000 (08:54 -0800)]
cmd/compile: remove duplicate const logic from typecheck

Now that we always use types2 to validate user source code, we can
remove the constSet logic from typecheck for detecting duplicate
expression switch cases and duplicate map literal keys. This logic is
redundant with types2, and currently causes unified IR to report
inappropriate duplicate constant errors that only appear after type
substitution.

Updates #42758.

Change-Id: I51ee2c5106eec9abf40eba2480dc52603c68ba21
Reviewed-on: https://go-review.googlesource.com/c/go/+/390474
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
3 years agoruntime: print goid when throwing in gentraceback
Michael Pratt [Fri, 4 Mar 2022 16:17:43 +0000 (11:17 -0500)]
runtime: print goid when throwing in gentraceback

This makes it easier to figure out where the crash is occurring.

Change-Id: Ie1f78a360367090dcd61c61b2a55c34f3e2ff2eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/390034
Trust: David Chase <drchase@google.com>
Reviewed-by: David Chase <drchase@google.com>
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
3 years agointernal/fuzz: fix TestUnmarshalMarshal on MIPS
Roland Shoemaker [Sat, 5 Mar 2022 16:47:33 +0000 (08:47 -0800)]
internal/fuzz: fix TestUnmarshalMarshal on MIPS

Previous value used in the float32 roundtrip used float32(math.NaN())-1
which caused the quiet/signal bit to flip, which seemed to break the
test on MIPS platforms. Instead switch to using float32(math.NaN())+1,
which preserves the bit and makes the test happy.

Possibly related to #37455
Fixes #51258

Change-Id: Ia85c649e89a5d02027c0ec197f0ff318aa819c19
Reviewed-on: https://go-review.googlesource.com/c/go/+/390214
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Trust: Roland Shoemaker <roland@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agotest: add test case for #51521
Matthew Dempsky [Mon, 7 Mar 2022 13:43:40 +0000 (05:43 -0800)]
test: add test case for #51521

The test case is already working with unified IR, so add it to make
sure we don't regress while finishing unified IR's support for
dictionaries.

Updates #51521.

Change-Id: Ib7c8bf9612d30cd552e8e631fd0d487dcb177f14
Reviewed-on: https://go-review.googlesource.com/c/go/+/390356
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years agocmd/compile: add itabs to unified IR dictionaries
Matthew Dempsky [Mon, 7 Mar 2022 11:35:14 +0000 (03:35 -0800)]
cmd/compile: add itabs to unified IR dictionaries

This CL changes unified IR to include itabs in its serialized
dictionary format.

Change-Id: I334c972dc1bc19293f955bb23cfb66844da7adec
Reviewed-on: https://go-review.googlesource.com/c/go/+/390355
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years agotest: additional generic type switch test coverage
Matthew Dempsky [Mon, 7 Mar 2022 10:27:35 +0000 (02:27 -0800)]
test: additional generic type switch test coverage

None of the current generic type switch test cases exercise type
switches where the instantiated case is an interface type.

Change-Id: I9272fa61b8dde1fe1a3702d524d4f40253ef19b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/390354
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years agocmd/compile: represent derived types with ir.DynamicType in unified IR
Matthew Dempsky [Mon, 7 Mar 2022 07:47:27 +0000 (23:47 -0800)]
cmd/compile: represent derived types with ir.DynamicType in unified IR

This CL switches unified IR to using ir.DynamicType for derived
types. This has an immediate effect of fixing compilation of generic
code that when fully stenciled results in statically invalid type
assertions. This does require updating typecheck to expect
ODYNAMICTYPE in type switches, but this is straightforward to
implement.

For now, we still statically resolve the runtime type (or itab)
pointer. However, a subsequent CL will allow reading these pointers
from the runtime dictionary.

Change-Id: I1666678fcc588bc9cb8b97871bd02b9059848e6d
Reviewed-on: https://go-review.googlesource.com/c/go/+/390336
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years agoflag: make tests silent
Daniel Martí [Sun, 6 Mar 2022 11:26:11 +0000 (11:26 +0000)]
flag: make tests silent

A few of the tests were printing garbage to stderr,
since FlagSet's default Output is os.Stderr:

$ go test
flag provided but not defined: -x
invalid value "1" for flag -v: test error
Usage of test:
flag needs an argument: -b
Usage of test:
  -b usage
PASS
ok   flag 0.008s

Add the remaining SetOutput(io.Discard) method calls.

Note that TestUserDefinedFunc was a tricky one.
Even with the added SetOutput calls,
the last part of the test would still print usage text to stderr.
It took me a while to figure out the problem was copying FlagSet.
I've filed go.dev/issue/51507 to record this particular sharp edge,
and the test code now avoids making FlagSet copies to avoid the bug.

Change-Id: I323f24091b98386312aa72df3eb890af6625628d
Reviewed-on: https://go-review.googlesource.com/c/go/+/390234
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agocmd/compile: remove unneeded type alias code in unified IR
Matthew Dempsky [Mon, 7 Mar 2022 03:52:08 +0000 (19:52 -0800)]
cmd/compile: remove unneeded type alias code in unified IR

Before #46477, the Go generics proposal allowed `type T = U` where `U`
was an uninstantiated generic type. However, we decided not to allow
that, and go/types and types2 have already been updated to disallow
it. This CL just removes the analogous code from unified IR.

Change-Id: I0fe6d1754c96790b498c1d5185b948333646d7de
Reviewed-on: https://go-review.googlesource.com/c/go/+/390315
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years agocmd/compile: fix reentrancy issue in unified IR function body reading
Matthew Dempsky [Mon, 7 Mar 2022 04:11:21 +0000 (20:11 -0800)]
cmd/compile: fix reentrancy issue in unified IR function body reading

We shouldn't need to read in function bodies for new functions found
during inlining, but something is expecting them to still be read
in. We should fix that code to not depend on them being read in, but
in the mean time reading them in anyway is at least correct, albeit
less efficient in time and space.

Fixes #49536.
Updates #50552.

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

3 years agoall: fix some typos
Dan Kortschak [Sat, 5 Mar 2022 08:51:15 +0000 (19:21 +1030)]
all: fix some typos

Change-Id: I7dfae0fc91c2d70873ec7ec920be7c0a4888153a
Reviewed-on: https://go-review.googlesource.com/c/go/+/390175
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Trust: Daniel Martí <mvdan@mvdan.cc>

3 years agofmt: clarify right-padded strings use spaces
Adam Shannon [Wed, 2 Mar 2022 23:05:39 +0000 (15:05 -0800)]
fmt: clarify right-padded strings use spaces

Fixes #51419

Change-Id: I0a32f41a6e6e01481ad58c7dddb57ec7085d77af
Reviewed-on: https://go-review.googlesource.com/c/go/+/389434
Reviewed-by: Rob Pike <r@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>

3 years agomath: don't use integer division that truncates to zero
Dan Kortschak [Tue, 21 Dec 2021 11:19:50 +0000 (21:49 +1030)]
math: don't use integer division that truncates to zero

Change-Id: I7389da0c3a63fea3be5c820f2ce0d0168a95ab4c
Reviewed-on: https://go-review.googlesource.com/c/go/+/373377
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agosyscall: use dup3 in forkAndExecInChild on OpenBSD
Tobias Klauser [Fri, 4 Mar 2022 08:49:32 +0000 (09:49 +0100)]
syscall: use dup3 in forkAndExecInChild on OpenBSD

Use dup3(oldfd, newfd, O_CLOEXEC) to atomically duplicate the file
descriptor and mark is as close-on-exec instead of dup2 & fcntl.

The dup3 system call first appeared in OpenBSD 5.7.

Change-Id: Ic06c2c7089dcdbd931ee24e5e8c316879d81474e
Reviewed-on: https://go-review.googlesource.com/c/go/+/389974
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agocmd/go: clarify error from 'go install' when arguments have mismatched versions and...
uji [Sat, 26 Feb 2022 13:58:54 +0000 (13:58 +0000)]
cmd/go: clarify error from 'go install' when arguments have mismatched versions and paths

Fixes #51196.

Change-Id: I0ee4d8234f11e4f3b71b81546518647e07fafd7d
GitHub-Last-Rev: 8fd1a77adff982dd00385c5b25a4e0cdf3e2e220
GitHub-Pull-Request: golang/go#51373
Reviewed-on: https://go-review.googlesource.com/c/go/+/388154
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Than McIntosh <thanm@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
3 years agoencoding/xml: improve the test coverage, fix minor bugs
Iskander Sharipov [Wed, 17 Nov 2021 14:46:22 +0000 (17:46 +0300)]
encoding/xml: improve the test coverage, fix minor bugs

Improve the test coverage of encoding/xml package by adding
the test cases for the execution paths that were not covered before.

Since it reveals a couple of issues, fix them as well while we're at it.

As I used an `strings.EqualFold` instead of adding one more `strings.ToLower`,
our fix to `autoClose()` tends to run faster as well as a result.

name             old time/op    new time/op    delta
HTMLAutoClose-8    5.93µs ± 2%    5.75µs ± 3%  -3.16%  (p=0.000 n=10+10)
name             old alloc/op   new alloc/op   delta
HTMLAutoClose-8    2.60kB ± 0%    2.58kB ± 0%  -0.46%  (p=0.000 n=10+10)
name             old allocs/op  new allocs/op  delta
HTMLAutoClose-8      72.0 ± 0%      67.0 ± 0%  -6.94%  (p=0.000 n=10+10)

The overall `encoding/xml` test coverage increase is `88.1% -> 89.9%`;
although it may look insignificant, this CL covers some important corner cases,
like `autoClose()` functionality (that was not tested at all).

Fixes #49635
Fixes #49636

Change-Id: I50b2769896c197eb285672313b7148f4fe8bdb38
Reviewed-on: https://go-review.googlesource.com/c/go/+/364734
Trust: Bryan Mills <bcmills@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agointernal/fuzz: handle Inf/NaN float values
Roland Shoemaker [Mon, 28 Feb 2022 13:42:11 +0000 (05:42 -0800)]
internal/fuzz: handle Inf/NaN float values

Fixes #51258

Change-Id: I3c8b785ac912d66e1a6e2179625e6903032b8330
Reviewed-on: https://go-review.googlesource.com/c/go/+/388354
Reviewed-by: Bryan Mills <bcmills@google.com>
Trust: Roland Shoemaker <roland@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agocrypto/sha512: fix stack size for previous change
Lynn Boger [Thu, 3 Mar 2022 13:28:44 +0000 (07:28 -0600)]
crypto/sha512: fix stack size for previous change

In a recent change CL 388654 a function was updated so it
no longer needed stack space, but the TEXT statement was
not updated to reflect that change. This corrects that problem.

Change-Id: I9e60cebddae620788b1097ab7b39c47b323d1f62
Reviewed-on: https://go-review.googlesource.com/c/go/+/389674
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Paul Murphy <murp@ibm.com>
3 years agodoc/go1.19: mention use of EDNS(0)
Ian Lance Taylor [Thu, 3 Mar 2022 04:16:55 +0000 (20:16 -0800)]
doc/go1.19: mention use of EDNS(0)

For #51153

Change-Id: I4374c63498b62ba7a08f146eebd034cbd50623f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/389634
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
3 years agosyscall: remove TestRlimit
Ian Lance Taylor [Fri, 4 Mar 2022 18:03:32 +0000 (10:03 -0800)]
syscall: remove TestRlimit

It's more trouble than it's worth. New code should be using x/sys/unix
anyhow.

Fixes #40564
Fixes #51479

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

3 years agocmd/go: avoid rebuilding itself in TestMain
Daniel Martí [Thu, 13 Jan 2022 12:46:34 +0000 (12:46 +0000)]
cmd/go: avoid rebuilding itself in TestMain

An extra "go build" was happening, for the sake of -tags=testgo,
which would insert some extra behavior into ./internal/work.

Instead, reuse the test binary as cmd/go directly,
by calling the main func when a special env var is set.
We still duplicate the test binary into testBin,
because we need a "go" executable in that directory for $PATH.

Finally, the special behavior is instead inserted via TestMain.

The numbers below represent how long it takes to run zero tests,
measured via:

benchcmd GoTestNothing go test -run=-

That is, the time it takes to run the first test is reduced by half.
Note that these numbers are on a warm build cache,
so if the -tags=testgo build were to be done from scratch,
the speed-up would be significantly more noticeable.

name           old time/op         new time/op         delta
GoTestNothing          830ms ± 2%          380ms ± 7%  -54.23%  (p=0.008 n=5+5)

name           old user-time/op    new user-time/op    delta
GoTestNothing          1.64s ± 1%          0.82s ± 3%  -50.24%  (p=0.008 n=5+5)

name           old sys-time/op     new sys-time/op     delta
GoTestNothing          306ms ± 7%          159ms ±28%  -48.15%  (p=0.008 n=5+5)

name           old peak-RSS-bytes  new peak-RSS-bytes  delta
GoTestNothing          173MB ± 1%          147MB ± 1%  -14.96%  (p=0.008 n=5+5)

Change-Id: I1f8fc71269a7b45bc5b82b7228e13f56589d44c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/378294
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
3 years agocrypto/rand: use fast key erasure RNG on plan9 instead of ANSI X9.31
Jason A. Donenfeld [Mon, 3 Jan 2022 17:48:51 +0000 (18:48 +0100)]
crypto/rand: use fast key erasure RNG on plan9 instead of ANSI X9.31

This should be a bit faster and slicker than the very old ANSI X9.31,
which relied on the system time. Uses AES instead of ChaCha because it's
in the standard library.

Reference: https://blog.cr.yp.to/20170723-random.html
Reference: https://github.com/jedisct1/supercop/blob/master/crypto_rng/aes256/ref/rng.c

Change-Id: Ib7b37a83cca29f5d346355b7cb8cfe5250086b95
Reviewed-on: https://go-review.googlesource.com/c/go/+/375215
Trust: Jason Donenfeld <Jason@zx2c4.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
3 years agocrypto/rand: separate out plan9 X9.31 /dev/random expander
Jason A. Donenfeld [Thu, 9 Dec 2021 14:24:38 +0000 (15:24 +0100)]
crypto/rand: separate out plan9 X9.31 /dev/random expander

The X9.31 expander is now only used for plan9. Perhaps once upon a time
there was a use for abstraction, but the code is now covered in hacky
"fileName == urandomDevice" and "GOOS == plan9" checks, to the point
where the abstraction is much too leaky. Since plan9 is the only
platform that has a /dev/random without a /dev/urandom, we can simplify
both the generic urandom code and the plan9 X9.31 code by separating
them into different files, each focusing on doing one thing well.

Change-Id: I0ca43b748a0fbbd60f2ec7819688a540506d34df
Reviewed-on: https://go-review.googlesource.com/c/go/+/370580
Trust: Jason Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
3 years agocrypto/ed25519/internal/edwards25519: sync with filippo.io/edwards25519
Filippo Valsorda [Wed, 5 Jan 2022 13:55:55 +0000 (08:55 -0500)]
crypto/ed25519/internal/edwards25519: sync with filippo.io/edwards25519

Import the following commits (and minor comment fixes):

    * 17a0e59 - field: fix heap escape in SqrtRatio <Filippo Valsorda>
    * edec5b9 - field: fix SqrtRatio when arguments and receiver alias <Filippo Valsorda>
    * 26ce6fc - edwards25519: expand the SetUniformBytes docs <Filippo Valsorda>
    * c1c1311 - edwards25519: make Scalar and field.Element setters return errors <Filippo Valsorda>

Change-Id: I102eb04818a2bed43467f3eda6fd4c46b09878fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/373077
Trust: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>

3 years agoruntime: support cgo traceback on linux arm64
eric fang [Fri, 17 Dec 2021 06:13:46 +0000 (06:13 +0000)]
runtime: support cgo traceback on linux arm64

Code essentially mirrors AMD64 implementation.

Change-Id: Ie97627a3041d1858fb1a30d2fc500302ab4011b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/373363
Trust: Eric Fang <eric.fang@arm.com>
Run-TryBot: Eric Fang <eric.fang@arm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agocmd/go: add links to workspaces reference and tutorial to go help work
Michael Matloob [Thu, 3 Mar 2022 21:18:31 +0000 (16:18 -0500)]
cmd/go: add links to workspaces reference and tutorial to go help work

For #45713

Change-Id: Ia2901cbfc5deb52503e74fcf9dff26a56ec582c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/389297
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agocmd/go: error out of 'go work use' if no directories are given
Bryan C. Mills [Thu, 3 Mar 2022 20:13:11 +0000 (15:13 -0500)]
cmd/go: error out of 'go work use' if no directories are given

Otherwise, the behavior of 'go work use -r' (without arguments)
may be surprising.

Change-Id: I50cf1339591720ec5bd333146b89c9944ce420d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/389855
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agocmd/go: make paths consistent between 'go work init' and 'go work use'
Bryan C. Mills [Thu, 3 Mar 2022 20:07:15 +0000 (15:07 -0500)]
cmd/go: make paths consistent between 'go work init' and 'go work use'

Fixes #51448

Change-Id: I86719b55037c377eb82154e169d8a9bbae20b77c
Reviewed-on: https://go-review.googlesource.com/c/go/+/389854
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
3 years agoruntime: remove fallback to pipe on platforms with pipe2
Tobias Klauser [Thu, 3 Mar 2022 09:19:07 +0000 (10:19 +0100)]
runtime: remove fallback to pipe on platforms with pipe2

On Linux, the minimum required kernel version for Go 1.18 was be changed
to 2.6.32, see #45964. The pipe2 syscall was added in 2.6.27.

All other platforms already provide the pipe2 syscall in the minimum
supported version:
- DragonFly BSD added it in version 4.2, see
  https://www.dragonflybsd.org/release42/
- FreeBSD added it in version 10.0, see
  https://www.freebsd.org/cgi/man.cgi?pipe(2)#end
- NetBSD added it in version 6.0, see
  https://man.netbsd.org/pipe2.2#HISTORY
- OpenBSD added it in version 5.7, see
  https://man.openbsd.org/pipe.2#HISTORY
- Illumos supports it since 2013, see
  https://www.illumos.org/issues/3714
- Solaris supports it since 11.4

This also allows to remove setNonblock which was only used in the pipe
fallback path on these platforms.

Change-Id: I1f40d32fd3065d74e22af77b9ff2292b9cf66706
Reviewed-on: https://go-review.googlesource.com/c/go/+/389354
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agoruntime: count spill slot for frame size at finalizer call
Cherry Mui [Thu, 3 Mar 2022 01:16:54 +0000 (20:16 -0500)]
runtime: count spill slot for frame size at finalizer call

The finalizer is called using reflectcall. When register ABI is
used, the finalizer's argument is passed in register(s). But the
frame size calculation does not include the spill slot. When the
argument actually spills, it may clobber the caller's stack frame.
This CL fixes it.

Change-Id: Ibcc7507c518ba65c1c5a7759e5cab0ae3fc7efce
Reviewed-on: https://go-review.googlesource.com/c/go/+/389574
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
3 years agosyscall, runtime/internal/syscall: always return 0 in r2 on ppc64{,le} linux syscalls
Paul E. Murphy [Mon, 14 Feb 2022 23:15:05 +0000 (17:15 -0600)]
syscall, runtime/internal/syscall: always return 0 in r2 on ppc64{,le} linux syscalls

Both endians perform syscalls similarly. Only CR0S0 and R3 hold
the resultant status of a syscall. A random value may be stored into
the second return value (r2) result in some cases. Always set it to
zero.

Fixes #51192

Change-Id: Ida6a5692578d2cdadf3099af28478b3bc364f623
Reviewed-on: https://go-review.googlesource.com/c/go/+/385796
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Trust: Paul Murphy <murp@ibm.com>

3 years agoapi: update next.txt for binary.AppendByteOrder interface
Joe Tsai [Thu, 3 Mar 2022 05:26:36 +0000 (21:26 -0800)]
api: update next.txt for binary.AppendByteOrder interface

CL 386017 added new API for encoding/binary package.
This file was accidentally not updated in the same CL.

Updates #50601

Change-Id: Iefeb596ba04b8c6576cf0fe42030f658a5848832
Reviewed-on: https://go-review.googlesource.com/c/go/+/389636
Trust: Joseph Tsai <joetsai@digital-static.net>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
3 years agogo/types, types2: fix scoping for iteration variables declared by range clause
Robert Griesemer [Thu, 3 Mar 2022 02:38:55 +0000 (18:38 -0800)]
go/types, types2: fix scoping for iteration variables declared by range clause

Also correct scope position for such variables.
Adjusted some comments.

Fixes #51437.

Change-Id: Ic49a1459469c8b2c7bc24fe546795f7d56c67cb4
Reviewed-on: https://go-review.googlesource.com/c/go/+/389594
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/asm,cmd/compile: generate preferred nop on PPC64
Paul E. Murphy [Tue, 1 Mar 2022 22:30:46 +0000 (16:30 -0600)]
cmd/asm,cmd/compile: generate preferred nop on PPC64

The preferred form of nop is ori 0,0,0. What was being generated was
or 0,0,0.

Fix a quirk in the assembler which effectively treats OR $0,Rx,Ry as
OR R0,Rx,Ry, and update the compiler to generate the preferred form.

Change-Id: I5ac4bf0258cff05b9eba516a767daebfc9e31bc7
Reviewed-on: https://go-review.googlesource.com/c/go/+/388974
Reviewed-by: Cherry Mui <cherryyz@google.com>
Trust: Paul Murphy <murp@ibm.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agocrypto/sha256: adapt ppc64le asm to work on ppc64
Paul E. Murphy [Tue, 25 Jan 2022 19:52:47 +0000 (13:52 -0600)]
crypto/sha256: adapt ppc64le asm to work on ppc64

Workaround the minor endian differences, and avoid needing to
stack a frame as extra VSRs can be used in a similar capacity.

The microbenchmarks show no significant differences on ppc64le/p9.

ppc64/linux performance difference on a POWER9:

name        old time/op    new time/op    delta
Hash8Bytes     686ns ± 0%     372ns ± 0%   -45.78%
Hash1K        9.17µs ± 0%    4.24µs ± 0%   -53.74%
Hash8K        67.9µs ± 0%    31.7µs ± 0%   -53.35%

Fixes #50785

Change-Id: I43d87670127df9767d54d10b5165b84e5b88f5d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/380776
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Trust: Paul Murphy <murp@ibm.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agoruntime: fix 32B backward copy on ppc64x
Paul E. Murphy [Tue, 8 Feb 2022 15:09:36 +0000 (09:09 -0600)]
runtime: fix 32B backward copy on ppc64x

The test to enter the 32b copy loop always fails, and execution
falls back to a single 8B/iteration copy loop for copies of more
than 7 bytes. Likewise, the 32B loop has SRC/DST args mixed,
and fails to truncate DWORDS after completing.

Fix these, and unroll the 8B/iteration loop as it will only
execute 1-3 times if reached.

POWER10 benchmarks:

name                             old speed      new speed       delta
MemmoveOverlap/32                5.28GB/s ± 0%  10.37GB/s ± 0%   +96.22%
MemmoveOverlap/64                5.97GB/s ± 0%  18.15GB/s ± 0%  +203.95%
MemmoveOverlap/128               7.67GB/s ± 0%  24.35GB/s ± 0%  +217.41%
MemmoveOverlap/256               14.1GB/s ± 0%   25.0GB/s ± 0%   +77.48%
MemmoveOverlap/512               14.2GB/s ± 0%   30.9GB/s ± 0%  +118.19%
MemmoveOverlap/1024              12.3GB/s ± 0%   36.4GB/s ± 0%  +194.75%
MemmoveOverlap/2048              13.7GB/s ± 0%   48.8GB/s ± 0%  +255.24%
MemmoveOverlap/4096              14.1GB/s ± 0%   43.4GB/s ± 0%  +208.80%
MemmoveUnalignedDstOverlap/32    5.07GB/s ± 0%   3.78GB/s ± 0%   -25.33%
MemmoveUnalignedDstOverlap/64    6.00GB/s ± 0%   9.59GB/s ± 0%   +59.78%
MemmoveUnalignedDstOverlap/128   7.66GB/s ± 0%  13.51GB/s ± 0%   +76.42%
MemmoveUnalignedDstOverlap/256   13.4GB/s ± 0%   24.3GB/s ± 0%   +80.92%
MemmoveUnalignedDstOverlap/512   13.9GB/s ± 0%   30.3GB/s ± 0%  +118.29%
MemmoveUnalignedDstOverlap/1024  12.3GB/s ± 0%   37.3GB/s ± 0%  +203.07%
MemmoveUnalignedDstOverlap/2048  13.7GB/s ± 0%   45.9GB/s ± 0%  +235.39%
MemmoveUnalignedDstOverlap/4096  13.9GB/s ± 0%   41.2GB/s ± 0%  +196.34%
MemmoveUnalignedSrcOverlap/32    5.13GB/s ± 0%   5.18GB/s ± 0%    +0.98%
MemmoveUnalignedSrcOverlap/64    6.26GB/s ± 0%   9.53GB/s ± 0%   +52.29%
MemmoveUnalignedSrcOverlap/128   7.94GB/s ± 0%  18.40GB/s ± 0%  +131.76%
MemmoveUnalignedSrcOverlap/256   14.1GB/s ± 0%   25.5GB/s ± 0%   +81.40%
MemmoveUnalignedSrcOverlap/512   14.2GB/s ± 0%   30.9GB/s ± 0%  +116.76%
MemmoveUnalignedSrcOverlap/1024  12.4GB/s ± 0%   46.4GB/s ± 0%  +275.22%
MemmoveUnalignedSrcOverlap/2048  13.7GB/s ± 0%   48.7GB/s ± 0%  +255.16%
MemmoveUnalignedSrcOverlap/4096  14.0GB/s ± 0%   43.2GB/s ± 0%  +208.89%

Change-Id: I9fc6956ff454a2856d56077d1014388fb74c1f52
Reviewed-on: https://go-review.googlesource.com/c/go/+/384074
Trust: Paul Murphy <murp@ibm.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agosort: use a different codegen strategy
Eli Bendersky [Tue, 28 Sep 2021 13:18:30 +0000 (06:18 -0700)]
sort: use a different codegen strategy

The existing codegen strategy in sort.go relied on parsing the sort.go source
with go/ast and a combination of an AST rewrite + code text rewrite with regexes
to generate zfuncversion -- the same sort functionality with a different variant
of data.

In preparation for implementing #47619, we need a more robust codegen
strategy. To generate variants required for the generic sort functions
in the slices package, we'd need significanly more complicated AST
rewrites, which would make genzfunc.go much heavier.

Instead, redo the codegen strategy to use text/template instead of AST rewrites.
gen_sort_variants.go now contains the code for the underlying sort functions,
and generates multiple versions of them based on Variant configuration structs.
With this approach, adding new variants to generate generic sort functions for
the slices package becomes trivial.

See the discussion in #47619 for more details on the design decisions.

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

3 years agocrypto/aes: improve performance for aes-cbc on ppc64le
Lynn Boger [Thu, 26 Aug 2021 12:09:50 +0000 (07:09 -0500)]
crypto/aes: improve performance for aes-cbc on ppc64le

This adds an asm implementation of aes-cbc for ppc64le to
improve performance. This is ported from the
cryptogams implementation as are other functions in
crypto/aes with further description at the top of
the asm file.

Improvements on a power10:

name             old time/op   new time/op    delta
AESCBCEncrypt1K   1.67µs ± 0%    0.87µs ±-48.15%
AESCBCDecrypt1K   1.35µs ± 0%    0.43µs ±-68.48%

name             old speed     new speed      delta
AESCBCEncrypt1K  614MB/s ± 0%  1184MB/s ± 0%+92.84%
AESCBCDecrypt1K  757MB/s ± 0%  2403M/s ± 0 +217.21%

A fuzz test to compare the generic Go implemenation
against the asm implementation has been added.

Change-Id: I18613dfc95c640820b8f1c60d29df638efc7a75c
Reviewed-on: https://go-review.googlesource.com/c/go/+/355429
Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Paul Murphy <murp@ibm.com>
Trust: Paul Murphy <murp@ibm.com>

3 years agocmd/go: ignore the workspace when running a package at a specified version
Bryan C. Mills [Wed, 2 Mar 2022 22:14:55 +0000 (17:14 -0500)]
cmd/go: ignore the workspace when running a package at a specified version

For #51390

Change-Id: I805e66809b2aafb48f7040dee72910dd7d6c1396
Reviewed-on: https://go-review.googlesource.com/c/go/+/388917
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
3 years agotesting: include ERROR_SHARING_VIOLATION in Windows cleanup retries
Bryan C. Mills [Wed, 2 Mar 2022 21:36:27 +0000 (16:36 -0500)]
testing: include ERROR_SHARING_VIOLATION in Windows cleanup retries

Fixes #51442
Updates #50051

Change-Id: I1bfbc08c907077467fd50febbec6299a9b73af41
Reviewed-on: https://go-review.googlesource.com/c/go/+/388916
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agoruntime: use stp/ldp to save and restore all registers on arm64
eric fang [Wed, 19 Jan 2022 04:02:25 +0000 (04:02 +0000)]
runtime: use stp/ldp to save and restore all registers on arm64

Async preemption needs to save and restore almost all of the registers,
currently this is done by ldr and str on arm64. We can do it with ldp
and stp as they are more efficient.

Change-Id: Ida5a6f0a8d825a56af607ba2c2cd91fdc2e8f67f
Reviewed-on: https://go-review.googlesource.com/c/go/+/379715
Reviewed-by: Cherry Mui <cherryyz@google.com>
Trust: Eric Fang <eric.fang@arm.com>
Run-TryBot: Eric Fang <eric.fang@arm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agonet: send EDNS(0) packet length in DNS query
Ian Lance Taylor [Tue, 15 Feb 2022 21:46:56 +0000 (13:46 -0800)]
net: send EDNS(0) packet length in DNS query

Advertise to DNS resolvers that we are willing and able to accept up
to 1232 bytes in a DNS packet. The value 1232 was chosen based on
https://dnsflagday.net/2020/.

For #6464
For #21160
For #44135
For #51127
Fixes #51153

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

3 years agocmd/compile: don't include instantiating types in type hash
Keith Randall [Wed, 2 Mar 2022 23:08:23 +0000 (15:08 -0800)]
cmd/compile: don't include instantiating types in type hash

This CL is a bit overkill, but it is pretty safe for 1.18. We'll
want to revisit for 1.19 so we can avoid the hash collisions between
types, e.g. G[int] and G[float64], that will cause some slowdowns
(but not incorrect behavior). Thanks Cherry for the simple idea.

Fixes #51250

Change-Id: I68130e09ba68e7cc35687bc623f63547bc552867
Reviewed-on: https://go-review.googlesource.com/c/go/+/389474
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agodoc: start draft of go1.19 release notes, move go1.18 to x/website
Carlos Amedee [Mon, 28 Feb 2022 23:04:20 +0000 (18:04 -0500)]
doc: start draft of go1.19 release notes, move go1.18 to x/website

This template is based on CL 342070 and previous ones like it.
Continue to eagerly include often-used sections, and clarify that
the TODO is about completing the section, or removing if it turns
out not to be needed.

Move the Go 1.18 release notes to x/website, since that's the new
home for past Go release notes as of CL 291711. They're added to
x/website in CL 388556.

For #51400
Updates #47694

Change-Id: I7b5213e039ad6e14a7ff7ad486311efcecc06824
Reviewed-on: https://go-review.googlesource.com/c/go/+/388515
Trust: Carlos Amedee <carlos@golang.org>
Run-TryBot: Carlos Amedee <carlos@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Alex Rakoczy <alex@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agodoc/go1.18: warn about possible breakage of 1.18 generic code
Ian Lance Taylor [Mon, 28 Feb 2022 18:19:43 +0000 (10:19 -0800)]
doc/go1.18: warn about possible breakage of 1.18 generic code

The Go 1 compatibility guarantee permits us to break code if there is
a specification error or a bug. Emphasize that for generics.

Change-Id: I8379a14cdab9f63bb747e961ca12d1adecfc2eb4
Reviewed-on: https://go-review.googlesource.com/c/go/+/388454
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
3 years agodoc: mention change in append behavior
Keith Randall [Thu, 17 Feb 2022 17:37:07 +0000 (09:37 -0800)]
doc: mention change in append behavior

Introduced in CL 347917.

Change-Id: I99b34341f787e779bd45b967110e70a035fa6558
Reviewed-on: https://go-review.googlesource.com/c/go/+/386217
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <martin@golang.org>
Trust: Martin Möhrmann <martin@golang.org>
Run-TryBot: Martin Möhrmann <martin@golang.org>

3 years agocrypto/sha512: add BE support to PPC64 asm implementation
Lynn Boger [Mon, 28 Feb 2022 21:36:11 +0000 (15:36 -0600)]
crypto/sha512: add BE support to PPC64 asm implementation

This adds big endian support for the assembly implementation of
sha512. There was a recent request to do this for sha256 for
AIX users; for completeness, the same is being done for sha512.
The majority of the code is common between big and little
endian with a few differences controlled by ifdefs: with LE
the generation of a mask is needed along with VPERM instructions
to put bytes in the correct order; some VPERMs need the V
registers in a different order.

name        old time/op    new time/op     delta
Hash8Bytes    1.02µs ± 0%     0.38µs ± 0%   -62.68%
Hash1K        7.01µs ± 0%     2.43µs ± 0%   -65.42%
Hash8K        50.2µs ± 0%     14.6µs ± 0%   -70.89%

Updates #50785

Change-Id: I739b5e7c07b22b5748af11ca781e82ac67adb4f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/388654
Reviewed-by: Cherry Mui <cherryyz@google.com>
Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agoencoding/binary: add AppendByteOrder
Joe Tsai [Wed, 16 Feb 2022 00:59:59 +0000 (16:59 -0800)]
encoding/binary: add AppendByteOrder

AppendByteOrder specifies new methods for LittleEndian and BigEndian
for appending an unsigned integer to a byte slice.

The performance of AppendXXX methods are slower than PutXXX methods
since the former needs to do a few slice operations,
while the latter is essentially a single integer store.
In practice, existing usages of PutXXX performed slicing operations
around the call such that this cost was present, regardless.

name                           time/op
PutUint16-24                   0.48ns ± 2%
AppendUint16-24                1.54ns ± 1%
PutUint32-24                   0.46ns ± 2%
AppendUint32-24                0.89ns ± 1%
PutUint64-24                   0.46ns ± 2%
AppendUint64-24                0.89ns ± 1%
LittleEndianPutUint16-24       0.47ns ± 2%
LittleEndianAppendUint16-24    1.54ns ± 1%
LittleEndianPutUint32-24       0.45ns ± 3%
LittleEndianAppendUint32-24    0.92ns ± 2%
LittleEndianPutUint64-24       0.46ns ± 3%
LittleEndianAppendUint64-24    0.95ns ± 4%

Fixes #50601

Change-Id: I33d2bbc93a3ce01a9269feac33a2432bc1166ead
Reviewed-on: https://go-review.googlesource.com/c/go/+/386017
Trust: Joseph Tsai <joetsai@digital-static.net>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agoreflect: allow Value.Bytes on addressable byte arrays
Joe Tsai [Sat, 4 Sep 2021 20:02:09 +0000 (13:02 -0700)]
reflect: allow Value.Bytes on addressable byte arrays

Modify Value.Bytes to be callable addressable byte arrays.
While related, the behavior of Value.SetBytes was not modified.

Fixes #47066

Change-Id: Ic3ba4432353b8da5f33b3188e20034a33b2f6ee8
Reviewed-on: https://go-review.googlesource.com/c/go/+/357331
Trust: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agocmd/go: allow users to specify required fields in JSON output
Michael Matloob [Wed, 26 Jan 2022 20:31:20 +0000 (15:31 -0500)]
cmd/go: allow users to specify required fields in JSON output

For #29666

Change-Id: Ibae3d75bb2c19571c8d473cb47d6c4b3a880bba8
Reviewed-on: https://go-review.googlesource.com/c/go/+/381035
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agosyscall: remove accept on Linux
Tobias Klauser [Fri, 18 Feb 2022 15:10:27 +0000 (16:10 +0100)]
syscall: remove accept on Linux

accept is no longer used on Linux since CL 346849 changed Accept to use
accept4 only.

For #45964

Change-Id: I72c13df1457016c4785ec13d356ab89cbca644b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/386415
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agoencoding/json: use reflect.Value.UnsafePointer over Pointer
Joe Tsai [Tue, 2 Nov 2021 19:01:24 +0000 (12:01 -0700)]
encoding/json: use reflect.Value.UnsafePointer over Pointer

The latter returns a uintptr, while the former returns a unsafe.Pointer.
A uintptr is unsafe if Go ever switches to a moving GC,
while a unsafe.Pointer will be properly tracked by the GC.

We do not use unsafe.Pointer for any unsafe type conversions,
and only use it for comparability purposes, which is relatively safe.

Updates #40592

Change-Id: I813e218668704b63a3043acda4331205a3835a66
Reviewed-on: https://go-review.googlesource.com/c/go/+/360855
Trust: Joseph Tsai <joetsai@digital-static.net>
Trust: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agocompress/gzip: return unexpected EOF for certain truncated streams
Phil Bracikowski [Wed, 2 Mar 2022 01:51:28 +0000 (01:51 +0000)]
compress/gzip: return unexpected EOF for certain truncated streams

For cases where RFC 1952 requires a field, the code returns the error
io.ErrUnexpectedEOF except in two places: for the FNAME flag or the
FCOMMENT flag. These flags expect a null-terminated string and
readString may return an EOF if the Reader is truncated before a
null byte is found. For consistency with parsing other parts of the
header, this is converted to an unexpected EOF herein.

Follow-up to CL 14832.

Fixes #51417

Change-Id: I173283a6ae309e4a8e52fc15df404ce5db06eff1
GitHub-Last-Rev: 2e573cd961c0b1e4296fbde53097cf5723a2ca29
GitHub-Pull-Request: golang/go#51418
Reviewed-on: https://go-review.googlesource.com/c/go/+/389034
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Trust: Joseph Tsai <joetsai@digital-static.net>
Trust: Ian Lance Taylor <iant@golang.org>

3 years agocmd/link: don't generate typedef DWARF entry for noalg.struct{...}
MoZhonghua [Fri, 17 Dec 2021 06:53:21 +0000 (06:53 +0000)]
cmd/link: don't generate typedef DWARF entry for noalg.struct{...}

cmd/compile uses "noalg.struct {...}" as type name when hash and eq algorithm generation of this struct type is suppressed. This should be treated as normal struct type, that is, link shouldn't generate DW_TAG_typedef DIE for it.

Change-Id: Ifada8a818bcfa2e5615f85ead9582cead923b86c
GitHub-Last-Rev: 15de3e4a846fcd79e231384539be20b06197b826
GitHub-Pull-Request: golang/go#50237
Reviewed-on: https://go-review.googlesource.com/c/go/+/373054
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agoregexp: fix typo in the overview
Jinwook Jeong [Mon, 1 Nov 2021 14:46:47 +0000 (23:46 +0900)]
regexp: fix typo in the overview

Correct the slice expression in the description of Index functions.

Change-Id: I97a1b670c4c7e600d858f6550b647f677ef90b41
Reviewed-on: https://go-review.googlesource.com/c/go/+/360058
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Trust: Daniel Martí <mvdan@mvdan.cc>

3 years agounicode/utf8: optimize Valid to parity with ValidString
Alan Donovan [Wed, 5 Jan 2022 14:20:15 +0000 (09:20 -0500)]
unicode/utf8: optimize Valid to parity with ValidString

The benchmarks added in this change revealed that ValidString
runs ~17% faster than Valid([]byte) on the ASCII prefix
of the input. Inspection of the assembly revealed that the
code generated for p[8:] required recomputing the slice capacity
to handle the cap=0 special case, which added an ADD -8 instruction.
By making len=cap, the capacity becomes a common subexpression
with the length, saving the ADD instruction.
(Thanks to khr for the tip.)

Incidentally, I tried a number of other optimizations but was
unable to make consistent gains across all benchmarks. The most
promising was to retain the bitmask of non-ASCII bytes from the
fast loop; the slow loop would shift it, and when it becomes zero,
return to the fast loop. This made the MostlyASCII benchmark 4x
faster, but made the other cases slower by up to 10%.

cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
benchmark                                   old ns/op     new ns/op     delta
BenchmarkValidTenASCIIChars-16              4.09          4.06          -0.85%
BenchmarkValid100KASCIIChars-16             9325          7747          -16.92%
BenchmarkValidTenJapaneseChars-16           27.0          27.2          +0.85%
BenchmarkValidLongMostlyASCII-16            57277         58361         +1.89%
BenchmarkValidLongJapanese-16               94002         93131         -0.93%
BenchmarkValidStringTenASCIIChars-16        4.15          4.07          -1.74%
BenchmarkValidString100KASCIIChars-16       7980          8019          +0.49%
BenchmarkValidStringTenJapaneseChars-16     26.0          25.9          -0.38%
BenchmarkValidStringLongMostlyASCII-16      58550         58006         -0.93%
BenchmarkValidStringLongJapanese-16         97964         100038        +2.12%

Change-Id: Ic9d585dedd9af83c27dd791ecd805150ac949f15
Reviewed-on: https://go-review.googlesource.com/c/go/+/375594
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Alex Rakoczy <alex@golang.org>

3 years agogo/token: slight performance improvement for IsIdentifier
chanxuehong [Mon, 21 Feb 2022 08:51:05 +0000 (08:51 +0000)]
go/token: slight performance improvement for IsIdentifier

If name is empty or a keyword, we can skip the loop entirely.
Otherwise, we do the same amount of work as before.

Here is the benchmark result for go/parser:

name          old time/op    new time/op    delta
Parse-12        2.53ms ± 2%    2.47ms ± 1%  -2.38%  (p=0.000 n=9+10)
ParseOnly-12    1.97ms ± 1%    1.93ms ± 2%  -1.80%  (p=0.000 n=10+10)
Resolve-12       560µs ± 1%     558µs ± 1%    ~     (p=0.200 n=9+8)

name          old speed      new speed      delta
Parse-12      26.1MB/s ± 2%  26.8MB/s ± 1%  +2.44%  (p=0.000 n=9+10)
ParseOnly-12  33.6MB/s ± 1%  34.3MB/s ± 2%  +1.82%  (p=0.000 n=10+10)
Resolve-12     118MB/s ± 2%   119MB/s ± 1%    ~     (p=0.116 n=10+8)

Change-Id: I87ac9c2637a6c0e697382b74245ac88ef523bba7
GitHub-Last-Rev: 036bc38d837c095dd5a8d97ece83e1596d875d3e
GitHub-Pull-Request: golang/go#48534
Reviewed-on: https://go-review.googlesource.com/c/go/+/351389
Trust: David Chase <drchase@google.com>
Trust: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Robert Griesemer <gri@golang.org>
3 years agomath/big: produce valid JSON in Int.MarshalJSON when nil
cuiweixie [Sat, 12 Feb 2022 15:19:18 +0000 (15:19 +0000)]
math/big: produce valid JSON in Int.MarshalJSON when nil

Fixes #50940.

Change-Id: Ie2a0c4505ca9d7e448017d9d00a020a6b3996be3
GitHub-Last-Rev: afd8c6b5598f43de25831c700b8d76cd97571426
GitHub-Pull-Request: golang/go#50941
Reviewed-on: https://go-review.googlesource.com/c/go/+/381963
Trust: Cherry Mui <cherryyz@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Trust: Daniel Martí <mvdan@mvdan.cc>

3 years agogo/types, types2: clarify a comment and add an extra test
Robert Griesemer [Mon, 28 Feb 2022 05:08:29 +0000 (21:08 -0800)]
go/types, types2: clarify a comment and add an extra test

Confirm that the current implementation of core type unification
looks correct and update the respective comment. Add an extra test.

Fixes #51376.

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

3 years agogo/types, types2: correctly consider ~ (tilde) in constraint type inference
Robert Griesemer [Fri, 25 Feb 2022 06:11:40 +0000 (22:11 -0800)]
go/types, types2: correctly consider ~ (tilde) in constraint type inference

When doing constraint type inference, we must consider whether the
constraint's core type is precise (no tilde) or imprecise (tilde,
or not a single specific type). In the latter case, we cannot infer
an unknown type argument from the (imprecise) core type because there
are infinitely many possible types. For instance, given

        [E ~byte]

if we don't know E, we cannot infer that E must be byte (it could be
myByte, etc.). On the other hand, if we do know the type argument,
say for S in this example:

        [S ~[]E, E any]

we must consider the underlying type of S when matching against ~[]E
because we have a tilde.

Because constraint type inference may infer type arguments that were
not eligible initially (because they were unknown and the core type
is imprecise), we must iterate the process until nothing changes any-
more. For instance, given

        [S ~[]E, M ~map[string]S, E any]

where we initially only know the type argument for M, we must ignore
S (and E) at first. After one iteration of constraint type inference,
S is known at which point we can infer E as well.

The change is large-ish but the actual functional changes are small:

- There's a new method "unknowns" to determine the number of as of yet
  unknown type arguments.

- The adjCoreType function has been adjusted to also return tilde
  and single-type information. This is now conveniently returned
  as (*term, bool), and the function has been renamed to coreTerm.

- The original constraint type inference loop has been adjusted to
  consider tilde information.

- This adjusted original constraint type inference loop has been
  nested in another loop for iteration, together with some minimal
  logic to control termination.

The remaining changes are modifications to tests:

- There's a substantial new test for this issue.

- Several existing test cases were adjusted to accomodate the
  fact that they inferred incorrect types: tildes have been
  removed throughout. Most of these tests are for pathological
  cases.

- A couple of tests were adjusted where there was a difference
  between the go/types and types2 version.

Fixes #51229.

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

3 years agocmd/compile: include all entries in map literal hint size
Keith Randall [Sun, 6 Feb 2022 17:43:39 +0000 (09:43 -0800)]
cmd/compile: include all entries in map literal hint size

Currently we only include static entries in the hint for sizing
the map when allocating a map for a map literal. Change that to
include all entries.

This will be an overallocation if the dynamic entries in the map have
equal keys, but equal keys in map literals are rare, and at worst we
waste a bit of space.

Fixes #43020

Change-Id: I232f82f15316bdf4ea6d657d25a0b094b77884ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/383634
Run-TryBot: Keith Randall <khr@golang.org>
Trust: Keith Randall <khr@golang.org>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agointernal/pkgbits: add version number
Matthew Dempsky [Tue, 1 Mar 2022 20:58:20 +0000 (12:58 -0800)]
internal/pkgbits: add version number

Especially once this code gets copied into x/tools, we need a way to
evolve the file format, so add an explicit version number.

Change-Id: I9cc2e357c3ca3f07fd8d0c0ba4e4a95f89edeac6
Reviewed-on: https://go-review.googlesource.com/c/go/+/388914
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
3 years agocmd/compile: use AutogeneratedPos for method value wrapper
Cherry Mui [Tue, 1 Mar 2022 17:02:38 +0000 (12:02 -0500)]
cmd/compile: use AutogeneratedPos for method value wrapper

We use AutogeneratedPos for most compiler-generated functions. But
for method value wrappers we currently don't. Instead, we use the
Pos for their (direct) declaration if there is one, otherwise
not set it in methodValueWrapper, which will probably cause it to
inherit from the caller, i.e. the Pos of that method value
expression. If that Pos has inline information, it will cause the
method wrapper to have bogus inline information, which could lead
to infinite loop when printing a stack trace.

Change it to use AutogeneratedPos instead.

Fixes #51401.

Change-Id: I398dfe85f9f875e1fd82dc2f489dab63ada6570d
Reviewed-on: https://go-review.googlesource.com/c/go/+/388794
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
3 years agotest: workaround codegen bug in typeparam/mdempsky/13.go
Matthew Dempsky [Tue, 1 Mar 2022 20:21:04 +0000 (12:21 -0800)]
test: workaround codegen bug in typeparam/mdempsky/13.go

This test case is failing on the noopt builder, because it disables
inlining. Evidently the explicit -gcflags flag in all of our generics
tests was overriding the noopt builder's default mode.

This CL restores a noop -gcflags to get the builder green again until
the issue can be properly fixed.

Updates #51413.

Change-Id: I61d22a007105f756104ba690b73f1d68ce4be281
Reviewed-on: https://go-review.googlesource.com/c/go/+/388894
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agocmd/compile/internal/ir: remove unused -G=0 node types
Matthew Dempsky [Mon, 28 Feb 2022 23:31:35 +0000 (15:31 -0800)]
cmd/compile/internal/ir: remove unused -G=0 node types

ir.PkgName was only used by the old -G=0 frontend for representing
identifiers that refer to a package name. The new types2-based
frontends directly resolve the qualified identifier to the respective
object during IR construction.

Similarly, most of the ir.*Type nodes were only needed for
representing types in the IR prior to type checking. The new
types2-based frontends directly construct the corresponding types.Type
instead.

Exception: The internal typecheck.DeclFunc API used for
compiler-generated functions still depends on ir.FuncType, so that IR
node type is retained for now. (Eventually, we should update
typecheck.DeclFunc and callers to not depend on it, but it's not
urgent.)

Change-Id: I982f1bbd41eef5b42ce0f32676c7dc4a8ab6d0ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/388538
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
3 years agocmd/compile/internal/typecheck: remove unused -G=0 code
Matthew Dempsky [Mon, 28 Feb 2022 23:07:56 +0000 (15:07 -0800)]
cmd/compile/internal/typecheck: remove unused -G=0 code

The typechecking code for dealing with dot imports and redeclaration
errors can be removed, as these will now always be caught by types2
instead. Even when running the typecheck on internally constructed IR,
we'll never introduce new imports or redeclare identifiers.

Also, Func.Shortname (and typecheck.addmethod) was only used by the
-G=0 frontend. The new types2-based frontends directly associate
methods with their receiver type during IR construction.

Change-Id: I6578a448412141c87a0a53a6566639d9c00eeed7
Reviewed-on: https://go-review.googlesource.com/c/go/+/388537
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
3 years agocmd/compile: remove a bunch of dead noder code
Matthew Dempsky [Mon, 28 Feb 2022 22:35:52 +0000 (14:35 -0800)]
cmd/compile: remove a bunch of dead noder code

This code was only needed for supporting -G=0 mode, which is now gone.

Change-Id: I504887ab179e357a3cd21ef582f9edae49f6cbb6
Reviewed-on: https://go-review.googlesource.com/c/go/+/388536
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
3 years agocmd/compile: remove -G flag
Matthew Dempsky [Mon, 28 Feb 2022 22:09:47 +0000 (14:09 -0800)]
cmd/compile: remove -G flag

Post 1.18, we're committed to types2 as cmd/compile's type checker.

Change-Id: I30d2dd2b2ba62832fcdcaeb996fcbc8a4a05d591
Reviewed-on: https://go-review.googlesource.com/c/go/+/388535
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
3 years agoall: avoid use of cmd/compile -G flag in tests
Matthew Dempsky [Mon, 28 Feb 2022 22:32:19 +0000 (14:32 -0800)]
all: avoid use of cmd/compile -G flag in tests

The next CL will remove the -G flag, effectively hard-coding it to its
current default (-G=3).

Change-Id: Ib4743b529206928f9f1cca9fdb19989728327831
Reviewed-on: https://go-review.googlesource.com/c/go/+/388534
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agocmd/compile/internal/importer: lazier unified IR importing
Matthew Dempsky [Tue, 1 Mar 2022 05:21:40 +0000 (21:21 -0800)]
cmd/compile/internal/importer: lazier unified IR importing

No need to eagerly read the object dictionary or setup the object
reader outside of the lazy resolve function.

Change-Id: Ic4245b0c09f3beaff97860d7f2dfb5b2b5778cc9
Reviewed-on: https://go-review.googlesource.com/c/go/+/388615
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years agocmd/compile: move unified IR's reader2 into importer package
Matthew Dempsky [Tue, 1 Mar 2022 04:35:24 +0000 (20:35 -0800)]
cmd/compile: move unified IR's reader2 into importer package

This keeps cmd/compile/internal/importer similar to how
go/internal/gcimporter will work after unified IR support is added in
a subsequent CL.

Change-Id: Id3c000f3a13a54a725602552c6b3191d1affb184
Reviewed-on: https://go-review.googlesource.com/c/go/+/388614
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years agocmd/compile: use bool->uint8 op instead of copy
Keith Randall [Wed, 15 Dec 2021 23:59:43 +0000 (15:59 -0800)]
cmd/compile: use bool->uint8 op instead of copy

Just a cleanup to make sure that generic SSA is properly typed.

Change-Id: Ie75fa972ae4e5fdaca535968769bca36044191c9
Reviewed-on: https://go-review.googlesource.com/c/go/+/372574
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
3 years agoruntime: improve work stealing randomness
Keith Randall [Tue, 7 Dec 2021 17:22:33 +0000 (09:22 -0800)]
runtime: improve work stealing randomness

For certain values of GOMAXPROCS, the current code is less random than
it looks. For example with GOMAXPROCS=12, there are 4 coprimes: 1 5 7 11.
That's bad, as 12 and 4 are not relatively prime. So if pos == 2, then we
always pick 7 as the inc. We want to pick pos and inc independently
at random.

Change-Id: I5c7e4f01f9223cbc2db12a685dc0bced2cf39abf
Reviewed-on: https://go-review.googlesource.com/c/go/+/369976
Run-TryBot: Keith Randall <khr@golang.org>
Trust: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
3 years agocmd/compile: avoid generating unreachable branch for select cases
zhouguangyuan [Wed, 26 Jan 2022 12:23:11 +0000 (20:23 +0800)]
cmd/compile: avoid generating unreachable branch for select cases

Fixes #50823

Change-Id: I1c12e875b840eecadefb0d9e044ff2a268ccfbaa
Reviewed-on: https://go-review.googlesource.com/c/go/+/380894
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Michael Knyszek <mknyszek@google.com>

3 years agocmd/compile: don't panic when printing package-less symbols
Keith Randall [Wed, 9 Feb 2022 19:42:54 +0000 (11:42 -0800)]
cmd/compile: don't panic when printing package-less symbols

Some of the SSA pseudo-variables like the memory variable don't
have a package. Print those gracefully instead of printing a panic.

Fixes #51108

Change-Id: I5c29029356e045c5cf70909d6e63666ebc58ffaa
Reviewed-on: https://go-review.googlesource.com/c/go/+/384614
Trust: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agocmd/compile: unified IR support for implicit interfaces
Matthew Dempsky [Wed, 2 Feb 2022 01:41:46 +0000 (17:41 -0800)]
cmd/compile: unified IR support for implicit interfaces

Change-Id: Ibdaa0750f7bc47b513c047fdf4b7145ebba9e870
Reviewed-on: https://go-review.googlesource.com/c/go/+/386001
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>

3 years agointernal/pkgbits: extract unified IR coding-level logic
Matthew Dempsky [Mon, 14 Feb 2022 17:41:19 +0000 (09:41 -0800)]
internal/pkgbits: extract unified IR coding-level logic

This logic is needed for the go/types unified IR importer, so extract
it into a separate internal package so we can reuse a single copy.

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

3 years agocmd/compile: shuffle and simplify sync markers
Matthew Dempsky [Mon, 14 Feb 2022 16:54:37 +0000 (08:54 -0800)]
cmd/compile: shuffle and simplify sync markers

Change-Id: I5894ac4697212267380b7a03876927bbf3e1de2b
Reviewed-on: https://go-review.googlesource.com/c/go/+/385999
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agocmd/compile: remove unified IR quirks mode
Matthew Dempsky [Fri, 11 Feb 2022 19:55:27 +0000 (11:55 -0800)]
cmd/compile: remove unified IR quirks mode

Unified IR quirks mode existed to help bootstrap unified IR by forcing
it to produce bit-for-bit identical output to the original gc noder
and typechecker. However, I believe it's far enough along now to stand
on its own, plus we have good test coverage of generics already for
-G=3 mode.

Change-Id: I8bf412c8bb5d720eadeac3fe31f49dc73679da70
Reviewed-on: https://go-review.googlesource.com/c/go/+/385998
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years agointernal/goversion: update Version to 1.19
Carlos Amedee [Mon, 28 Feb 2022 15:54:32 +0000 (10:54 -0500)]
internal/goversion: update Version to 1.19

This is the start of the Go 1.19 development cycle, so update the
Version value accordingly. It represents the Go 1.x version that will
soon open up for development (and eventually become released).

Updates #40705
Updates #51336

Change-Id: Ic4b3f2c04b1fa5c588cb6d62e829f2ed1864e511
Reviewed-on: https://go-review.googlesource.com/c/go/+/388376
Trust: Carlos Amedee <carlos@golang.org>
Run-TryBot: Carlos Amedee <carlos@golang.org>
Trust: Alex Rakoczy <alex@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Alex Rakoczy <alex@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agocmd/go: make work and work_edit script tests version-independent
Michael Matloob [Mon, 28 Feb 2022 21:39:28 +0000 (16:39 -0500)]
cmd/go: make work and work_edit script tests version-independent

The work and work_edit script tests ran go work init, which put the
current Go version into the go.work files. Before this change, the tests
used cmp to compare the outputs with a file that contained a literal
"go 1.18" line. Instead, use cmpenv so we can compare with
"go $goversion". (Some of the test cases still compare against files
that contain "go 1.18" lines, but these tests explicitly set the version
to go 1.18 either in the original go.work files or using go work edit.)

Change-Id: Iea2caa7697b5fe5939070558b1664f70130095ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/388514
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
3 years agocmd/internal/obj/riscv/testdata/testbranch: add //go:build lines
Tobias Klauser [Mon, 28 Feb 2022 13:34:11 +0000 (14:34 +0100)]
cmd/internal/obj/riscv/testdata/testbranch: add //go:build lines

Change-Id: I95ea33c0aad7d427da99c0ea7d0869f10ed5dd71
Reviewed-on: https://go-review.googlesource.com/c/go/+/388334
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agoall: fix typos
cuishuang [Mon, 28 Feb 2022 12:17:25 +0000 (12:17 +0000)]
all: fix typos

Change-Id: I93ff3d33a5db130dd57a9545456f2961fc3f668b
GitHub-Last-Rev: f95fafc04937a99f82cb992aabb7bac602033d8e
GitHub-Pull-Request: golang/go#51394
Reviewed-on: https://go-review.googlesource.com/c/go/+/388314
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
3 years agogo/types, types2: fix string to type parameter conversions
Robert Griesemer [Mon, 28 Feb 2022 02:13:23 +0000 (18:13 -0800)]
go/types, types2: fix string to type parameter conversions

Converting an untyped constant to a type parameter results
in a non-constant value; but the constant must still be
representable by all specific types of the type parameter.

Adjust the special handling for constant-to-type parameter
conversions to also include string-to-[]byte and []rune
conversions, which are handled separately for conversions
to types that are not type parameters because those are not
constant conversions in non-generic code.

Fixes #51386.

Change-Id: I15e5a0fd281efd15af387280cd3dee320a1ac5e1
Reviewed-on: https://go-review.googlesource.com/c/go/+/388254
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile: deal with constructed types that have shapes in them
Dan Scales [Wed, 23 Feb 2022 05:41:43 +0000 (21:41 -0800)]
cmd/compile: deal with constructed types that have shapes in them

We convert type args to shape types inside instantiations. If an
instantiation constructs a compound type based on that shape type and
uses that as a type arg to another generic function being called, then
we have a type arg with a shape type embedded inside of it. In that
case, we need to substitute out those embedded shape types with their
underlying type.

If we don't do this, we may create extra unneeded shape types that
have these other shape types embedded in them. This may lead to
generating extra shape instantiations, and a mismatch between the
instantiations that we used in generating dictionaries and the
instantations that are actually called.

Updates #51303

Change-Id: Ieef894a5fac176cfd1415f95926086277ad09759
Reviewed-on: https://go-review.googlesource.com/c/go/+/387674
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agospec: the -'s possessive suffix is English, not code
Matthew Dempsky [Sun, 27 Feb 2022 05:08:52 +0000 (21:08 -0800)]
spec: the -'s possessive suffix is English, not code

Change-Id: I2debcf926ef116c632c7366646d37de8686b7c9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/388174
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>

3 years agoruntime: avoid cgo_unsafe_args for syscall.syscall functions on darwin/arm64
Cherry Mui [Fri, 18 Feb 2022 18:09:54 +0000 (13:09 -0500)]
runtime: avoid cgo_unsafe_args for syscall.syscall functions on darwin/arm64

Currently, syscall.syscall-like functions are defined as
cgo_unsafe_args, which makes them ABI0, as it takes the address of
the argument area based on ABI0 layout. Those functions are
linkname'd to the syscall package. When compiling the syscall
package, the compiler doesn't know they are ABI0 therefore
generate an ABIInternal call, which will use the wrapper. As some
of the functions (e.g. syscall6) has many arguments, the wrapper
would take a good amount of stack space. And those functions must
be nosplit. This causes nosplit overflow when building with -N -l
and -race.

Avoid that by rewriting the functions to not use cgo_unsafe_args.
Instead, make a struct locally and pass the address of that
struct. This way the functions are ABIInternal and the call will
not use the wrapper.

Fixes #51247.

Change-Id: I76c1ab86b9d28664fa7d5b9c7928fbb2fd8d1417
Reviewed-on: https://go-review.googlesource.com/c/go/+/386719
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
3 years agocmd/compile: fix case for structural types where we should be looking at typeparams
Dan Scales [Fri, 25 Feb 2022 22:56:04 +0000 (14:56 -0800)]
cmd/compile: fix case for structural types where we should be looking at typeparams

In getInstantiation, we were not computing tparams correctly for the
case where the receiver of a method was a fully-instantiated type. This
wasn't affecting later parts of the function, since method
instantiations of fully-instantiated types were already being calculated
in an earlier path. But it did give us a non-typeparam when trying to
see if a shape was associated with a type param with a structural type.
The fix is just to get the typeparams associated with the base generic
type. Then we can eliminate a conditional check later in the code.
The tparam parameter of Shapify should always be non-nil

Fixes #51367

Change-Id: I6f95fe603886148b2dad0c581416c51373c85009
Reviewed-on: https://go-review.googlesource.com/c/go/+/388116
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
3 years agocmd/compile: emit types of constants which are instantiated generic types
Keith Randall [Sat, 26 Feb 2022 00:06:53 +0000 (16:06 -0800)]
cmd/compile: emit types of constants which are instantiated generic types

Normally types of constants are emitted when the type is defined (an
ODCLTYPE). However, the types of constants where the type is an
instantiated generic type made inside the constant declaration, do not
normally get emitted. But the DWARF processor in the linker wants
to see those types. So we emit them during stenciling.

Fixes #51245

Change-Id: I59f20f1d7b91501c9ac760cf839a354356331fc6
Reviewed-on: https://go-review.googlesource.com/c/go/+/388117
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
3 years agoCONTRIBUTORS: update for the Go 1.18 release
Dmitri Shuralyov [Mon, 28 Feb 2022 14:28:47 +0000 (09:28 -0500)]
CONTRIBUTORS: update for the Go 1.18 release

This update was created using the updatecontrib command:

go install golang.org/x/build/cmd/updatecontrib@latest
cd gotip
updatecontrib

With manual changes based on publicly available information
to canonicalize letter case and formatting for a few names.

For #12042.

Change-Id: If08b7e798cff6ec4248011bdadcc524b510aaff7
Reviewed-on: https://go-review.googlesource.com/c/go/+/388394
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Trust: Carlos Amedee <carlos@golang.org>

3 years agotest: add new test case for 51219 that triggers the types2 issue
Dan Scales [Thu, 24 Feb 2022 01:57:09 +0000 (17:57 -0800)]
test: add new test case for 51219 that triggers the types2 issue

The existing test for 51219 didn't actually trigger the types2 issue - I
hadn't been able to minimize the test case yet properly. This new test
case issue51219b.go now does trigger the types2 issue (it's only
slightly different).

Updates #51219

Change-Id: Iaba8144b4702ff4fefec86c899b8acef127b10dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/387814
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile: ensure dictionary assignment statements are defining statements
Keith Randall [Fri, 25 Feb 2022 23:10:24 +0000 (15:10 -0800)]
cmd/compile: ensure dictionary assignment statements are defining statements

The problem in 51355 is that escape analysis decided that the
dictionary variable was captured by reference instead of by value. We
want dictionaries to always be captured by value.

Escape analysis was confused because it saw what it thought was a
reassignment of the dictionary variable. In fact, it was the only
assignment, it just wasn't marked as the defining assignment. Fix
that.

Add an assert to make sure this stays true.

Fixes #51355

Change-Id: Ifd9342455fa107b113f5ff521a94cdbf1b8a7733
Reviewed-on: https://go-review.googlesource.com/c/go/+/388115
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Dan Scales <danscales@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

3 years agogo/types, types2: report an error for x.sel where x is a built-in
Robert Griesemer [Fri, 25 Feb 2022 19:10:44 +0000 (11:10 -0800)]
go/types, types2: report an error for x.sel where x is a built-in

In case of a selector expression x.sel where x is a built-in
we didn't report an error because the type of built-ins is
invalid and we surpress errors on operands of invalid types,
assuming that an error has been reported before.

Add a corresponding check for this case.

Review all places where we call Checker.exprOrType to ensure
(invalid) built-ins are reported.

Adjusted position for index error in types2.

Fixes #51360.

Change-Id: I24693819c729994ab79d31de8fa7bd370b3e8469
Reviewed-on: https://go-review.googlesource.com/c/go/+/388054
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agogo/types,types2: revert documentation for Type.Underlying
Robert Findley [Fri, 25 Feb 2022 23:20:12 +0000 (18:20 -0500)]
go/types,types2: revert documentation for Type.Underlying

In the dev.typeparams branch, the documentation for Type.Underlying was
updated with commentary about forwarding chains. This aspect of
Underlying should not be exposed to the user. Revert to the
documentation of Go 1.16.

Fixes #51036

Change-Id: I4b73d3908a88606314aab56540cca91c014dc426
Reviewed-on: https://go-review.googlesource.com/c/go/+/388036
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
3 years agoruntime/internal/atomic: set SP delta correctly for 64-bit atomic functions on ARM
Cherry Mui [Fri, 25 Feb 2022 04:31:53 +0000 (23:31 -0500)]
runtime/internal/atomic: set SP delta correctly for 64-bit atomic functions on ARM

64-bit atomic functions on ARM have the following structure:
- check if the address is 64-bit aligned, if not, prepare a frame
  and call panicUnaligned
- tail call armXXX or goXXX depending on GOARM

The alignment check calls panicUnaligned after preparing a frame,
so the stack can be unwound. The call never returns, so the SP is
not set back. However, the assembler assigns SP delta following
the instruction stream order, not the control flow. So it leaves
a nonzero SP delta after the check, to the tail call instructions,
which is wrong because when they are executed the SP is not
decremented. This CL fixes this by adding the SP back (the
instruction never executes, just tells the assembler to set the
SP delta back).

Should fix #51353.

Change-Id: I976cb1cfb0e9008b13538765cbc7eea0c19c7130
Reviewed-on: https://go-review.googlesource.com/c/go/+/388014
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
3 years agogo/types, types2: delay receiver type validation
Robert Griesemer [Thu, 24 Feb 2022 21:35:16 +0000 (13:35 -0800)]
go/types, types2: delay receiver type validation

Delay validation of receiver type as it may cause premature expansion
of types the receiver type is dependent on. This was actually a TODO.

While the diff looks large-ish, the actual change is small: all the
receiver validation code has been moved inside the delayed function
body, and a couple of comments have been adjusted.

Fixes #51232.
Fixes #51233.

Change-Id: I44edf0ba615996266791724b832d81b9ccb8b435
Reviewed-on: https://go-review.googlesource.com/c/go/+/387918
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agodoc/go1.18: note changes to automatic go.mod and go.sum updates
Bryan C. Mills [Thu, 24 Feb 2022 22:01:14 +0000 (17:01 -0500)]
doc/go1.18: note changes to automatic go.mod and go.sum updates

Fixes #51242
Updates #45551

Change-Id: Iba6e6acd9a94d24e26fcdd125f1022430723ada7
Reviewed-on: https://go-review.googlesource.com/c/go/+/387920
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Bryan Mills <bcmills@google.com>

3 years agodoc/go1.18: document minimum Linux kernel version
Tobias Klauser [Thu, 24 Feb 2022 09:19:54 +0000 (10:19 +0100)]
doc/go1.18: document minimum Linux kernel version

For #45964

Change-Id: Ic66502c50ca328e944c91e710dca6c8dbc168e4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/387855
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>