cmd/compile/internal/staticinit: fix panic in interface conversion
This patch fixes a panic from incorrect interface conversion from
*ir.BasicLit to *ir.ConstExpr. This only occurs when nounified
GOEXPERIMENT is set, so ideally it should be backported to Go
1.20 and removed from master.
Fixes #58339
Change-Id: I357069d7ee1707d5cc6811bd2fbdd7b0456323ae
GitHub-Last-Rev: 641dedb5f9f95e6f8d46723d445a8c9609719ce4
GitHub-Pull-Request: golang/go#58389
Reviewed-on: https://go-review.googlesource.com/c/go/+/466175 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com>
Cuong Manh Le [Sat, 4 Feb 2023 05:00:20 +0000 (12:00 +0700)]
cmd/compile: remove constant arithmetic overflows during typecheck
Since go1.19, these errors are already reported by types2 for any user's
Go code. Compiler generated code, which looks like constant expression
should be evaluated as non-constant semantic, which allows overflows.
Fixes #58293
Change-Id: I6f0049a69bdb0a8d0d7a0db49c7badaa92598ea2
Reviewed-on: https://go-review.googlesource.com/c/go/+/465096 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Bryan C. Mills [Wed, 8 Feb 2023 19:36:47 +0000 (14:36 -0500)]
cmd/go/internal/test: refresh flagdefs.go and fix test
The tests for cmd/go/internal/test were not running at all due to a
missed call to m.Run in TestMain. That masked two missing vet
analyzers ("directive" and "timeformat") and a missed update to the
generator script in CL 355452.
Jorropo [Tue, 31 Jan 2023 18:10:33 +0000 (19:10 +0100)]
cmd/compile: use MakeResult in empty MakeSlice elimination
This gets eliminated by thoses rules above:
// for rewriting results of some late-expanded rewrites (below)
(SelectN [0] (MakeResult x ___)) => x
(SelectN [1] (MakeResult x y ___)) => y
(SelectN [2] (MakeResult x y z ___)) => z
Fixes #58161
Change-Id: I4fbfd52c72c06b6b3db906bd9910b6dbb7fe8975
Reviewed-on: https://go-review.googlesource.com/c/go/+/463846 Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com>
Michael Pratt [Wed, 8 Feb 2023 18:48:17 +0000 (18:48 +0000)]
Revert "cmd/compile/internal/pgo: fix hard-coded PGO sample data position"
This reverts CL 465135.
Reason for revert: This broke cmd/go.TestScript/build_pgo on the linux-amd64-longtest builder: https://build.golang.org/log/8f8ed7bf576f891a06d295c4a5bca987c6e941d6
Change-Id: Ie2f2cc2731099eb28eda6b94dded4dfc34e29441
Reviewed-on: https://go-review.googlesource.com/c/go/+/466439
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Than McIntosh [Tue, 7 Feb 2023 16:11:45 +0000 (11:11 -0500)]
cmd/cover: add newline to fix -covermode=atomic build error
Fix a minor buglet in atomic mode fixup that would generate
non-compilable code for a package containing only the "package X"
clause with no trailing newline following the "X".
Fixes #58370.
Change-Id: I0d9bc4f2b687c6bd913595418f6db7dbe50cc5df
Reviewed-on: https://go-review.googlesource.com/c/go/+/466115 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Frederic Branczyk [Wed, 8 Feb 2023 17:59:27 +0000 (17:59 +0000)]
cmd/compile/internal/pgo: fix hard-coded PGO sample data position
This patch detects at which index position profiling samples that have the value-type samples count are, instead of the previously hard-coded position of index 1. Runtime generated profiles always generate CPU profiling data with the 0 index being CPU nanoseconds, and samples count at index 1, which is why this previously hasn't come up.
Fixes #58292
Change-Id: Idde761d53b02259f3076c4e5dcb4a96a9d53df0e
GitHub-Last-Rev: dabbf9f88c560286e150e9b136a27c3ac23c5ec1
GitHub-Pull-Request: golang/go#58294
Reviewed-on: https://go-review.googlesource.com/c/go/+/465135
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
Oleksandr Redko [Tue, 7 Feb 2023 09:09:24 +0000 (09:09 +0000)]
runtime: correct typos
- Fix typo in throw error message for arena.
- Correct typos in assembly and Go comments.
- Fix log message in TestTraceCPUProfile.
Change-Id: I874c9e8cd46394448b6717bc6021aa3ecf319d16
GitHub-Last-Rev: d27fad4d3cea81cc7a4ca6917985bcf5fa49b0e0
GitHub-Pull-Request: golang/go#58375
Reviewed-on: https://go-review.googlesource.com/c/go/+/465975 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Wayne Zuo [Mon, 6 Feb 2023 13:21:52 +0000 (21:21 +0800)]
cmd/compile: intrinsify math/bits/ReverseBytes{32|64} for 386
The BSWAPL instruction is supported in i486 and newer.
https://github.com/golang/go/wiki/MinimumRequirements#386 says we
support "All Pentium MMX or later". The Pentium is also referred to as
i586, so that we are safe with these instructions.
Change-Id: I6dea1f9d864a45bb07c8f8f35a81cfe16cca216c
Reviewed-on: https://go-review.googlesource.com/c/go/+/465515
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org> Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@google.com>
Cuong Manh Le [Sun, 5 Feb 2023 07:33:32 +0000 (14:33 +0700)]
cmd/compile: fix inline static init arguments substitued tree
Blank node must be ignored when building arguments substitued tree.
Otherwise, it could be used to replace other blank node in left hand
side of an assignment, causing an invalid IR node.
After staticAssignInlinedCall, the assignment becomes:
var _ = S1{s2: S2{}.Make()}
and the arg substitued tree is "map[*ir.Name]ir.Node{_: S1{}}". Now,
when doing static assignment, if there is any assignment to blank node,
for example:
_ := S2{}
That blank node will be replaced with "S1{}":
S1{} := S2{}
So constructing an invalid IR which causes the ICE.
Fixes #58325
Change-Id: I21b48357f669a7e02a7eb4325246aadc31f78fb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/465098
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com>
Ian Lance Taylor [Fri, 3 Feb 2023 06:13:18 +0000 (22:13 -0800)]
math/rand: use fastrand64 if possible
Now that the top-level math/rand functions are auto-seeded by default
(issue #54880), use the runtime fastrand64 function when 1) Seed
has not been called; 2) the GODEBUG randautoseed=0 is not used.
The benchmarks run quickly and are relatively noisy, but they show
significant improvements for parallel calls to the top-level functions.
Oleksandr Redko [Tue, 7 Feb 2023 08:21:05 +0000 (08:21 +0000)]
doc: fix spec typo
Change-Id: I5e3aca2b8fc78f38c9e2cdc67adf86d57ac85b1c
GitHub-Last-Rev: 0e5ddffe33f5677449d24e09bdb332e3d5c08aa3
GitHub-Pull-Request: golang/go#58353
Reviewed-on: https://go-review.googlesource.com/c/go/+/465615 Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
qmuntal [Tue, 7 Feb 2023 13:53:48 +0000 (14:53 +0100)]
runtime: use explicit NOFRAME on darwin/amd64
This CL marks some darwin assembly functions as NOFRAME to avoid relying
on the implicit amd64 NOFRAME heuristic, where NOSPLIT functions
without stack were also marked as NOFRAME.
This is a second attempt after CL 460235 was reverted.
Joe Tsai [Mon, 6 Feb 2023 22:48:19 +0000 (14:48 -0800)]
encoding/hex: fix Decode output check regression
CL 461958 fixed a potential panic,
but also introduced an observable regression where
invalid input could be detected before the panic occurs.
Adjust the check to preserve prior behavior,
while also preventing the panic.
Change-Id: I52819f88a6a64883fbc9fd512697c38c29ca0ccd
Reviewed-on: https://go-review.googlesource.com/c/go/+/465855
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com>
Roland Shoemaker [Tue, 31 Jan 2023 17:14:16 +0000 (09:14 -0800)]
crypto/ecdh: explicitly reject mismatched curves in ECDH
Return an explicit error when PrivateKey.ECDH is called with a PublicKey
which uses a different Curve. Also document this requirement, even
though it is perhaps obvious.
Than McIntosh [Wed, 25 Jan 2023 15:46:08 +0000 (10:46 -0500)]
cmd/link: linker portion of dead map removal
This patch contains the linker changes needed to enable deadcoding of
large unreferenced map variables, in combination with a previous
compiler change. We add a new cleanup function that runs just after
deadcode that looks for relocations in "init" funcs that are weak, of
type R_CALL (and siblings), and are targeting an unreachable function.
If we find such a relocation, after checking to make sure it targets a
map.init.XXX helper, we redirect the relocation to a point to a no-op
routine ("mapinitnoop") in the runtime.
The map init outlining is done selectively (only in the case where the
RHS code exceeds a size limit of 20 IR nodes).
In order to ensure that a given map.init.NNN function is included when
its corresponding map is live, we add dummy R_KEEP relocation from the
map variable to the map init function.
This first patch includes the main compiler compiler changes, and with
the weak relocation addition disabled. Subsequent patch includes the
requred linker changes along with switching to the call to the
outlined routine to a weak relocation. See the later linker change for
associated compile time performance numbers.
Updates #2559.
Updates #36021.
Updates #14840.
Change-Id: I1fd6fd6397772be1ebd3eb397caf68ae9a3147e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/461315
Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Unfortunately, this technique falls down when the first instruction
of the function is from an inlined callee. Then the expression above
gets you the name of the inlined function instead of the function itself.
To fix this, ensure that the first instruction is never from an inlinee.
Normally functions have prologs so those are already fine. In just the
cases where a function is a leaf with no local variables, and an instruction
from an inlinee appears first in the prog list, add a nop at the start
of the function to hold a non-inlined position.
Consider the nop a "mini-prolog" for leaf functions.
Fixes #58300
Change-Id: Ie37092f4ac3167fe8e5ef4a2207b14abc1786897
Reviewed-on: https://go-review.googlesource.com/c/go/+/465076
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: David Chase <drchase@google.com>
Than McIntosh [Thu, 26 Jan 2023 20:12:00 +0000 (15:12 -0500)]
cmd/internal/obj: flag init functions in object file
Introduce a flag in the object file indicating whether a given
function corresponds to a compiler-generated (not user-written) init
function, such as "os.init" or "syscall.init". Add code to the
compiler to fill in the correct value for the flag, and add support to
the loader package in the linker for testing the flag. The new loader
API is currently unused, but will be needed in the next CL in this
stack.
Updates #2559.
Updates #36021.
Updates #14840.
Change-Id: Iea7ad2adda487e4af7a44f062f9817977c53b394
Reviewed-on: https://go-review.googlesource.com/c/go/+/463855 Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Robert Griesemer [Thu, 2 Feb 2023 04:03:17 +0000 (20:03 -0800)]
go/types, types2: eliminate need to sort arguments for type inference
When unifying types, we always consider underlying types if inference
would fail otherwise. If a type parameter has a (non-defined) type
inferred and later matches against a defined type, make sure to keep
that defined type instead.
For #43056.
Change-Id: I24e4cd2939df7c8069e505be10914017c1c1c288
Reviewed-on: https://go-review.googlesource.com/c/go/+/464348 Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Joe Tsai [Sat, 4 Feb 2023 19:30:18 +0000 (11:30 -0800)]
log: fix and cleanup trailing newline logic
The intent was to always append a newline if a newline was missing.
The older logic accidentally only checked the payload for newlines
and forgot to check the prefix as well. Fix it to check both together.
This changes the output of Logger.Output in the situation where
the prefix contains a trailing newline and the output is empty.
This is a very rare combination and unlikely to occur in practice.
Change-Id: Ic04ded6c29a90383e29bf7f59223a808ee1cbdc0
Reviewed-on: https://go-review.googlesource.com/c/go/+/465316 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Johan Brandhorst-Satzkorn [Sat, 4 Feb 2023 05:14:05 +0000 (21:14 -0800)]
crypto/rand: replace shift with constant
It was mentioned after CL 463993 was merged that it
is uncommon to use shifts for numbers other than
powers of ten. Replace the shift with a base 10 constant.
Change-Id: I11c90128740109a59add40ed7b680f7bcc9715ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/465275
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Guoqi Chen [Thu, 4 Aug 2022 10:13:59 +0000 (18:13 +0800)]
cmd/asm: add RDTIME{L,H}.W, RDTIME.D support for loong64
Instruction formats: rdtime rd, rj
The RDTIME family of instructions are used to read constant frequency timer
information, the stable counter value is written into the general register
rd, and the counter id information is written into the general register rj.
(Note: both of its register operands are outputs).
Archana R [Fri, 11 Nov 2022 12:10:59 +0000 (06:10 -0600)]
cmd/compile: add rules to emit SETBC/R instructions on power10
This CL adds rules that replaces instances of ISEL that produce
a boolean result based on a condition register by SETBC/SETBCR
operations. On Power10 these are convereted to SETBC/SETBCR
instructions that use one register instead of 3 registers
conventionally used by ISEL and hence reduces register pressure.
On loops written specifically to exercise such instances of ISEL
extensively, a performance improvement of 2.5% is seen on Power10.
Also added verification tests to verify correct generation of
SETBC/SETBCR instructions on Power10.
weebney [Mon, 12 Dec 2022 19:10:54 +0000 (19:10 +0000)]
all: upgrade Unicode from 13.0.0 to 15.0.0
Update unicode/tables.go to reflect changes in the Unicode Standard up to
Unicode 15.0.0, released 13 Sept 2022.
In order to accommodate this update, strconv/isPrint has been updated to
reflect changes in printable characters.
Also changed is template/exec_test.go for both text and html packages- in
the test "TestJSEscaping", rune U+FDFF was used as a placeholder for an
unprintable character. This codepoint was assigned and made printable in
Unicode 14.0.0, breaking this test. It has been replaced with the assigned
and never-printable U+FFFE to fix the test and provide resiliency in the
future.
This upgrade bypasses Unicode 14.0.0, but is compatible.
Joe Tsai [Thu, 2 Feb 2023 02:18:57 +0000 (18:18 -0800)]
log: make use of fmt.Append functionality
Since log is already responsible for managing its own buffers
it is unfortunate that it calls fmt.Sprintf, which allocates,
only to append that intermediate string to another buffer.
Instead, use the new fmt.Append variants and avoid the allocation.
We modify Logger.Output to wrap an internal Logger.output,
which can be configured to use a particular append function.
Logger.output is called from all the other functionality instead.
This has the further advantage of simplifying the isDiscard check,
which occurs to avoid the costly fmt.Print call.
We coalesce all 6 checks as just 1 check in Logger.output.
Also, swap the declaration order of Logger.Print and Logger.Printf
to match the ordering elsewhere in the file.
Performance:
name old time/op new time/op delta
Println 188ns ± 2% 172ns ± 4% -8.39% (p=0.000 n=10+10)
PrintlnNoFlags 139ns ± 1% 116ns ± 1% -16.71% (p=0.000 n=9+9)
name old allocs/op new allocs/op delta
Println 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10)
PrintlnNoFlags 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10)
Change-Id: I79d0ee404df848beb3626fe863ccc73a3e2eb325
Reviewed-on: https://go-review.googlesource.com/c/go/+/464345 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Change-Id: Ia0460db3b8412fbaa6f1539fd6b4fb1b873896c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/463999 Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Joe Tsai [Wed, 1 Feb 2023 21:23:02 +0000 (13:23 -0800)]
log: reduce lock contention
Logger.Log methods are called in a highly concurrent manner in many servers.
Acquiring a lock in each method call results in high lock contention,
especially since each lock covers a non-trivial amount of work
(e.g., formatting the header and outputting to the writer).
Changes made:
* Modify the Logger to use atomics so that the header formatting
can be moved out of the critical lock section.
Acquiring the flags does not occur in the same critical section
as outputting to the underlying writer, so this introduces
a very slight consistency instability where concurrently calling
multiple Logger.Output along with Logger.SetFlags may cause
the older flags to be used by some ongoing Logger.Output calls
even after Logger.SetFlags has returned.
* Use a sync.Pool to buffer the intermediate buffer.
This approach is identical to how fmt does it,
with the same max cap mitigation for #23199.
* Only protect outputting to the underlying writer with a lock
to ensure serialized ordering of output.
Performance:
name old time/op new time/op delta
Concurrent-24 19.9µs ± 2% 8.3µs ± 1% -58.37% (p=0.000 n=10+10)
Updates #19438
Change-Id: I091beb7431d8661976a6c01cdb0d145e37fe3d22
Reviewed-on: https://go-review.googlesource.com/c/go/+/464344
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
Archana R [Mon, 31 Oct 2022 16:47:17 +0000 (11:47 -0500)]
cmd/compile: intrinsify math/bits/ReverseBytes{16|32|64} for ppc64/power10
This change intrinsifies ReverseBytes{16|32|64} by generating the
corresponding new instructions in Power10: brh, brd and brw and
adds a verification test for the same.
On Power 9 and 8, the .go code performs optimally as it is.
Ian Lance Taylor [Wed, 1 Feb 2023 21:47:48 +0000 (13:47 -0800)]
maps: new package
This copies x/exp/maps into the standard library (except for the Clear
function which is now available as the clear builtin.)
Fixes #57436
Change-Id: I30dd470c2f7ae34c7c82b4c1025a7582d61fabaa
Reviewed-on: https://go-review.googlesource.com/c/go/+/464343
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Eli Bendersky <eliben@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
Bryan C. Mills [Fri, 3 Feb 2023 14:59:16 +0000 (09:59 -0500)]
cmd/dist: do not include runtime/internal/sys in cmd staleness checks
Since CL 454836, cmd/dist has built the packages in 'cmd' with
different settings than those in 'std': namely, for' cmd' we disable
the use of cgo, and (since CL 463740) if GO_BUILDER_NAME is non-empty
or the VERSION file indicates a release version we also set
GOFLAGS=-trimpath.
However, since at least CL 73212 the staleness checks performed by
cmd/dist for the “toolchain” targets (a subset of 'cmd') have included
the package "runtime/internal/sys" (which is in 'std', not 'cmd').
At that time, cmd/go did not have a separate build cache, so it would
not have been possible to check staleness for a 'cmd' build differently
from 'std'. However, now that is possible, and most of the time
"runtime/internal/sys" lives *only* in the build cache (and so is
essentially never stale after building anything that imports it).
But there is one more wrinkle: if GODEBUG=installgoroot=all is set,
the packages in 'std' are still installed to GOROOT/pkg, and can once
again become stale. Since the install with the 'std' configuration does
not match the configuration used to build 'cmd', the staleness check
fails for "runtime/internal/sys" under the 'cmd' configuration.
Since we intentionally build the toolchain with a different
"runtime/internal/sys" stored only in the build cache, there is no
longer a point in checking that package for staleness: if it is stale,
then the toolchain itself will be reported as stale anyway.
So we can simply remove the package from that staleness check,
and unbreak bootstrapping with GODEBUG=installgoroot=all.
Roger Peppe [Mon, 30 Jan 2023 17:27:42 +0000 (17:27 +0000)]
cmd/go/internal/par: use generic Cache
Using generics here makes the code easier to understand,
as the contract is clearly specified. It also makes the
code a little more concise, as it's easy to write a wrapper
for the cache that adds an error value, meaning that
a bunch of auxilliary types no longer need to be defined
for this common case.
The load.cachingRepo code has been changed to use a separate
cache for each key-value type combination, which seems a bit less
sleazy, but might have some knock-on effect on memory usage,
and could easily be changed back if desired.
Because there's no longer an unambiguous way to find out
whether there's an entry in the cache, the Cache.Get method
now returns a bool as well as the value itself.
Change-Id: I28443125bab0b3720cc95d750e72d28e9b96257d
Reviewed-on: https://go-review.googlesource.com/c/go/+/463843 Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: roger peppe <rogpeppe@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Florin Papa [Mon, 21 Nov 2022 18:07:58 +0000 (10:07 -0800)]
debug/elf: add DT_FLAGS_1 constants
Add constants for all ELF dynamic flags (pertaining to DT_FLAGS_1). This will help, for example, determining whether an object is a position-independent executable (PIE). The constants are defined according to Table 15-10 in https://docs.oracle.com/en/operating-systems/solaris/oracle-solaris/11.4/linkers-libraries/dynamic-section.html.
Fixes #56887
Change-Id: I6cd501af50d9dbcc2aa8a9a002e12c6fb6726761
Reviewed-on: https://go-review.googlesource.com/c/go/+/452496 Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Robert Griesemer [Mon, 30 Jan 2023 23:54:10 +0000 (15:54 -0800)]
go/types, types2: implement simpler type inference (infer2)
This change implements infer2 which is a drop-in replacement for
infer; it can be enabled by setting the useNewTypeInference flag
in infer2.go. It is currently disabled (but tested manually).
infer2 uses the same machinery like infer but in a simpler approach
that is more amenable to precise description and future extensions.
The goal of type inference is to determine a set of (missing) type
arguments from a set of other given facts. Currently, these other
facts are function arguments and type constraints.
In the following, when we refer to "type parameters", we mean the
type parameters defined by the generic function to which we apply
type inference. More precisely, in the algorithm, these are the
type parameters recorded with the unifier.
The approach is as follows:
- A single unifier is set up which tracks all type parameters and
corresponding inferred types.
- The unifier is then fed all the facts we have. The order is not
relevant (*) except that we use default types of untyped constant
arguments only as a last resort, at the end.
- We start with all function arguments: for each generic function
parameter with a typed function argument, we unify the parameter
and function type.
- We then unify each type parameter with its type constraint.
This step is iterated until nothing changes anymore, because
each unification may enable further unification.
- If there are any type parameters left without inferred types,
and which are used as function parameters with untyped constant
arguments, unify them with the default types of those arguments.
Because of unification with constraints which themselves may contain
type parameters, inferred types may contain type parameters. Thus,
in a final step we substitute type parameters for their inferred types
until there are no type parameters left in the inferred types.
All these individual steps are the same as in infer, but there is no
need to do constraint type inference twice (all the facts have already
been used for inference). Also, we only need a single unifier which
serves as the holder for the inferred type parameter types.
Type inference fails if any unification step fails or if not all
type arguments could be inferred. By always using all available
facts (**) we ensure that order doesn't matter.
By using more facts, type inference can now be extended to become
more powerful.
The code can be split up into smaller components that are more
easily digestable. Because we forsee more simplifications, we
defer such cleanups to later CLs.
(*) We currently have a sorting phase in the beginning such that
function argument types that are named types are used before
any other type. We believe this step can be eliminated by
modifying the unifier slightly.
(**) When unifying constraints, in some cases we don't report
an error if unification fails. We believe we can modify the
unifier and then consistently report an inference failure
in this case as well.
Change-Id: If1640a5461bc102fa7fd31dc6e741be667c97e7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/463746 Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Robert Griesemer [Thu, 2 Feb 2023 18:14:58 +0000 (10:14 -0800)]
go/types, types2: simplify symmetric code
Because unification is symmetric, in cases where we have symmetric
code for x and y depending on some property we can swap x and y as
needed and simplify the code.
Also, change u.depth increment/decrement position for slightly
nicer tracing ooutput.
Change-Id: I2e84570d463d1c32f6556108f3cb54062b57c718
Reviewed-on: https://go-review.googlesource.com/c/go/+/464896
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
Bryan C. Mills [Wed, 1 Feb 2023 21:44:21 +0000 (16:44 -0500)]
cmd/go/internal/test: scale the WaitDelay for test subprocesses
Prior to CL 456116 we had an arbitrary 5-second delay after a test
times out before we kill the test. In CL 456116, I reused that
arbitrary 5-second delay as the WaitDelay as well, but on slower
builders it does not seem to be generous enough.
Instead of hard-coding the delay, for tests with a finite timout we
now use a hard-coded fraction of the overall timeout. That will
probably give delays that are longer than strictly necessary for very
long timeouts, but if the user is willing to wait for a very long
timeout they can probably wait a little longer for I/O too.
Bryan C. Mills [Thu, 2 Feb 2023 15:09:39 +0000 (10:09 -0500)]
runtime: eliminate arbitrary timeout in TestCgoLockOSThreadExit
This test previously failed if running a new pthread took longer than
a hard-coded 100ms. On some slow or heavily-loaded builders, that
scheduling latency is too short.
Since the point of this test is to verify that the background thread
is not reused after it terminates (see #20395), the arbitrary time
limit does not seem helpful: if the background thread fails to
terminate the test will time out on its own, and if the main goroutine
is scheduled on the background thread the test will fail regardless of
how long it takes.
Bryan C. Mills [Thu, 2 Feb 2023 15:42:46 +0000 (10:42 -0500)]
internal/testenv: avoid rebuilding all of std in WriteImportcfg
Instead, have the caller pass in an explicit list of the packages
(if any) they need.
After #47257, a builder running a test does not necessarily have the
entire standard library already cached, especially when running tests
in sharded mode. testenv.WriteImportcfg used to write an importcfg for
the entire standard library — which required rebuilding the entire
standard library — even though most tests need only a tiny subset.
This reduces the time to test internal/abi with a cold build cache on
my workstation from ~16s to ~0.05s.
It somewhat increases the time for 'go test go/internal/gcimporter'
with a cold cache, from ~43s to ~54s, presumably due to decreased
parallelism in rebuilding the standard library and increased overhead
in re-resolving the import map. However, 'go test -short' running time
remains stable (~5.5s before and after).
Joe Tsai [Sat, 20 Aug 2022 19:05:07 +0000 (12:05 -0700)]
net/netip: fix invalid representation of Prefix
For a given Addr, ensure there is exactly one invalid representation.
This allows invalid representations to be safely comparable.
To ensure that the zero value of Prefix is invalid,
we modify the encoding of bits to simply be the bit count plus one.
Since Addr is immutable, we check in the PrefixFrom constructor that
the provided Addr is valid and only store a non-zero bits length if so.
IsValid is simplified to just checking whether bitsPlusOne is non-zero.
Fixes #54525
Change-Id: I9244cae2fd160cc9c81d007866992df2e422d3b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/425035
Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Johan Brandhorst-Satzkorn [Tue, 31 Jan 2023 05:51:40 +0000 (21:51 -0800)]
misc: increase node stack size
The default NodeJS V8 stack size is 984K, which is not enough to run
the regexp or go/parser tests. This commit increases the stack size
to 8192K, which removes the stack size limit error.
Fixes #56498
Fixes #57614
Change-Id: I357885d420daf259187403deab25ff587defa0fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/463994 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Julien Fabre <ju.pryz@gmail.com>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Russ Cox [Wed, 1 Feb 2023 17:15:08 +0000 (12:15 -0500)]
cmd/link: keep go.buildinfo even with --gc-sections
If you use an external linker with --gc-sections, nothing refers
to .go.buildinfo, so the section is deleted, which in turns makes
'go version' fail on the binary. It is important for vulnerability
scanning and the like to be able to run 'go version' on any binary.
Fix this by inserting a reference to .go.buildinfo from the rodata
section, which will not be GC'ed.
Robert Griesemer [Tue, 31 Jan 2023 19:34:16 +0000 (11:34 -0800)]
go/types, types2: better error when trying to use ~ as bitwise operation
When coming from C, the bitwise integer complement (bitwise negation)
operator is ~, but in Go it is ^. Report an error mentioning ^ when
~ is used with an integer operand.
Background: Some articles on the web claim that Go doesn't have a
bitwise complement operator.
Change-Id: I41185cae4a70d528754e44f42c13c013ed91bf27
Reviewed-on: https://go-review.googlesource.com/c/go/+/463747
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Robert Griesemer [Mon, 30 Jan 2023 19:09:48 +0000 (11:09 -0800)]
go/types, types2: further simplify unification
Allocate all handles up-front: in a correct program, all type parameters
must be resolved and thus eventually will get a handle.
Also, sharing of handles caused by unified type parameters is rare and
so it's ok to not optimize for that case (and delay handle allocation).
This removes a (premature) optimization whis further simplifies
unification.
Change-Id: Ie1259b86ea5e966538667ab9557676e9be9f6364
Reviewed-on: https://go-review.googlesource.com/c/go/+/463989 Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Robert Griesemer [Thu, 26 Jan 2023 23:39:04 +0000 (15:39 -0800)]
go/types, types2: replace unifier type parameter list with a map
Further simplify the unifier by using a mapping from type parameter
to type (argument) handle, where a handle is just an indirection to
the actual type associated with the type parameter.
If multiple type parameters are "joined", i.e., share the same type
(argument), then they use the same handle. Thus, if one of the type
parameters gets a type, all type parameters sharing the same handle
get the same type.
The handles mapping replaces the indices list (mapping from type
parameter index to types index). Because each handle holds any
associated type directly, we also don't need a types list anymore.
We still keep the incoming type parameter list to maintain the same
order for printing and reporting inferred types. We may be able to
eliminate this list as well in future CLs.
Change-Id: I389527dbb325b828c91050e59902ae546c3d0347
Reviewed-on: https://go-review.googlesource.com/c/go/+/463228 Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Keith Randall [Wed, 1 Feb 2023 16:31:03 +0000 (08:31 -0800)]
cmd/compile: schedule values with no in-block uses later
When scheduling a block, deprioritize values whose results aren't used
until subsequent blocks.
For #58166, this has the effect of pushing the induction variable increment
to the end of the block, past all the other uses of the pre-incremented value.
Do this only with optimizations on. Debuggers have a preference for values
in source code order, which this CL can degrade.
Fixes #58166
Fixes #57976
Change-Id: I40d5885c661b142443c6d4702294c8abe8026c4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/463751
Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Johan Brandhorst-Satzkorn [Tue, 31 Jan 2023 04:09:23 +0000 (20:09 -0800)]
crypto/rand: batch large random reads on js
CL 463975 replaced the use of the NodeJS crypto.randomFillSync API
with a direct call to crypto.getRandomValues. This function rejects
any requests to fill a buffer larger than 65536 bytes, so we need to
batch reads larger than this size. This reuses the batching
functions used on other platforms to perform this batching.
Fixes #58145
Change-Id: Ic0acf3be7c9e994bc345d6614867c9b0c47bd26d
Reviewed-on: https://go-review.googlesource.com/c/go/+/463993 Reviewed-by: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Cuong Manh Le [Fri, 20 Jan 2023 19:36:45 +0000 (02:36 +0700)]
builtin: add documentation for clear
Updates #56351
Change-Id: I7b1dd29e60f71d804a6d9cba3377e28c3a5b964e
Reviewed-on: https://go-review.googlesource.com/c/go/+/462935
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Ian Lance Taylor [Tue, 31 Jan 2023 21:55:19 +0000 (13:55 -0800)]
cmd/dist, internal/platform: remove some target modes that fail
Before CL 463992 there were some cases that cmd/dist did not test
but that platform.BuildModeSupport permitted. In CL 463992 those
conflicts were resolved in favor of platform.BuildModeSupport.
However, further testing has uncovered some cases that do not in
fact work. Adjust those in both cmd/dist and internal/platform.
In particular, mark android-arm and android-arm64 as not supporting
plugin mode. Sample failure:
https://build.golang.org/log/ebba858ea9f94f076966d8cfd42348a0e9345095
Change-Id: Ic1bd18e36382cac0779aad48cb6e7b1de8eeb10d
Reviewed-on: https://go-review.googlesource.com/c/go/+/464339 Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Mateusz Poliwczak [Tue, 31 Jan 2023 09:00:22 +0000 (09:00 +0000)]
net: use net/netip for address parsing
Fixes #58098
Change-Id: I6ef963ba2c110215b8eda763cbfb258a25c8199a
GitHub-Last-Rev: 3d22f076b725337fa97eedcf92a1520a72bf0c17
GitHub-Pull-Request: golang/go#58143
Reviewed-on: https://go-review.googlesource.com/c/go/+/463987
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Bryan C. Mills [Fri, 13 Jan 2023 18:59:19 +0000 (13:59 -0500)]
cmd/go: traverse module-root symlinks in Walk calls
fsys.Walk, like filepath.Walk, avoids traversing symlinks. Also like
filepath.Walk, it follows a symlink at the root if the root path ends
in a file separator (consistent with POSIX pathname resolution¹).
If the user's working directory is within a repository stored in
(and symlinked to) a different filesystem path, we want to follow the
symlink instead of treating the module as completely empty.
Mateusz Poliwczak [Tue, 31 Jan 2023 18:38:01 +0000 (18:38 +0000)]
net: report IsNotFound when getnameinfo returns EAI_NONAME
Fixes #57548
Change-Id: I4092624b1e906fbcd520f43aa4bc71c144dea3b6
GitHub-Last-Rev: ab048359473978ee245188710b6d6e12d50fb0ab
GitHub-Pull-Request: golang/go#57549
Reviewed-on: https://go-review.googlesource.com/c/go/+/460255
Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
Cherry Mui [Wed, 21 Dec 2022 00:31:40 +0000 (19:31 -0500)]
cmd/link: add debug print in hostobjCopy
In external linking mode, when the external linker fails to handle
something in a host object file, it usually reports the name of
the host object which is a copied file named 000NNN.o. This is
often not helpful to determine what file it is. Add some debug
print so at least in -v mode it is more helpful.
Change-Id: Ibe762bff6a25640d16ee0dc082736ba5161b7522
Reviewed-on: https://go-review.googlesource.com/c/go/+/458735 Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Bryan C. Mills [Thu, 8 Dec 2022 19:10:59 +0000 (14:10 -0500)]
os: allow $HOME to not exist in TestUserHomeDir
This seems like a cleaner fix for the situation Debian has patched
around with
https://sources.debian.org/patches/golang-1.19/1.19.3-1/0001-Disable-test-for-UserHomeDir.patch/
Tested with 'GOCACHE=$(go env GOCACHE) HOME=/home/nobody go test os'.
Change-Id: I9fd00da38b86df2edfcd8cb87629e2875573903e
Reviewed-on: https://go-review.googlesource.com/c/go/+/456126
Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>