]> Cypherpunks repositories - gostls13.git/log
gostls13.git
3 years agocmd/compile: update the export version for generics
Dan Scales [Tue, 19 Oct 2021 20:28:54 +0000 (13:28 -0700)]
cmd/compile:  update the export version for generics

Bump the export version to a new value iexportVersionGo1_18 (2). This
will give a better error message when old compilers/tools encounter the
new export format (that includes parameterized types and functions).

We are also making a breaking change in the format:
 - a 'kind' byte is added to constant values

Also updated tinter() to pass the implicit bit through during type
substitution.

Tested that all tests still pass if the iexportVersionCurrent is changed
back to 1 in typecheck/iexport.go, iimporter/iimport.go, and
gcimporter/iimport.go

Updates #47654

Change-Id: I1dbeb167a97f6c7e0b7e0c011d6bada5db312b36
Reviewed-on: https://go-review.googlesource.com/c/go/+/357049
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Dan Scales <danscales@google.com>

3 years agocmd/compile: add -asan option
fanzha02 [Mon, 4 Jan 2021 09:14:35 +0000 (17:14 +0800)]
cmd/compile: add -asan option

The -asan option causes the compiler to add instrumentation for the
C/C++ address sanitizer.  Every memory read/write will be replaced
by a call to asanread/asanwrite.

This CL also inserts asan instrumentation during SSA building.

This CL passes tests but is not usable by itself. The actual
implementation of asanread/asanwrite in the runtime package, and
support for -asan in the go tool and tests, will follow in subsequent
CLs.

Updates #44853.

Change-Id: Ia18c9c5d5c351857420d2f6835f0daec2ad31096
Reviewed-on: https://go-review.googlesource.com/c/go/+/298611
Trust: fannie zhang <Fannie.Zhang@arm.com>
Run-TryBot: fannie zhang <Fannie.Zhang@arm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agointernal/poll: avoid tiny allocator for splicePipe
Ian Lance Taylor [Fri, 22 Oct 2021 21:19:34 +0000 (14:19 -0700)]
internal/poll: avoid tiny allocator for splicePipe

We want to set a finalizer on splicePipe, so make it large enough to
not use the tiny allocator. Otherwise the finalizer will not run until
the rest of the tiny allocation can be freed. This only matters on
32-bit systems.

Fixes #48968

Change-Id: I8eb3c9f48fdccab7dc79c5b918d4257b6151ee91
Reviewed-on: https://go-review.googlesource.com/c/go/+/358114
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
3 years agocmd/compile: fix typo in comment in CL 358435
Cherry Mui [Mon, 25 Oct 2021 20:48:07 +0000 (16:48 -0400)]
cmd/compile: fix typo in comment in CL 358435

Change-Id: I0d8128668fc7a80b29aabc58dbc9a2929b889ec9
Reviewed-on: https://go-review.googlesource.com/c/go/+/358614
Trust: Cherry Mui <cherryyz@google.com>
Trust: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
3 years agocmd/link: escape % characters in symbols when reporting errors
Keith Randall [Fri, 22 Oct 2021 01:28:50 +0000 (18:28 -0700)]
cmd/link: escape % characters in symbols when reporting errors

Generic function symbols sometimes have % in them, like:

    main.B2[%2eshape.string_0].m2·f

Which confuses this code because it doesn't esacpe % when
using this string as a format string, instead of a format argument.

Or could we get rid of the . -> %2e rewrite somehow?
I think it comes from LinkString.

Change-Id: I3275501f44cf30485e9d4577e0dfa77996d4939e
Reviewed-on: https://go-review.googlesource.com/c/go/+/357837
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
3 years agocmd/compile: revert most of CL 349169
Keith Randall [Fri, 22 Oct 2021 01:09:07 +0000 (18:09 -0700)]
cmd/compile: revert most of CL 349169

The method of using references to dictionaries to hold methods
live during linker deadcode elimination wasn't working very well.
I implemented a new scheme in the CL below this, so this CL strips
out the old method.

The new method has the added benefit of having 0 runtime overhead
(unlike the stuff we're ripping out here, which does have a small overhead).

Update #48047

Change-Id: I68ac57119792d53c58f1480f407de6ab2bb53211
Reviewed-on: https://go-review.googlesource.com/c/go/+/357836
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
3 years agocmd/compile: remove MarkUsedIfaceMethodIndex mechanism
Keith Randall [Fri, 22 Oct 2021 02:15:24 +0000 (19:15 -0700)]
cmd/compile: remove MarkUsedIfaceMethodIndex mechanism

We don't need it any more, after CL 357835.

Change-Id: I1ff5f24b5540c3e80c4b35be8215a1c378952274
Reviewed-on: https://go-review.googlesource.com/c/go/+/357894
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
3 years agocmd/compile,cmd/link: introduce generic interface call relocations
Keith Randall [Fri, 22 Oct 2021 01:04:55 +0000 (18:04 -0700)]
cmd/compile,cmd/link: introduce generic interface call relocations

To capture the fact that a method was called on a generic interface,
so we can make sure the linker doesn't throw away any implementations
that might be the method called.

See the comment in reflect.go for details.

Fixes #49049

Change-Id: I0be74b6e727c1ecefedae072b149f59d539dc1e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/357835
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years agocmd/link: increase reserved space for passing env on wasm
Richard Musiol [Sun, 24 Oct 2021 10:28:18 +0000 (12:28 +0200)]
cmd/link: increase reserved space for passing env on wasm

On wasm, the wasm_exec.js helper passes the command line arguments and
environment variables via a reserved space in the wasm linear memory.
Increase this reserved space from 4096 to 8192 bytes so more environment
variables can fit into the limit.

Later, after https://golang.org/cl/350737 landed, we can switch to the
WASI interface for getting the arguments and environment. This would
remove the limit entirely.

Fixes #49011

Change-Id: I48a6e952a97d33404ed692c98e9b49c5cd6b269b
Reviewed-on: https://go-review.googlesource.com/c/go/+/358194
Trust: Richard Musiol <neelance@gmail.com>
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
3 years agocmd/go/testdata/script: fix flaky test_fuzz_fuzztime test
Katie Hockman [Fri, 22 Oct 2021 15:56:23 +0000 (11:56 -0400)]
cmd/go/testdata/script: fix flaky test_fuzz_fuzztime test

Previously, the test would panic if the short timeout
was reached before fuzzing began. Increasing the
timeout should stop this test from being flaky.

Fixes #49046

Change-Id: Iaa0b3b3e8ea29d9a42ab5fc1c801fc73fffe1675
Reviewed-on: https://go-review.googlesource.com/c/go/+/358055
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
3 years agocrypto/tls: add Conn.NetConn method
Agniva De Sarker [Sat, 5 Jun 2021 05:34:37 +0000 (11:04 +0530)]
crypto/tls: add Conn.NetConn method

NetConn method gives us access to the underlying net.Conn
value.

Fixes #29257

Change-Id: I68b2a92ed9dab4be9900807c94184f8c0aeb4f72
Reviewed-on: https://go-review.googlesource.com/c/go/+/325250
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Trust: Agniva De Sarker <agniva.quicksilver@gmail.com>
Trust: Katie Hockman <katie@golang.org>

3 years agocmd/compile: don't clobber LR for tail calls
Cherry Mui [Mon, 25 Oct 2021 15:51:25 +0000 (11:51 -0400)]
cmd/compile: don't clobber LR for tail calls

When doing a tail call the link register is live as the callee
will directly return to the caller (of the function that does the
tail call). Don't allocate or clobber the link register.

Fixes #49032.

Change-Id: I2d60f2354e5b6c14aa285c8983a9786687b90223
Reviewed-on: https://go-review.googlesource.com/c/go/+/358435
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agocmd/compile: use SetInit instead of *PtrInit
wdvxdr [Mon, 25 Oct 2021 10:15:43 +0000 (18:15 +0800)]
cmd/compile: use SetInit instead of *PtrInit

Change-Id: Ie802ff27b611ed248d7b14f6e972e6300c181f43
Reviewed-on: https://go-review.googlesource.com/c/go/+/358316
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
3 years agocmd/compile/internal/typecheck: record whether an interface is implicit
Robert Findley [Tue, 19 Oct 2021 22:40:27 +0000 (18:40 -0400)]
cmd/compile/internal/typecheck: record whether an interface is implicit

In preparation for capturing the implicit interface bit in export data,
thread through the IsImplicit property from types2 into typecheck.

Change-Id: I9b46fe73de102935a127e6ececaacd76738b557e
Reviewed-on: https://go-review.googlesource.com/c/go/+/357109
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years agogo/types: remove subscripts from type parameter names
Robert Findley [Thu, 21 Oct 2021 22:36:14 +0000 (18:36 -0400)]
go/types: remove subscripts from type parameter names

Now that we've removed the necessity for subscripts in importers, we can
effectively eliminate them from the the type parameter API by removing
them from the type string.

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

3 years agonet/http: correct Content-Length parsing for js/wasm
Charlotte Brandhorst-Satzkorn [Sat, 23 Oct 2021 02:46:46 +0000 (22:46 -0400)]
net/http: correct Content-Length parsing for js/wasm

The Content-Length was incorrectly set to 0 for ill-formed and invalid
values. In these cases, return an error.

If the Content-Length header was omitted, it was incorrectly set to 0.
In this case, set the Content-Length value to -1.

Fixes #49108

Change-Id: I24fe9a31ed5b6ddb53f2b2bd10f2c84e428823e3
Reviewed-on: https://go-review.googlesource.com/c/go/+/358134
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Trust: David Crawshaw <crawshaw@golang.org>

3 years agocmd/compile: fix inlining labeled switch statements
wdvxdr [Mon, 25 Oct 2021 09:54:11 +0000 (17:54 +0800)]
cmd/compile: fix inlining labeled switch statements

CL 357649 fixes inlining labeled FOR/RANGE loops,
we should do same translation for inlined SWITCH's label

Fixes #49145

Change-Id: I9a6f365f57e974271a1eb279b38e81f9b5148788
Reviewed-on: https://go-review.googlesource.com/c/go/+/358315
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
3 years agotesting: skip extra -count iterations if there are no tests
Michael Pratt [Mon, 18 Oct 2021 22:34:24 +0000 (18:34 -0400)]
testing: skip extra -count iterations if there are no tests

When running benchmarks with high -count and no tests (either at all or
filtered with -run), the time for runTests to check for tests -count
times can add a significant delay to starting benchmarks.

To avoid this delay, make runTests bail out on the second iteration if
the first found no tests to run. We expect the same tests to run every
time, so there is no reason to duplicate work.

One caveat: the testing docs do not explicitly require the same subtests
to be run on every call, so this could break tests that depend on
multiple runs to actually run all tests. I consider such tests invalid,
but some may exist.

Fixes #49050

Change-Id: I7b34f3832b31493cc089ee0555e231f4dc690154
Reviewed-on: https://go-review.googlesource.com/c/go/+/356669
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agocmd/compile/internal/types2: better error messages for empty type sets
Robert Griesemer [Sat, 23 Oct 2021 23:39:32 +0000 (16:39 -0700)]
cmd/compile/internal/types2: better error messages for empty type sets

- change _TypeSet.hasTerms() to report if a type set has actual types
  (excluding a "universe" term)
- handle empty type set type arguments correctly
- bring comments up-to-date in Checker.satisfies

Change-Id: I87f9a1096ebb21a1b08c87a9b59f400f3bc2f040
Reviewed-on: https://go-review.googlesource.com/c/go/+/358175
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agotesting: reference benchmark format spec
Austin Clements [Thu, 21 Oct 2021 15:11:13 +0000 (11:11 -0400)]
testing: reference benchmark format spec

This updates the testing package documentation to reference the
specification for the benchmark format, and points users to our
standard tools for working with benchmark data. (It's somewhat
remarkable how widely used benchstat appears to be given that we don't
mention it anywhere!)

Change-Id: Idbb4416d2fde9606ea7e6c15595f3b9e6a38f3b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/357589
Trust: Austin Clements <austin@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agoimage/draw: improve performances if mask is *image.Alpha
Olivier Wulveryck [Mon, 31 May 2021 06:03:57 +0000 (08:03 +0200)]
image/draw: improve performances if mask is *image.Alpha

The existing DrawMask method is generic and is therefore calling the At().RGBA() method for every pixel of the mask and the source.
Do a specific implementation when the mask is *image.Alpha (which is
common) and use use the PixOffset method to increase performances.

name                old time/op  new time/op  delta
RGBA2-12            1.60ms ± 0%  1.13ms ± 1%  -29.16%  (p=0.008 n=5+5)
GenericMaskOver-12   915µs ± 4%   926µs ± 1%     ~     (p=0.190 n=5+4)
RGBA64Over-12       1.53ms ± 3%  1.21ms ± 2%  -20.74%  (p=0.008 n=5+5)
GrayOver-12         1.36ms ± 2%  1.01ms ± 7%  -26.27%  (p=0.008 n=5+5)

Fixes: #46395
Change-Id: Iaeaa8cfcc6a3fe93eb19b361f3bf076e41cac5b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/323749
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Trust: Nigel Tao <nigeltao@golang.org>
Trust: Andrew Gerrand <adg@golang.org>
Run-TryBot: Nigel Tao <nigeltao@golang.org>

3 years agocmd/compile: factor out code to remove phi argument
Cuong Manh Le [Sun, 24 Oct 2021 06:46:54 +0000 (13:46 +0700)]
cmd/compile: factor out code to remove phi argument

CL 358117 fixed a bug that Phi's argument wasn't updated correctly after
removing a predecessor of Block. This CL factor out the code that
updates phi argument into a Block's method, so it's easier to use,
maintain and hopefully prevent that kind of bug in the future.

Change-Id: Ie9741e19ea28f56860425089b6093a381aa10f5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/357964
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
3 years agocmd/compile: remove Value.RemoveArg
Cuong Manh Le [Sun, 24 Oct 2021 18:02:12 +0000 (01:02 +0700)]
cmd/compile: remove Value.RemoveArg

It's only used in two places:

 - The one in regalloc.go can be replaced with v.resetArgs()
 - The one in rewrite.go can be open coded

and can cause wrong usage like the bug that CL 358117 fixed.

Change-Id: I125baf237db159d056fe4b1c73072331eea4d06a
Reviewed-on: https://go-review.googlesource.com/c/go/+/357965
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
3 years agocmd/compile: fix fuse pass to do CFG surgery correctly
Keith Randall [Sat, 23 Oct 2021 17:16:41 +0000 (10:16 -0700)]
cmd/compile: fix fuse pass to do CFG surgery correctly

removePred and removeArg do different things. removePred moves the last
predecessor to index k, whereas removeArg slides all the args k or
greater down by 1 index.

Kind of unfortunate different behavior in things named similarly.

Fixes #49122

Change-Id: I9ae409bdac744e713f4c121f948e43db6fdc8542
Reviewed-on: https://go-review.googlesource.com/c/go/+/358117
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years agocmd/compile/internal/types2: comp literals to accept type sets with single underlying...
Robert Griesemer [Fri, 22 Oct 2021 03:01:51 +0000 (20:01 -0700)]
cmd/compile/internal/types2: comp literals to accept type sets with single underlying types

Change-Id: Ib51bcdf023910d244739ec176880a16e700851e7
Reviewed-on: https://go-review.googlesource.com/c/go/+/357915
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile/internal/types2: slice exprs to accept type sets with single underlying...
Robert Griesemer [Thu, 21 Oct 2021 23:17:07 +0000 (16:17 -0700)]
cmd/compile/internal/types2: slice exprs to accept type sets with single underlying types

Change-Id: Ib9bd08ab6153129aaf8b77b41fc6ea302d0c1589
Reviewed-on: https://go-review.googlesource.com/c/go/+/357779
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile/internal/types2: range clause to accept type sets with single underlying...
Robert Griesemer [Thu, 21 Oct 2021 22:56:08 +0000 (15:56 -0700)]
cmd/compile/internal/types2: range clause to accept type sets with single underlying types

This generalizes range clauses. Removed some dead code and cleaned
up the surrounding bits.

Change-Id: Icd8384205afa3f52b7e7df9abed5de2bb556861d
Reviewed-on: https://go-review.googlesource.com/c/go/+/357778
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile/internal/types2: make built-in to accept type sets with single underlying...
Robert Griesemer [Thu, 21 Oct 2021 20:29:00 +0000 (13:29 -0700)]
cmd/compile/internal/types2: make built-in to accept type sets with single underlying types

This generalizes make the same way copy was generalized and eliminates
a use of optype.

Change-Id: I8221abd53d77dde8ead47c0075c13fd2a3221642
Reviewed-on: https://go-review.googlesource.com/c/go/+/357776
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile/internal/types2: factor out slice elem computation for copy built-in
Robert Griesemer [Wed, 20 Oct 2021 22:06:35 +0000 (15:06 -0700)]
cmd/compile/internal/types2: factor out slice elem computation for copy built-in

Implement singleUnder[String] which determines a single underlying type
for a given type: either the underlying type, or the single underlying
type for a type parameter, if it exists. Use singleUnder[String] instead
of optype for copy built-in.

This CL removes a dependency on optype and also makes the copy built-in
slighty more general for generic arguments (the source argument may be
constrained by a slice or string simultaneously).

Change-Id: Ia329e96afc69a09d2ca3b1f82fe712d4f7ba1d9f
Reviewed-on: https://go-review.googlesource.com/c/go/+/357413
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/go: update test script for reformatted error message (fix long builds)
Robert Griesemer [Fri, 22 Oct 2021 23:57:58 +0000 (16:57 -0700)]
cmd/go: update test script for reformatted error message (fix long builds)

TBR=iant

Change-Id: Ic72af52e5ff8d28f8102c07b03e4930df61445ca
Reviewed-on: https://go-review.googlesource.com/c/go/+/358115
Trust: Robert Griesemer <gri@golang.org>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile: prevent compiling closures more than once
Cuong Manh Le [Fri, 22 Oct 2021 10:05:35 +0000 (17:05 +0700)]
cmd/compile: prevent compiling closures more than once

Since CL 282892, functions are always compiled before closures. To do
that, when walking the closure, it is added to its outer function queue
for scheduling compilation later. Thus, a closure may be added to queue
more than once, causing the ICE dues to being compiled twice.

To fix this, catching the re-walking of the closure expression and do
not add it to the compilation queue.

Fixes #49029

Change-Id: I7d188e8f5b4d5c4248a0d8e6389da26f1084e464
Reviewed-on: https://go-review.googlesource.com/c/go/+/357960
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
3 years agodoc: document new reflect.UnsafePointer function
Cuong Manh Le [Mon, 18 Oct 2021 16:54:02 +0000 (23:54 +0700)]
doc: document new reflect.UnsafePointer function

Updates #40592

Change-Id: If66629e47ca9859128ee3ad8fb584e022d7a6982
Reviewed-on: https://go-review.googlesource.com/c/go/+/356255
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agocmd/link: add -asan option
fanzha02 [Mon, 4 Jan 2021 08:23:01 +0000 (16:23 +0800)]
cmd/link: add -asan option

The -asan option causes the linker to link against the runtime/asan
package in order to use the C/C++ address sanitizer.

This CL passes tests but is not usable by itself.  The actual
runtime/asan package, and support for -asan in the go tool and the
compiler, and tests, are in separate CLs.

Updates #44853.

Change-Id: Ifc6046c1f75ba52777cbb3d937a4b66e91d5798d
Reviewed-on: https://go-review.googlesource.com/c/go/+/298610
Trust: fannie zhang <Fannie.Zhang@arm.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agocmd/compile/internal/types2: more detailed error messages for generic conversions
Robert Griesemer [Wed, 20 Oct 2021 01:09:30 +0000 (18:09 -0700)]
cmd/compile/internal/types2: more detailed error messages for generic conversions

- slightly refactor convertibleTo and convertibleToImpl
- provide ability to return a conversion failure cause
- add detailed cause for generic conversions

For #47150.

Change-Id: Ie97d89be0234414ef4df22a6920e18acc944a102
Reviewed-on: https://go-review.googlesource.com/c/go/+/357249
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile/internal/types2: reduce output when describing type parameters
Robert Griesemer [Wed, 20 Oct 2021 20:12:43 +0000 (13:12 -0700)]
cmd/compile/internal/types2: reduce output when describing type parameters

There's no need to say "type parameter" for a type parameter. The
name is sufficient (they are always named), and the prose is followed
by "constrained by".

Change-Id: I98df8caa1432b8b7a874e58da6e3ed6be102b4a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/357410
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agointernal/poll: fix a few function names on comments
Andy Pan [Fri, 22 Oct 2021 07:29:41 +0000 (15:29 +0800)]
internal/poll: fix a few function names on comments

Change-Id: I5b1dfeeb0ae5ac32667633151ef83bcf4654c43f
Reviewed-on: https://go-review.googlesource.com/c/go/+/357957
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agocmd/compile: only look for struct type when crawling inline body
Cuong Manh Le [Thu, 21 Oct 2021 07:31:40 +0000 (14:31 +0700)]
cmd/compile: only look for struct type when crawling inline body

CL 356254 fixed crawling of embeddable types during inline. However, we
are too agressive, since when we call markEmbed for every type seen
during inlining function body. That leads to false positive that for a
non-embedded type, its unexported methods are also marked inline.

Instead, we should only look at struct type that we seen during inlining
function body, and calling markEmbed for all of its embedded fields.

Fixes #49094

Change-Id: I6ef9a8bf1fc649ec6bf75e4883f6031ec8560ba1
Reviewed-on: https://go-review.googlesource.com/c/go/+/357232
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
3 years agoreflect: make Value.Pointer panic on bad notinheap pointers
Cuong Manh Le [Thu, 21 Oct 2021 16:35:05 +0000 (23:35 +0700)]
reflect: make Value.Pointer panic on bad notinheap pointers

Same as CL 350153 did for Value.Elem to panic on bad notinheap pointers.
While at it, also add more tests for notinheap deref.

Change-Id: Id7d9d12ad8467de5926b6a7e8f9d659fea5fedb5
Reviewed-on: https://go-review.googlesource.com/c/go/+/357630
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
3 years agogo/types, types2: add the Interface.MarkImplicit method
Robert Findley [Thu, 21 Oct 2021 22:59:10 +0000 (18:59 -0400)]
go/types, types2: add the Interface.MarkImplicit method

Add a new interface method, MarkImplicit, to allow marking interfaces as
implicit from outside the type-checker. This is necessary so that we can
capture the implicit bit in export data, and use it from importers.

For #48424
For #49040

Change-Id: I999aba2a298f92432326d7ccbd87fe133a2e1a72
Reviewed-on: https://go-review.googlesource.com/c/go/+/357796
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
3 years agocmd/internal/obj/ppc64: rework argument classifications
Paul E. Murphy [Mon, 9 Aug 2021 16:17:08 +0000 (11:17 -0500)]
cmd/internal/obj/ppc64: rework argument classifications

This introduces a number of new classifications which will make it
easier to generate functions to assemble the new instructions of
ISA 3.1, and potentially earlier versions.

No code generation changes should occur as a result of these. These
allow finer control over how an opcode is matched to an optab entry.

Literal values are now classified based on the smallest number of bits
needed to encode, and matching rules will accept a literal if it
can be zero/sign extended to fit a larger literal class.

Likewise, support classifying even register numbers for GPR, VSX, and
FPR instructions. Some instructions require and even/odd register pair,
and these are usually represented by specifying the even register, and
similarly encoded.

Likewise, add a unit test for the argument classifier function (aclass).
This caught an off-by-one bug in aclass which is also fixed.

Updates #44549

Change-Id: Ia03013aea8b56c4d59b7c3812cdd67ddb3b720b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/350152
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agocmd/compile: fix inlining of labeled for loops
Dan Scales [Wed, 20 Oct 2021 20:56:15 +0000 (13:56 -0700)]
cmd/compile: fix inlining of labeled for loops

There is already a mechanism using inlgen to rename labels insided
inlined functions so that they are unique and don't clash with loops in
the outer function. This is used for OLABEL and OGOTO. Now that we are
doing inlining of OFOR loops, we need to do this translation for OBREAK,
OCONTINUE, and OFOR. I also added the translation for ORANGE loops, in
anticipation of a CL that will allow inlining of ORANGE for loops.

Fixes #49100

Change-Id: I2ccddc3350370825c386965f4a1e4bc54d3c369b
Reviewed-on: https://go-review.googlesource.com/c/go/+/357649
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>

3 years agoruntime: detangle gcPaceScavenger from the pacer
Michael Anthony Knyszek [Thu, 8 Apr 2021 22:01:13 +0000 (22:01 +0000)]
runtime: detangle gcPaceScavenger from the pacer

Currently gcPaceScavenger is called by gcControllerState.commit, but it
manipulates global state which precludes testing. This change detangles
the two.

Change-Id: I10d8ebdf426d99ba49d2f2cb4fb64891e9fd6091
Reviewed-on: https://go-review.googlesource.com/c/go/+/309272
Reviewed-by: Michael Pratt <mpratt@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agoruntime: formalize and fix gcPercent synchronization
Michael Anthony Knyszek [Thu, 8 Apr 2021 21:07:02 +0000 (21:07 +0000)]
runtime: formalize and fix gcPercent synchronization

Currently gcController.gcPercent is read non-atomically by
gcControllerState.revise and gcTrigger.test, but these users may
execute concurrently with an update to gcPercent.

Although revise's results are best-effort, reading it directly in this
way is, generally speaking, unsafe.

This change makes gcPercent atomically updated for concurrent readers
and documents the complete synchronization semantics.

Because gcPercent otherwise only updated with the heap lock held or the
world stopped, all other reads can remain unsynchronized.

For #44167.

Change-Id: If09af103aae84a1e133e2d4fed8ab888d4b8f457
Reviewed-on: https://go-review.googlesource.com/c/go/+/308690
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
3 years agogo/types, types2: always return an underlying type from optype
Robert Findley [Thu, 21 Oct 2021 17:23:29 +0000 (13:23 -0400)]
go/types, types2: always return an underlying type from optype

Optype should never return a defined type.

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

3 years agonet/url: add testable examples for Values funcs
Amelia Downs [Mon, 18 Oct 2021 16:36:07 +0000 (12:36 -0400)]
net/url: add testable examples for Values funcs

Change-Id: Id71f3d8d7c1ef7910d5d9497167dc677f2f0a2ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/356535
Trust: Damien Neil <dneil@google.com>
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
3 years agonet/url: add testable examples for url pkg funcs
Amelia Downs [Mon, 18 Oct 2021 17:06:58 +0000 (13:06 -0400)]
net/url: add testable examples for url pkg funcs

Change-Id: I61011b75128478aa50308d84f4cba23b3e241b3f
Reviewed-on: https://go-review.googlesource.com/c/go/+/356536
Trust: Damien Neil <dneil@google.com>
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
3 years agoruntime: fix typo of pushBackAll
emahiro [Thu, 21 Oct 2021 15:34:33 +0000 (00:34 +0900)]
runtime: fix typo of pushBackAll

Fixes: #49081
Change-Id: Ie6742f1e7a60c2d92ce1283bcfaa3eac521440a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/357629
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Trust: Daniel Martí <mvdan@mvdan.cc>
Trust: Cherry Mui <cherryyz@google.com>

3 years agointernal/bytealg: fix Separator length check for Index/ppc64le
Archana R [Tue, 19 Oct 2021 09:11:46 +0000 (04:11 -0500)]
internal/bytealg: fix Separator length check for Index/ppc64le

Modified condition in the ASM implementation of indexbody to
determine if separator length crosses 16 bytes to BGT from BGE
to avoid incorrectly crossing a page.

Also fixed IndexString to invoke indexbodyp9 when on the POWER9
platform

Change-Id: I0602a797cc75287990eea1972e9e473744f6f5a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/356849
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Trust: Keith Randall <khr@golang.org>

3 years agocmd/compile/internal/ssa/gen: eliminate unnecessary neg and xori on PPC64
Lynn Boger [Thu, 14 Oct 2021 17:55:43 +0000 (12:55 -0500)]
cmd/compile/internal/ssa/gen: eliminate unnecessary neg and xori on PPC64

This adds a few rules to PPC64 to eliminate some instructions:
- when an isel is used to generate a boolean value based on a
condition and followed by an xori to flip the result, it can
instead flip the operands in the isel and avoid the xori.
= when a neg follows a sub the operands to the sub can be
swapped and the neg avoided.

There are several opportunities in reflect.DeepEqual to omit
xori which improves some of its benchmarks by as much as
5%

Change-Id: I81bbc02c0f16995c65934b6f045867b731ab302b
Reviewed-on: https://go-review.googlesource.com/c/go/+/357509
Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
3 years agotest/codegen: updated comparison test to verify on ppc64,ppc64le
Archana R [Wed, 20 Oct 2021 09:11:57 +0000 (04:11 -0500)]
test/codegen: updated comparison test to verify on ppc64,ppc64le

Updated test/codegen/comparison.go to verify memequal is inlined
as implemented in CL 328291.

Change-Id: If7824aed37ee1f8640e54fda0f9b7610582ba316
Reviewed-on: https://go-review.googlesource.com/c/go/+/357289
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
3 years agogo/types: print assignment operation for invalid operation errors
Cuong Manh Le [Wed, 20 Oct 2021 05:31:53 +0000 (12:31 +0700)]
go/types: print assignment operation for invalid operation errors

This is port of CL 357229 for types2 to go/types.

Change-Id: I35ed6b784969210a00ea5b36238df7d6b7fa18bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/357230
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile: use `else if` for mutually exclusive `if` statements
hkhere [Wed, 20 Oct 2021 17:26:41 +0000 (17:26 +0000)]
cmd/compile: use `else if` for mutually exclusive `if` statements

Change-Id: I43e5bb778fbba1398c8006b1644524a9885157db
GitHub-Last-Rev: fa76473ab8b207b8cfc350ca8a26de37dfe57f82
GitHub-Pull-Request: golang/go#47155
Reviewed-on: https://go-review.googlesource.com/c/go/+/334169
Trust: Keith Randall <khr@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
3 years agoruntime: retype mheap.reclaimCredit as atomic.Uintptr
Michael Anthony Knyszek [Mon, 18 Oct 2021 23:14:20 +0000 (23:14 +0000)]
runtime: retype mheap.reclaimCredit as atomic.Uintptr

[git-generate]
cd src/runtime
mv export_test.go export.go
GOROOT=$(dirname $(dirname $PWD)) rf '
  add mheap.reclaimCredit \
// reclaimCredit is spare credit for extra pages swept. Since \
// the page reclaimer works in large chunks, it may reclaim \
// more than requested. Any spare pages released go to this \
// credit pool. \
reclaimCredit_ atomic.Uintptr
  ex {
    import "runtime/internal/atomic"

    var t mheap
    var v, w uintptr
    var d uintptr

    t.reclaimCredit -> t.reclaimCredit_.Load()
    t.reclaimCredit = v -> t.reclaimCredit_.Store(v)
    atomic.Loaduintptr(&t.reclaimCredit) -> t.reclaimCredit_.Load()
    atomic.LoadAcquintptr(&t.reclaimCredit) -> t.reclaimCredit_.LoadAcquire()
    atomic.Storeuintptr(&t.reclaimCredit, v) -> t.reclaimCredit_.Store(v)
    atomic.StoreReluintptr(&t.reclaimCredit, v) -> t.reclaimCredit_.StoreRelease(v)
    atomic.Casuintptr(&t.reclaimCredit, v, w) -> t.reclaimCredit_.CompareAndSwap(v, w)
    atomic.Xchguintptr(&t.reclaimCredit, v) -> t.reclaimCredit_.Swap(v)
    atomic.Xadduintptr(&t.reclaimCredit, d) -> t.reclaimCredit_.Add(d)
  }
  rm mheap.reclaimCredit
  mv mheap.reclaimCredit_ mheap.reclaimCredit
'
mv export.go export_test.go

Change-Id: I2c567781a28f5d8c2275ff18f2cf605b82f22d09
Reviewed-on: https://go-review.googlesource.com/c/go/+/356712
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
3 years agoruntime: retype mheap.reclaimIndex as atomic.Uint64
Michael Anthony Knyszek [Mon, 18 Oct 2021 23:12:16 +0000 (23:12 +0000)]
runtime: retype mheap.reclaimIndex as atomic.Uint64

[git-generate]
cd src/runtime
mv export_test.go export.go
GOROOT=$(dirname $(dirname $PWD)) rf '
  add mheap.reclaimIndex \
// reclaimIndex is the page index in allArenas of next page to \
// reclaim. Specifically, it refers to page (i % \
// pagesPerArena) of arena allArenas[i / pagesPerArena]. \
// \
// If this is >= 1<<63, the page reclaimer is done scanning \
// the page marks. \
reclaimIndex_ atomic.Uint64
  ex {
    import "runtime/internal/atomic"

    var t mheap
    var v, w uint64
    var d int64

    t.reclaimIndex -> t.reclaimIndex_.Load()
    t.reclaimIndex = v -> t.reclaimIndex_.Store(v)
    atomic.Load64(&t.reclaimIndex) -> t.reclaimIndex_.Load()
    atomic.LoadAcq64(&t.reclaimIndex) -> t.reclaimIndex_.LoadAcquire()
    atomic.Store64(&t.reclaimIndex, v) -> t.reclaimIndex_.Store(v)
    atomic.StoreRel64(&t.reclaimIndex, v) -> t.reclaimIndex_.StoreRelease(v)
    atomic.Cas64(&t.reclaimIndex, v, w) -> t.reclaimIndex_.CompareAndSwap(v, w)
    atomic.Xchg64(&t.reclaimIndex, v) -> t.reclaimIndex_.Swap(v)
    atomic.Xadd64(&t.reclaimIndex, d) -> t.reclaimIndex_.Add(d)
  }
  rm mheap.reclaimIndex
  mv mheap.reclaimIndex_ mheap.reclaimIndex
'
mv export.go export_test.go

Change-Id: I1d619e3ac032285b5f7eb6c563a5188c8e36d089
Reviewed-on: https://go-review.googlesource.com/c/go/+/356711
Reviewed-by: Austin Clements <austin@google.com>
Trust: Michael Knyszek <mknyszek@google.com>

3 years agoruntime: retype mheap.pagesSweptBasis as atomic.Uint64
Michael Anthony Knyszek [Mon, 18 Oct 2021 23:10:43 +0000 (23:10 +0000)]
runtime: retype mheap.pagesSweptBasis as atomic.Uint64

[git-generate]
cd src/runtime
mv export_test.go export.go
GOROOT=$(dirname $(dirname $PWD)) rf '
  add mheap.pagesSweptBasis pagesSweptBasis_ atomic.Uint64 // pagesSwept to use as the origin of the sweep ratio
  ex {
    import "runtime/internal/atomic"

    var t mheap
    var v, w uint64
    var d int64

    t.pagesSweptBasis -> t.pagesSweptBasis_.Load()
    t.pagesSweptBasis = v -> t.pagesSweptBasis_.Store(v)
    atomic.Load64(&t.pagesSweptBasis) -> t.pagesSweptBasis_.Load()
    atomic.LoadAcq64(&t.pagesSweptBasis) -> t.pagesSweptBasis_.LoadAcquire()
    atomic.Store64(&t.pagesSweptBasis, v) -> t.pagesSweptBasis_.Store(v)
    atomic.StoreRel64(&t.pagesSweptBasis, v) -> t.pagesSweptBasis_.StoreRelease(v)
    atomic.Cas64(&t.pagesSweptBasis, v, w) -> t.pagesSweptBasis_.CompareAndSwap(v, w)
    atomic.Xchg64(&t.pagesSweptBasis, v) -> t.pagesSweptBasis_.Swap(v)
    atomic.Xadd64(&t.pagesSweptBasis, d) -> t.pagesSweptBasis_.Add(d)
  }
  rm mheap.pagesSweptBasis
  mv mheap.pagesSweptBasis_ mheap.pagesSweptBasis
'
mv export.go export_test.go

Change-Id: Id9438184b9bd06d96894c02376385bad45dee154
Reviewed-on: https://go-review.googlesource.com/c/go/+/356710
Reviewed-by: Austin Clements <austin@google.com>
Trust: Michael Knyszek <mknyszek@google.com>

3 years agoruntime: retype mheap.pagesSwept as atomic.Uint64
Michael Anthony Knyszek [Mon, 18 Oct 2021 23:07:59 +0000 (23:07 +0000)]
runtime: retype mheap.pagesSwept as atomic.Uint64

[git-generate]
cd src/runtime
mv export_test.go export.go
GOROOT=$(dirname $(dirname $PWD)) rf '
  add mheap.pagesSwept pagesSwept_ atomic.Uint64 // pages swept this cycle
  ex {
    import "runtime/internal/atomic"

    var t mheap
    var v, w uint64
    var d int64

    t.pagesSwept -> t.pagesSwept_.Load()
    t.pagesSwept = v -> t.pagesSwept_.Store(v)
    atomic.Load64(&t.pagesSwept) -> t.pagesSwept_.Load()
    atomic.LoadAcq64(&t.pagesSwept) -> t.pagesSwept_.LoadAcquire()
    atomic.Store64(&t.pagesSwept, v) -> t.pagesSwept_.Store(v)
    atomic.StoreRel64(&t.pagesSwept, v) -> t.pagesSwept_.StoreRelease(v)
    atomic.Cas64(&t.pagesSwept, v, w) -> t.pagesSwept_.CompareAndSwap(v, w)
    atomic.Xchg64(&t.pagesSwept, v) -> t.pagesSwept_.Swap(v)
    atomic.Xadd64(&t.pagesSwept, d) -> t.pagesSwept_.Add(d)
  }
  rm mheap.pagesSwept
  mv mheap.pagesSwept_ mheap.pagesSwept
'
mv export.go export_test.go

Change-Id: Ife99893d90a339655f604bc3a64ee3decec645ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/356709
Trust: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Austin Clements <austin@google.com>
3 years agoruntime: retype mheap.pagesInUse as atomic.Uint64
Michael Anthony Knyszek [Fri, 15 Oct 2021 19:22:10 +0000 (19:22 +0000)]
runtime: retype mheap.pagesInUse as atomic.Uint64

[git-generate]
cd src/runtime
mv export_test.go export.go
GOROOT=$(dirname $(dirname $PWD)) rf '
  add mheap.pagesInUse \
// Proportional sweep \
// \
// These parameters represent a linear function from gcController.heapLive \
// to page sweep count. The proportional sweep system works to \
// stay in the black by keeping the current page sweep count \
// above this line at the current gcController.heapLive. \
// \
// The line has slope sweepPagesPerByte and passes through a \
// basis point at (sweepHeapLiveBasis, pagesSweptBasis). At \
// any given time, the system is at (gcController.heapLive, \
// pagesSwept) in this space. \
// \
// It is important that the line pass through a point we \
// control rather than simply starting at a 0,0 origin \
// because that lets us adjust sweep pacing at any time while \
// accounting for current progress. If we could only adjust \
// the slope, it would create a discontinuity in debt if any \
// progress has already been made. \
pagesInUse_ atomic.Uint64 // pages of spans in stats mSpanInUse
  ex {
    import "runtime/internal/atomic"

    var t mheap
    var v, w uint64
    var d int64

    t.pagesInUse -> t.pagesInUse_.Load()
    t.pagesInUse = v -> t.pagesInUse_.Store(v)
    atomic.Load64(&t.pagesInUse) -> t.pagesInUse_.Load()
    atomic.LoadAcq64(&t.pagesInUse) -> t.pagesInUse_.LoadAcquire()
    atomic.Store64(&t.pagesInUse, v) -> t.pagesInUse_.Store(v)
    atomic.StoreRel64(&t.pagesInUse, v) -> t.pagesInUse_.StoreRelease(v)
    atomic.Cas64(&t.pagesInUse, v, w) -> t.pagesInUse_.CompareAndSwap(v, w)
    atomic.Xchg64(&t.pagesInUse, v) -> t.pagesInUse_.Swap(v)
    atomic.Xadd64(&t.pagesInUse, d) -> t.pagesInUse_.Add(d)
  }
  rm mheap.pagesInUse
  mv mheap.pagesInUse_ mheap.pagesInUse
'
mv export.go export_test.go

Change-Id: I495d188683dba0778518563c46755b5ad43be298
Reviewed-on: https://go-review.googlesource.com/c/go/+/356549
Trust: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Austin Clements <austin@google.com>
3 years agoruntime: use atomic.Float64 for assist ratio
Michael Anthony Knyszek [Fri, 24 Sep 2021 16:06:07 +0000 (16:06 +0000)]
runtime: use atomic.Float64 for assist ratio

Change-Id: Ie7f09a7c9545ef9dd1860b1e332c4edbcbf8165e
Reviewed-on: https://go-review.googlesource.com/c/go/+/356170
Reviewed-by: Austin Clements <austin@google.com>
Trust: Michael Knyszek <mknyszek@google.com>

3 years agoruntime/internal/atomic: add atomic types for all functions
Michael Anthony Knyszek [Fri, 24 Sep 2021 16:01:03 +0000 (16:01 +0000)]
runtime/internal/atomic: add atomic types for all functions

Change-Id: I74f365316484feb819c31c77fbffd78fadfe32a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/356169
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
3 years agocmd/compile/internal/types2: use correct types when checking generic conversions
Robert Griesemer [Wed, 20 Oct 2021 19:18:40 +0000 (12:18 -0700)]
cmd/compile/internal/types2: use correct types when checking generic conversions

Iterate through the actual, possibly defined types of constraints
when type-checking generic conversions, not the underlying types.

For #47150.

Change-Id: Ia7af313bf46d6f6b0ad5292ff793b030b8e2d3d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/357333
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agogo/internal/gcimporter: avoid setting unnecessary lines in fakeFileSet
Robert Findley [Wed, 20 Oct 2021 18:54:13 +0000 (14:54 -0400)]
go/internal/gcimporter: avoid setting unnecessary lines in fakeFileSet

This is a clean port of CL 357291 from x/tools.

For #46586

Change-Id: Ib22087ae7fe8477d368acd230b263b83cdad4d36
Reviewed-on: https://go-review.googlesource.com/c/go/+/357429
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agocmd/compile: fix crawling of embeddable types during inline
Cuong Manh Le [Mon, 18 Oct 2021 07:31:48 +0000 (14:31 +0700)]
cmd/compile: fix crawling of embeddable types during inline

In CL 327872, there's a fix for crawling of embeddable types directly
reached by the user, so all of its methods need to be re-exported. But
we missed the cased when an un-exported type may be reachable by
embedding in exported type. Example:

type t struct {}
func (t) M() {}

func F() interface{} { return struct{ t }{} }

We generate the wrapper for "struct{ t }".M, and when inlining call to
"struct{ t }".M makes "t.M" reachable.

It works well, and only be revealed in CL 327871, when we changed
methodWrapper to always call inline.InlineCalls, thus causes the crash
in #49016, which involve dot type in inlined function.

Fixes #49016

Change-Id: If174fa5575132da5cf60e4bd052f7011c4e76c5d
Reviewed-on: https://go-review.googlesource.com/c/go/+/356254
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
3 years agocmd/internal/goobj: minor dead code cleanup
Than McIntosh [Wed, 20 Oct 2021 14:43:43 +0000 (10:43 -0400)]
cmd/internal/goobj: minor dead code cleanup

Remove a bit of dead code from the Go object file reader (io.ReaderAt
no longer needed in goobj.Reader).

Change-Id: I04150d37fb90b59c9dbe930878d4dd21cdcd7ca7
Reviewed-on: https://go-review.googlesource.com/c/go/+/357309
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agomath/big: remove stray whitespace in addMulVVW on amd64
andig [Wed, 20 Oct 2021 07:46:23 +0000 (07:46 +0000)]
math/big: remove stray whitespace in addMulVVW on amd64

Minor leftover from CL 74851.

Change-Id: I1b56afcde3c505ba77a0f79e8ae9b01000362298
GitHub-Last-Rev: 87e97571a58d5eadd63a28226543aaf1510a7b02
GitHub-Pull-Request: golang/go#48942
Reviewed-on: https://go-review.googlesource.com/c/go/+/355629
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Daniel Martí <mvdan@mvdan.cc>
Trust: Alexander Rakoczy <alex@golang.org>

3 years agonet/http/internal: return unexpected EOF on incomplete chunk read
Alexander Yastrebov [Sat, 16 Oct 2021 02:19:20 +0000 (02:19 +0000)]
net/http/internal: return unexpected EOF on incomplete chunk read

Fixes #48861

Change-Id: I3f55bfbdc4f2cf5b33d1ab2d76e01335bb497c6f
GitHub-Last-Rev: 0ecd790b87ddd31d0cf08e8f2726f918a2edd1fb
GitHub-Pull-Request: golang/go#48903
Reviewed-on: https://go-review.googlesource.com/c/go/+/355029
Trust: Damien Neil <dneil@google.com>
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
3 years agocmd/compile/internal/types2: print assignment operation for invalid operation errors
Cuong Manh Le [Wed, 20 Oct 2021 02:55:26 +0000 (09:55 +0700)]
cmd/compile/internal/types2: print assignment operation for invalid operation errors

When invoking check.binary for assignment operation, the expression will
be nil, thus for printing the assignment operation error message, we
need to reconstruct the statement from lhs, op, rhs.

Fixes #48472

Change-Id: Ie38c3dd8069b47e508968d6e43cedcf7536559ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/357229
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
3 years agocmd/compile/internal/types2: implement generic conversions
Robert Griesemer [Thu, 14 Oct 2021 17:04:10 +0000 (10:04 -0700)]
cmd/compile/internal/types2: implement generic conversions

Fixes #47150.

Change-Id: I7531ca5917d4e52ca0b9211d6f2114495b19ba09
Reviewed-on: https://go-review.googlesource.com/c/go/+/356010
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile: allow importing and exporting of ODYNAMICTYPE
Keith Randall [Mon, 18 Oct 2021 17:59:29 +0000 (10:59 -0700)]
cmd/compile: allow importing and exporting of ODYNAMICTYPE

Change-Id: I2fca7a801c85ed93c002c23bfcb0cf9593f1bdf4
Reviewed-on: https://go-review.googlesource.com/c/go/+/356571
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
3 years agocmd/compile: substitute "". prefix with package in more import locations
Keith Randall [Mon, 18 Oct 2021 19:19:07 +0000 (12:19 -0700)]
cmd/compile: substitute "". prefix with package in more import locations

The "" stand-in for the current package needs to be substituted
in more places when importing, because of generics.

""..dict.conv4["".MyString]

when imported in main and then exported, this becomes

a..dict.conv4["".MyString]

and then the linker makes that into

a..dict.conv4[main.MyString]

Which isn't correct. We need to replace on import not just
function names, but also globals, which this CL does.

Change-Id: Ia04a23b5ffd60aeeaba72c807f69261105670f8e
Reviewed-on: https://go-review.googlesource.com/c/go/+/356570
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
3 years agogo/types, types2: always accept type parameters when running Manual test
Robert Griesemer [Tue, 19 Oct 2021 20:44:01 +0000 (13:44 -0700)]
go/types, types2: always accept type parameters when running Manual test

This makes it easier to run tests on existing generic code that is
not using the `.go2` ending currently used by type checker tests.

For #49074.

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

3 years agoreflect: fix methodValueCall code pointer mismatch in Value.Pointer
Cuong Manh Le [Tue, 19 Oct 2021 17:16:23 +0000 (00:16 +0700)]
reflect: fix methodValueCall code pointer mismatch in Value.Pointer

This is the port of CL 356809 for Value.Pointer to fix the mismatch of
methodValueCall code pointer.

Change-Id: I080ac41b94b44d878cd5896207a76a28c57fd48b
Reviewed-on: https://go-review.googlesource.com/c/go/+/356950
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
3 years agoreflect: restore Value.Pointer implementation
Cuong Manh Le [Tue, 19 Oct 2021 17:09:09 +0000 (00:09 +0700)]
reflect: restore Value.Pointer implementation

CL 350691 added Value.UnsafePointer and make Value.Pointer call it
internally. It has a downside that Value.Pointer can now eligible to be
inlined, thus making un-intentional side effect, like the test in
fixedbugs/issue15329.go becomes flaky.

This CL restore Value.Pointer original implementation, pre CL 350691,
with the deprecation TODO removed.

Fixes #49067

Change-Id: I735af182f8e729294333ca906ffc062f477cfc99
Reviewed-on: https://go-review.googlesource.com/c/go/+/356949
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
3 years agocmd/go: add GOWORK to go env command
Michael Matloob [Fri, 17 Sep 2021 23:38:33 +0000 (19:38 -0400)]
cmd/go: add GOWORK to go env command

GOWORK will be set to the go.work file's path, if in workspace mode
or will be empty otherwise.

For #45713
Fixes #48589

Change-Id: I163ffaf274e0a41469c1f3b8514d6f90e20423b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/355689
Trust: Michael Matloob <matloob@golang.org>
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
3 years agocmd/go: support replaces in the go.work file
Michael Matloob [Fri, 17 Sep 2021 23:38:33 +0000 (19:38 -0400)]
cmd/go: support replaces in the go.work file

Add support for replace directives in the go.work file. If there are
conflicting replaces in go.mod files, suggest that users add an
overriding replace in the go.work file.

Add HighestReplaced to MainModules so that it accounts for the
replacements in the go.work file.

(Reviewers: I'm not totally sure that HighestReplace is computed
correctly. Could you take a closer look at that?)

For #45713

Change-Id: I1d789219ca1dd065ba009ce5d38db9a1fc38ba83
Reviewed-on: https://go-review.googlesource.com/c/go/+/352812
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
3 years agoerrors: mention Is methods should not call Unwrap
Matt T. Proud [Tue, 19 Oct 2021 08:09:06 +0000 (10:09 +0200)]
errors: mention Is methods should not call Unwrap

errors.Is internally unwraps the error until the error matches the
target. Because of this, a user-authored Is method on an error type
need not call errors.Unwrap on itself or the target, because that would
make the unwrapping operation O(N^2). It is a subtle detail to remind
authors for resource efficiency reasons.

Change-Id: Ic1ba59a5bdbfe2c7cb51a2cba2537ab6de4a13ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/356789
Reviewed-by: Jean de Klerk <deklerk@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Jean de Klerk <deklerk@google.com>
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Jean de Klerk <deklerk@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agointernal/bytealg: port bytes.Index and bytes.Count to reg ABI on ppc64x
Archana R [Wed, 13 Oct 2021 08:50:06 +0000 (03:50 -0500)]
internal/bytealg: port bytes.Index and bytes.Count to reg ABI on ppc64x

This change adds support for the reg ABI to the Index and Count
functions for ppc64/ppc64le.

Most Index and Count benchmarks show improvement in performance on
POWER9 with this change. Similar numbers observed on POWER8 and POWER10.

name                             old time/op    new time/op    delta
Index/32                         71.0ns ± 0%    67.9ns ± 0%   -4.42% (p=0.001 n=7+6)
IndexEasy/10                     17.5ns ± 0%    17.2ns ± 0%   -1.30% (p=0.001 n=7+7)

name             old time/op    new time/op    delta
Count/10           26.6ns ± 0%    25.0ns ± 1%   -6.02%  (p=0.001 n=7+7)
Count/32           78.6ns ± 0%    74.7ns ± 0%   -4.97%  (p=0.001 n=7+7)
Count/4K           5.03µs ± 0%    5.03µs ± 0%   -0.07%  (p=0.000 n=6+7)
CountEasy/10       26.9ns ± 0%    25.2ns ± 1%   -6.31%  (p=0.001 n=7+7)
CountSingle/32     11.8ns ± 0%     9.9ns ± 0%  -15.70%  (p=0.002 n=6+6)

Change-Id: Ibd146c04f8107291c55f9e6100b8264dfccc41ae
Reviewed-on: https://go-review.googlesource.com/c/go/+/355509
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agosync: avoid a dynamic check in WaitGroup on 64-bit architectures
Carlo Alberto Ferraris [Thu, 14 Oct 2021 07:50:41 +0000 (16:50 +0900)]
sync: avoid a dynamic check in WaitGroup on 64-bit architectures

uint64 is guaranteed by the compiler to be aligned on 64-bit archs.
By using uint64+uint32 instead of [3]uint32 we can make use of the
guaranteed alignment to avoid the run-time alignment check.

On linux/amd64:

name                     old time/op    new time/op    delta
WaitGroupUncontended-4     8.84ns ± 3%    7.62ns ± 4%  -13.72%  (p=0.000 n=17+18)
WaitGroupAddDone-4         66.8ns ± 3%    45.9ns ± 2%  -31.31%  (p=0.000 n=20+18)
WaitGroupAddDoneWork-4     79.2ns ± 1%    56.6ns ± 1%  -28.54%  (p=0.000 n=17+20)
WaitGroupWait-4            2.83ns ± 2%    2.58ns ± 2%   -9.05%  (p=0.000 n=18+20)
WaitGroupWaitWork-4        16.8ns ± 6%    16.5ns ± 6%     ~     (p=0.072 n=20+18)
WaitGroupActuallyWait-4     263ns ± 2%     261ns ± 5%     ~     (p=0.063 n=18+20)

Change-Id: I314340f2ed8a47d8b9c15f8a3b07e41f252f4831
Reviewed-on: https://go-review.googlesource.com/c/go/+/189837
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agotesting: don't allow f.Log/Logf or f.Skipped inside f.Fuzz
Katie Hockman [Fri, 15 Oct 2021 15:16:54 +0000 (11:16 -0400)]
testing: don't allow f.Log/Logf or f.Skipped inside f.Fuzz

This change also does some refactors around how
we prevent many (*F) methods from being called
inside (*F).Fuzz. Previously, there was a lot of
comment/code duplication, which was going to be
difficult to maintain and brittle. The refactor
lessens this duplication.

Previously, the methods Log, Logf, Failed, Name and
Skipped were the only (*common) methods that were
allowed to be called inside (*F).Fuzz. After this
change, Failed and Name are still allowed, but
Log, Logf, and Skipped are not (t.Log, t.Logf, or
t.Skipped should be used instead).

Fixes #48988

Change-Id: I4066247d551ea1908e8a2ca2889509fc68e3bb44
Reviewed-on: https://go-review.googlesource.com/c/go/+/356151
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
3 years agoruntime: remove reference to crypto/tls GODEBUG usage
Benjamin Peterson [Fri, 15 Oct 2021 23:24:28 +0000 (23:24 +0000)]
runtime: remove reference to crypto/tls GODEBUG usage

crypto/tls briefly used GODEBUG. That usage was removed in CL 191999.

Change-Id: I759b6f1b02db8160075cba30d73823018e19ad9d
GitHub-Last-Rev: 12d2a4a82b1467e4c2214aa78eb9a0af4938a9de
GitHub-Pull-Request: golang/go#49012
Reviewed-on: https://go-review.googlesource.com/c/go/+/356313
Reviewed-by: Austin Clements <austin@google.com>
Trust: Michael Pratt <mpratt@google.com>

3 years agocmd/compile/internal/types2: delay expansion of underlying in typeDecl
Robert Griesemer [Tue, 19 Oct 2021 00:42:21 +0000 (17:42 -0700)]
cmd/compile/internal/types2: delay expansion of underlying in typeDecl

This is a clean port of CL 356533 from go/types to types2.

Fixes #49043.

Change-Id: If389b94ece28042b0c8b436959dd21f26147a144
Reviewed-on: https://go-review.googlesource.com/c/go/+/356517
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile/internal/types2: ensure named types are expanded after type-checking
Robert Griesemer [Tue, 19 Oct 2021 00:31:23 +0000 (17:31 -0700)]
cmd/compile/internal/types2: ensure named types are expanded after type-checking

This is a clean port of CL 356490 from go/types to types2.

Fixes #48703.
Fixes #48974.

Change-Id: I08c0db0b92250cbb043325541b21a577726b40ca
Reviewed-on: https://go-review.googlesource.com/c/go/+/356515
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile/internal/types2: add support for inferring type instances
Robert Griesemer [Tue, 19 Oct 2021 00:17:08 +0000 (17:17 -0700)]
cmd/compile/internal/types2: add support for inferring type instances

This is an essentially clean port of CL 356489 from go/types to types2,
with minor adjustments due to the different AST packages and error
reporting.

Fixes #47990.

Change-Id: I52187872474bfc1fb49eb77905f22fc820b7295b
Reviewed-on: https://go-review.googlesource.com/c/go/+/356514
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
3 years agocmd/compile, types2: better error message for invalid type assertion
Robert Griesemer [Mon, 18 Oct 2021 21:56:08 +0000 (14:56 -0700)]
cmd/compile, types2: better error message for invalid type assertion

This CL addresses the 2nd part of the issue below.

- For types2, now use the same error messages as the compiler in this case.
- Make the mechanism for reporting clarifying error messages handle the case
  where we don't have additional position information.
- Provide context information (type assertion vs type switch).

Fixes #49005.

Change-Id: I4eeaf4f0c3f2f8735b63993778f58d713fef21ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/356512
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 agoreflect: fix methodValueCall code pointer mismatched
Cuong Manh Le [Tue, 19 Oct 2021 09:34:43 +0000 (16:34 +0700)]
reflect: fix methodValueCall code pointer mismatched

CL 322350 changed how to take address of assembly functions, using
abi.FuncPCABI0 intrinsic. But we forgot to update the code in
Value.UnsafePointer (was Value.Pointer) to reflect that change.

This CL fixes that bug, and also add a test to make sure the code
pointer is in sync.

Change-Id: I05ae7df31c706583a0f374d8af027066528f5ceb
Reviewed-on: https://go-review.googlesource.com/c/go/+/356809
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
3 years agocmd/compile: use MOVBE instruction for GOAMD64>=v3
wdvxdr [Tue, 19 Oct 2021 11:39:21 +0000 (19:39 +0800)]
cmd/compile: use MOVBE instruction for GOAMD64>=v3

In CL 354670, I copied some existing rules for convenience but forgot
to update the last rule which broke `GOAMD64=v3 ./make.bat`

Revive CL 354670

Change-Id: Ic1e2047c603f0122482a4b293ce1ef74d806c019
Reviewed-on: https://go-review.googlesource.com/c/go/+/356810
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agotesting: write output to buffer when fuzzing
Katie Hockman [Thu, 14 Oct 2021 16:32:58 +0000 (12:32 -0400)]
testing: write output to buffer when fuzzing

Fixes #48709

Change-Id: Ia6376a2f792946498d6565a53605b3e6c985ea7c
Reviewed-on: https://go-review.googlesource.com/c/go/+/355909
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
3 years agocmd/go: skip flaky fuzz tests
Bryan C. Mills [Mon, 18 Oct 2021 20:15:43 +0000 (16:15 -0400)]
cmd/go: skip flaky fuzz tests

(Temporarily, until they can be fixed.)

For #49046
For #49047

Change-Id: Ib580a5e45a0955aabdfc1899ed38a262a37f66ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/356649
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
3 years agocmd/internal/obj/riscv: fix trampoline calls from large functions
Joel Sing [Fri, 15 Oct 2021 16:59:41 +0000 (03:59 +1100)]
cmd/internal/obj/riscv: fix trampoline calls from large functions

On riscv64, the JAL instruction is only capable of reaching +/-1MB. In the case where
a single function and its trampolines exceeds this size, it is possible that the JAL
is unable to reach the trampoline, which is laid down after the function text. In the
case of large functions, switch back to using a AUIPC+JALR pairs rather than using
trampolines.

Fixes #48791

Change-Id: I119cf3bc20ce4933a9b7ab41a8e514437c6addb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/356250
Trust: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
3 years agoRevert "cmd/compile: use MOVBE instruction for GOAMD64>=v3"
Daniel Martí [Tue, 19 Oct 2021 09:09:55 +0000 (09:09 +0000)]
Revert "cmd/compile: use MOVBE instruction for GOAMD64>=v3"

This reverts CL 354670.

Reason for revert: broke make.bash with GOAMD64=v3.

Fixes #49061.

Change-Id: I7f2ed99b7c10100c4e0c1462ea91c4c9d8c609b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/356790
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Koichi Shiraishi <zchee.io@gmail.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years agoencoding/base64: add examples for Encode/Decode
180909 [Wed, 8 Sep 2021 16:32:03 +0000 (00:32 +0800)]
encoding/base64: add examples for Encode/Decode

Fixes #37595

Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
Reviewed-on: https://go-review.googlesource.com/c/go/+/348394
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Daniel Martí <mvdan@mvdan.cc>
Trust: Cherry Mui <cherryyz@google.com>

3 years agoruntime: ensure at least 1 tick between events
Meng Zhuo [Mon, 20 Sep 2021 12:44:50 +0000 (20:44 +0800)]
runtime: ensure at least 1 tick between events

ticks might be same after tick division, although the real cputicks
is linear growth

Fixes #46737

Change-Id: I1d98866fbf21b426c6c1c96cc9cf802d7f440f18
Reviewed-on: https://go-review.googlesource.com/c/go/+/330849
Trust: Meng Zhuo <mzh@golangcn.org>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agocmd/internal/obj/riscv: fix and enable test in short mode
Joel Sing [Fri, 8 Oct 2021 09:28:58 +0000 (20:28 +1100)]
cmd/internal/obj/riscv: fix and enable test in short mode

The branch test only takes a few seconds so enable it in short mode. Also fix a
typo that currently prevents the code from compiling.

Change-Id: I25fc646b002a66c042c61fb1f56d5efa8e47903c
Reviewed-on: https://go-review.googlesource.com/c/go/+/356249
Trust: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years agogo/types: delay expansion of underlying in typeDecl
Robert Findley [Sun, 17 Oct 2021 22:27:53 +0000 (18:27 -0400)]
go/types: delay expansion of underlying in typeDecl

Even after type-checking the RHS of a type declaration, we may not yet
be able to expand, if the RHS is itself an instance (see #49043).

We can instead rely on the mechanisms we have in place for delayed
expansion.

Fixes #49043

Change-Id: Ibffa4c1b1163c824b5c7e151aaac35f3e8c84ec7
Reviewed-on: https://go-review.googlesource.com/c/go/+/356533
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
3 years agogo/types: ensure named types are expanded after type-checking
Robert Findley [Fri, 15 Oct 2021 20:39:39 +0000 (16:39 -0400)]
go/types: ensure named types are expanded after type-checking

Rather than using Checker.later in newNamed, add a Checker.defTypes
field to track named types that have been created during type-checking,
and use this to expand named types as a final phase in type checking.

We have encountered several bugs related to infinite recursion while
expanding named types, because (I would argue) we have two conflicting
requirements in the type checker: ensuring that we eventually collapse
underlying chains, and yet allowing lazy substitution of the underlying
type in instances. The former is necessary for correctness, and to
ensure that we detect cycles during the type-checking pass. The latter
is necessary to allow infinitely expanding patterns of instances through
underlying or method definitions.

I believe this CL reconciles these conflicting requirements, by creating
a boundary between types that are encountered in the source during
type checking, and instances that are created by recursive evaluation.
At the end of the type checking pass, Checker.defTypes should contain
all possible origin types for instantiation. Once we compute the true
underlying for these origin types, any remaining instances that are
unresolved are guaranteed to have an origin with a valid underlying.
Therefore, we can return from the type-checking pass without calling
under() for these remaining instances.

Fixes #48703
Fixes #48974

Change-Id: I1474f514e2ab71c1ad4c3704fe32bfba11d59394
Reviewed-on: https://go-review.googlesource.com/c/go/+/356490
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
3 years agogo/types: add support for inferring type instances
Robert Findley [Fri, 15 Oct 2021 14:52:55 +0000 (10:52 -0400)]
go/types: add support for inferring type instances

Add constraint type inference for type instances, to be consistent with
inference of function values.

Fixes #47990

Change-Id: Ib99b5215cb2da5c10badc4de7e9e60ca0e48489f
Reviewed-on: https://go-review.googlesource.com/c/go/+/356489
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
3 years agonet/url: fix stale RFC 3986 links
jiahua wang [Sat, 16 Oct 2021 15:19:57 +0000 (23:19 +0800)]
net/url: fix stale RFC 3986 links

The URLs for RFC 3986 have been changed from:
  http://tools.ietf.org/html/rfc3986
to:
  https://datatracker.ietf.org/doc/html/rfc3986

Change-Id: I0662557d91bbb7de51d7ca4bc64e838741cd9074
Reviewed-on: https://go-review.googlesource.com/c/go/+/356429
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Cherry Mui <cherryyz@google.com>

3 years agobufio: use underlying ReadFrom even when data is buffered
Damien Neil [Fri, 6 Aug 2021 20:23:13 +0000 (13:23 -0700)]
bufio: use underlying ReadFrom even when data is buffered

When (*bufio.Writer).ReadFrom is called with a partially filled buffer,
fill out and flush the buffer and then call the underlying writer's
ReadFrom method if present.

Fixes #44815.

Change-Id: I15b3ef0746d0d60fd62041189a9b9df11254dd29
Reviewed-on: https://go-review.googlesource.com/c/go/+/340530
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
3 years agocmd/compile/internal/ssagen: set BitLen32 as intrinsic on PPC64
Lynn Boger [Thu, 14 Oct 2021 15:48:08 +0000 (10:48 -0500)]
cmd/compile/internal/ssagen: set BitLen32 as intrinsic on PPC64

It was noticed through some other investigation that BitLen32
was not generating the best code and found that it wasn't recognized
as an intrinsic. This corrects that and enables the test for PPC64.

Change-Id: Iab496a8830c8552f507b7292649b1b660f3848b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/355872
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
3 years agosyscall/js: remove Wrapper interface
Richard Musiol [Sat, 16 Oct 2021 15:17:21 +0000 (17:17 +0200)]
syscall/js: remove Wrapper interface

This change removes the js.Wrapper interface for performance reasons.
See proposal #44006 for details.

This is a breaking change, but syscall/js is exempt from Go's
compatibility promise.

Fixes #44006

Change-Id: I968cd14b1e61cc72ea9f84240b6bd29e8b8ae673
Reviewed-on: https://go-review.googlesource.com/c/go/+/356430
Trust: Richard Musiol <neelance@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
3 years agohtml/template: remove unused `mode` field on `Tree` struct
Gusted [Mon, 18 Oct 2021 17:38:22 +0000 (17:38 +0000)]
html/template: remove unused `mode` field on `Tree` struct

This changes Go, to remove this unused field on the `Tree` struct. Which seems to replaced by the non-private field `Mode`.

Change-Id: I5b384424cf60aa0af36eb8aad1d8db3f99b9838e
GitHub-Last-Rev: 4b033f967b55ff99df8a969ac1c91c358b82b726
GitHub-Pull-Request: golang/go#48028
Reviewed-on: https://go-review.googlesource.com/c/go/+/345789
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>