]> Cypherpunks.ru repositories - gostls13.git/log
gostls13.git
13 months agonet: mptcp: add TCPConn's MultipathTCP checker
Matthieu Baerts [Fri, 24 Feb 2023 16:52:00 +0000 (17:52 +0100)]
net: mptcp: add TCPConn's MultipathTCP checker

This new TCPConn method returns whether the connection is using MPTCP or
if a fallback to TCP has been done, e.g. because the other peer doesn't
support MPTCP.

When working on the new E2E test linked to MPTCP (#56539), it looks like
the user might need to know such info to be able to do some special
actions (report, stop, etc.). This also improves the test to make sure
MPTCP has been used as expected.

Regarding the implementation, from kernel version 5.16, it is possible
to use:

    getsockopt(..., SOL_MPTCP, MPTCP_INFO, ...)

and check if EOPNOTSUPP (IPv4) or ENOPROTOOPT (IPv6) is returned. If it
is, it means a fallback to TCP has been done. See this link for more
details:

    https://github.com/multipath-tcp/mptcp_net-next/issues/294

Before v5.16, there is no other simple way, from the userspace, to check
if the created socket did a fallback to TCP. Netlink requests could be
done to try to find more details about a specific socket but that seems
quite a heavy machinery. Instead, only the protocol is checked on older
kernels.

The E2E test has been modified to check that the MPTCP connection didn't
do any fallback to TCP, explicitely validating the two methods
(SO_PROTOCOL and MPTCP_INFO) if it is supported by the host.

This work has been co-developed by Gregory Detal
<gregory.detal@tessares.net> and Benjamin Hesmans
<benjamin.hesmans@tessares.net>.

Fixes #59166

Change-Id: I5a313207146f71c66c349aa8588a2525179dd8b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/471140
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
13 months agointernal/poll: add GetsockoptInt
Matthieu Baerts [Fri, 24 Feb 2023 16:51:59 +0000 (17:51 +0100)]
internal/poll: add GetsockoptInt

This new function wraps the getsockopt network call with an integer
argument, similar to SetsockoptInt.

This will be used in MPTCP in the following commit.

This work has been co-developed by Gregory Detal
<gregory.detal@tessares.net>.

Updates #59166

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

13 months agoplugin: fix duplicated word in comment
Oleksandr Redko [Mon, 17 Apr 2023 09:23:36 +0000 (12:23 +0300)]
plugin: fix duplicated word in comment

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

13 months agomaps: replace slicesEqual with slices.Equal
jiahua wang [Sat, 8 Apr 2023 12:42:26 +0000 (20:42 +0800)]
maps: replace slicesEqual with slices.Equal

Change-Id: I15aeef9c6d3ddc80644a14d6266d21a8515ede4e
Reviewed-on: https://go-review.googlesource.com/c/go/+/483156
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
13 months agocmd/go: add check for unknown godebug setting
Russ Cox [Tue, 14 Mar 2023 18:25:56 +0000 (14:25 -0400)]
cmd/go: add check for unknown godebug setting

A //go:debug line mentioning an unknown or retired setting
should be diagnosed as making the program invalid. Do that.
We agreed on this in the proposal but I forgot to implement it.

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

13 months agocmd/go: change toolchain based on $GOTOOLCHAIN
Russ Cox [Fri, 10 Mar 2023 19:02:32 +0000 (14:02 -0500)]
cmd/go: change toolchain based on $GOTOOLCHAIN

For proposal #57001, add code to reinvoke a different Go toolchain
based on $GOTOOLCHAIN. The toolchain is searched for in $PATH
first and otherwise downloaded. The download is a standard module
download, so the toolchain is validated using the checksum database
before being executed or even stored in the file system.

Followup CLs will refine the exact toolchain selection and implement
other parts of the proposal. This is only the download+reinvoke code.

For #57001.

Change-Id: I44363cbd916dac01342b1bfce6a487fe7166be4a
Reviewed-on: https://go-review.googlesource.com/c/go/+/475955
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
13 months agoRevert "cmd/compile: allow more inlining of functions that construct closures"
Michael Knyszek [Mon, 17 Apr 2023 21:21:41 +0000 (21:21 +0000)]
Revert "cmd/compile: allow more inlining of functions that construct closures"

This reverts commit f8162a0e726f4b3a9df60a37e8ca7883dde61914.

Reason for revert: https://github.com/golang/go/issues/59680

Change-Id: I91821c691a2d019ff0ad5b69509e32f3d56b8f67
Reviewed-on: https://go-review.googlesource.com/c/go/+/485498
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>

13 months agoRevert "runtime/cgo: store M for C-created thread in pthread key"
Michael Pratt [Mon, 17 Apr 2023 18:13:06 +0000 (14:13 -0400)]
Revert "runtime/cgo: store M for C-created thread in pthread key"

This reverts CL 481061.

Reason for revert: When built with C TSAN, x_cgo_getstackbound triggers
race detection on `g->stacklo` because the synchronization is in Go,
which isn't instrumented.

For #51676.
For #59294.
For #59678.

Change-Id: I38afcda9fcffd6537582a39a5214bc23dc147d47
Reviewed-on: https://go-review.googlesource.com/c/go/+/485275
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
13 months agoRevert "runtime: correct GoCheckBindM's C declaration in EnsureBindM test"
Michael Pratt [Mon, 17 Apr 2023 18:12:25 +0000 (14:12 -0400)]
Revert "runtime: correct GoCheckBindM's C declaration in EnsureBindM test"

This reverts CL 482975.

Reason for revert: CL 481061 causes C TSAN failures and must be
reverted. See CL 485275. This CL depends on CL 481061.

For #59678.

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

13 months agoRevert "Revert "Revert "runtime: consolidate function descriptor definitions on PPC64"""
Michael Pratt [Mon, 17 Apr 2023 18:09:39 +0000 (14:09 -0400)]
Revert "Revert "Revert "runtime: consolidate function descriptor definitions on PPC64"""

This reverts CL 481075 (a re-apply of previously reverted CL 478917).

Reason for revert: CL 481061 causes C TSAN failures and must be
reverted. See CL 485275. This CL depends on CL 481061.

For #59678.

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

13 months agoRevert "runtime/cgo: use pthread_attr_get_np on Illumos"
Michael Pratt [Mon, 17 Apr 2023 18:06:10 +0000 (14:06 -0400)]
Revert "runtime/cgo: use pthread_attr_get_np on Illumos"

This reverts CL 481795.

Reason for revert: CL 481061 causes C TSAN failures and must be
reverted. See CL 485275. This CL depends on CL 481061.

For #59678.

Change-Id: I5ec1f495154205ebdf19cd44c6e6452a7a3606f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/485315
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
13 months agocmd/compile: allow more inlining of functions that construct closures
Than McIntosh [Tue, 4 Apr 2023 22:31:46 +0000 (18:31 -0400)]
cmd/compile: allow more inlining of functions that construct closures

[This is a roll-forward of CL 479095, which was reverted due to a bad
interaction between inlining and escape analysis, then later fixed
fist with an attempt in CL 482355, then again in 484859 .]

Currently, when the inliner is determining if a function is
inlineable, it descends into the bodies of closures constructed by
that function. This has several unfortunate consequences:

- If the closure contains a disallowed operation (e.g., a defer), then
  the outer function can't be inlined. It makes sense that the
  *closure* can't be inlined in this case, but it doesn't make sense
  to punish the function that constructs the closure.

- The hairiness of the closure counts against the inlining budget of
  the outer function. Since we currently copy the closure body when
  inlining the outer function, this makes sense from the perspective
  of export data size and binary size, but ultimately doesn't make
  much sense from the perspective of what should be inlineable.

- Since the inliner walks into every closure created by an outer
  function in addition to starting a walk at every closure, this adds
  an n^2 factor to inlinability analysis.

This CL simply drops this behavior.

In std, this makes 57 more functions inlinable, and disallows inlining
for 10 (due to the basic instability of our bottom-up inlining
approach), for an net increase of 47 inlinable functions (+0.6%).

This will help significantly with the performance of the functions to
be added for #56102, which have a somewhat complicated nesting of
closures with a performance-critical fast path.

The downside of this seems to be a potential increase in export data
and text size, but the practical impact of this seems to be
negligible:

       │    before    │           after            │
       │    bytes     │    bytes      vs base      │
Go/binary        15.12Mi ± 0%   15.14Mi ± 0%  +0.16% (n=1)
Go/text          5.220Mi ± 0%   5.237Mi ± 0%  +0.32% (n=1)
Compile/binary   22.92Mi ± 0%   22.94Mi ± 0%  +0.07% (n=1)
Compile/text     8.428Mi ± 0%   8.435Mi ± 0%  +0.08% (n=1)

Updates #56102.

Change-Id: I6e938d596992ffb473cf51e7e598f372ce08deb0
Reviewed-on: https://go-review.googlesource.com/c/go/+/484860
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
13 months agocmd/compile: rework marking of dead hidden closure functions
Than McIntosh [Fri, 14 Apr 2023 18:07:37 +0000 (14:07 -0400)]
cmd/compile: rework marking of dead hidden closure functions

This patch generalizes the code in the inliner that marks unreferenced
hidden closure functions as dead. Rather than doing the marking on the
fly (previous approach), this new approach does a single pass at the
end of inlining, which catches more dead functions.

Fixes #59638.
Updates #59404.
Updates #59547.

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

13 months agogo/types, types2: factor out type parameter renaming from type inference
Robert Griesemer [Thu, 13 Apr 2023 23:11:14 +0000 (16:11 -0700)]
go/types, types2: factor out type parameter renaming from type inference

Preparation for reverse type inference where there is no need
to rename all type parameters supplied to type inference when
passing generic functions as arguments to (possibly generic)
function calls.

This also leads to a better separation of concerns.

Change-Id: Id487a5c1340b743519b9053edc43f8aa99408522
Reviewed-on: https://go-review.googlesource.com/c/go/+/484655
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
13 months agocmd/go/internal/cache: update docs on cache accessor func
Brad Fitzpatrick [Mon, 6 Feb 2023 14:07:07 +0000 (06:07 -0800)]
cmd/go/internal/cache: update docs on cache accessor func

Its docs went stale in Go 1.12 when the build cache became required.

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

13 months agocmd/compile: remove typecheck.EvalConst
Cuong Manh Le [Mon, 20 Feb 2023 05:49:03 +0000 (12:49 +0700)]
cmd/compile: remove typecheck.EvalConst

types2 has already done most of the constant folding parts. The only
case left is unsafe.{Alignoff,Offsetof,Sizeof} with variable size
argument, which is handled separately during typecheck.

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

13 months agogo/types, types2: (slightly) refactor tpWalker.isParameterized (cleanup)
Robert Griesemer [Thu, 13 Apr 2023 20:58:45 +0000 (13:58 -0700)]
go/types, types2: (slightly) refactor tpWalker.isParameterized (cleanup)

Match the structure of cycleFinder. Removes a TODO.

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

13 months agocmd/compile: add test that non-name call does not allocate
Cuong Manh Le [Wed, 28 Dec 2022 04:21:47 +0000 (11:21 +0700)]
cmd/compile: add test that non-name call does not allocate

Updates #57434

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

13 months agoembed/internal/embedtest: test openFile.ReadAt with non-zero offset
Tobias Klauser [Thu, 13 Apr 2023 15:57:42 +0000 (17:57 +0200)]
embed/internal/embedtest: test openFile.ReadAt with non-zero offset

Also fix log messages to report expected values in the standard "got foo,
want bar" format.

Change-Id: I6a9fd4abe1f86c2651c72c2bf7ac4588028e5923
Reviewed-on: https://go-review.googlesource.com/c/go/+/484715
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>

13 months agocmd/compile/internal/importer,go/internal/gcimporter: use the 'go' command from build...
Bryan C. Mills [Fri, 14 Apr 2023 16:48:26 +0000 (16:48 +0000)]
cmd/compile/internal/importer,go/internal/gcimporter: use the 'go' command from build.Default.GOROOT in lookupGorootExport

Also set GOROOT explicitly in case it is set to something else in the
caller's environment.

Fixes #59598.

Change-Id: I5599ed1183b23187fc3b976786f3c320d42ef4f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/484756
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
13 months agocmd/link/internal/ld: disable execute-only for external linking on openbsd/arm64
Joel Sing [Thu, 13 Apr 2023 19:47:36 +0000 (05:47 +1000)]
cmd/link/internal/ld: disable execute-only for external linking on openbsd/arm64

The Go arm64 assembler places constants into the text section of a binary.
OpenBSD 7.3 enabled xonly by default on OpenBSD/arm64. This means that any
externally linked Go binary now segfaults. Disable execute-only when invoking
the external linker on openbsd/arm64, in order to work around this issue.

Updates #59615

Change-Id: I1a291293da3c6e4409b21873d066ea15e9bfe280
Reviewed-on: https://go-review.googlesource.com/c/go/+/484555
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Aaron Bieber <deftly@gmail.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Than McIntosh <thanm@google.com>
13 months agogo/types,types2: fix panic in reverse type inference when -lang<go1.18
Rob Findley [Fri, 14 Apr 2023 18:25:53 +0000 (14:25 -0400)]
go/types,types2: fix panic in reverse type inference when -lang<go1.18

Due to reverse type inference, we may not have an index expression when
type-checking a function instantiation. Fix a panic when the index expr
is nil.

Fixes #59639

Change-Id: Ib5de5e49cdb7b339653e4fb775bf5c5fdb3c6907
Reviewed-on: https://go-review.googlesource.com/c/go/+/484757
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>

13 months agocmd/compile: add math benchmarks
Joel Sing [Wed, 5 Apr 2023 20:11:01 +0000 (06:11 +1000)]
cmd/compile: add math benchmarks

This adds benchmarks for division and modulus of 64 bit signed and unsigned
integers.

Updates #59089

Change-Id: Ie757c6d74a1f355873e79619eae26ece21a8f23e
Reviewed-on: https://go-review.googlesource.com/c/go/+/482656
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
13 months agocmd/compile/internal/ir: remove HasBreak field of some nodes
Cuong Manh Le [Thu, 13 Apr 2023 15:26:09 +0000 (22:26 +0700)]
cmd/compile/internal/ir: remove HasBreak field of some nodes

CL 484435 removed all usages of them.

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

13 months agocmd/compile/internal/typecheck: remove some un-used functions
Cuong Manh Le [Thu, 13 Apr 2023 15:05:14 +0000 (22:05 +0700)]
cmd/compile/internal/typecheck: remove some un-used functions

CL 405094 removed the only caller of markBreak/setHasBreak and
isTermNodes/isTermNode.

importlist variable is only used in old frontend.

Change-Id: I9472f2c0017b6200847999f2cea0e9021a1b14e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/484435
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
13 months agocmd/compile: stop constructing untyped nodes when instrumenting asan
Cuong Manh Le [Thu, 13 Apr 2023 10:44:32 +0000 (17:44 +0700)]
cmd/compile: stop constructing untyped nodes when instrumenting asan

The code is using typecheck.ConvNop to convert from untyped int to
uintptr. However, that left the literal node untyped. It often does not
matter, because typecheck.EvalConst will see the OCONVNOP, and replace
the node with a new constant node.

This CL changes the code to construct the constant node directly using
typecheck.DefaultLit, so the last dependecy of typecheck.EvalConst will
go away, next CL can safely remove it from the code base.

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

13 months agocmd/compile: better code generation for constant-fold switch
Cuong Manh Le [Thu, 13 Apr 2023 07:51:05 +0000 (14:51 +0700)]
cmd/compile: better code generation for constant-fold switch

CL 399694 added constant-fold switch early in compilation. So function:

func f() string {
    switch intSize {
    case 32:
        return "32"
    case 64:
        return "64"
    default:
        panic("unreachable")
    }
}

will be constant-fold to:

func f() string {
    switch intSize {
    case 64:
        return "64"
    }
}

When this function get inlined, there is a check whether we can delay
declaring the result parameter until the "return" statement. For the
original function, we can't delay the result, because there's more than
one return statement. However, the constant-fold one can, because
there's on one return statement in the body now. The result parameter
~R0 ends up declaring inside the switch statement scope.

Now, when walking the switch statement, it's re-written into if-else
statement. Without typecheck.EvalConst, the if condition "if 64 == 64"
is passed as-is to the ssa generation pass. Because "64 == 64" is not a
constant, the ssagen creates normal blocks for branching the results.
This confuses the liveness analysis, because ~R0 is only live inside the
if block. With typecheck.EvalConst, "64 == 64" is evaluated to "true",
so ssagen can branch the result without emitting conditional blocks.

Instead, the constant-fold can be re-written as:

switch {
case true:
    // Body
}

So it does not depend on the delay results check during inlining. Adding
a test, which will fail when typecheck.EvalConst is removed, so we can
do the cleanup without breaking things.

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

13 months agocmd/compile: move unsafe operation out of EvalConst
Cuong Manh Le [Thu, 13 Apr 2023 02:31:41 +0000 (09:31 +0700)]
cmd/compile: move unsafe operation out of EvalConst

So future CLs can get rid of EvalConst entirely.

Change-Id: Ic8e147fd76e53c002a6ceda2fb3be979459bf865
Reviewed-on: https://go-review.googlesource.com/c/go/+/484315
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@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>

13 months agocmd/compile: reenable inline static init
Cuong Manh Le [Thu, 9 Feb 2023 19:20:56 +0000 (02:20 +0700)]
cmd/compile: reenable inline static init

Updates #58293
Updates #58339
Fixes #58439

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

13 months agocmd/compile: handle string concatenation in static init inliner
Cuong Manh Le [Wed, 8 Feb 2023 08:45:09 +0000 (15:45 +0700)]
cmd/compile: handle string concatenation in static init inliner

Static init inliner is using typecheck.EvalConst to handle string
concatenation expressions. But static init inliner may reveal constant
expressions after substitution, and the compiler needs to evaluate those
expressions in non-constant semantic. Using typecheck.EvalConst, which
always evaluates expressions in constant semantic, is not the right
choice.

For safety, this CL fold the logic to handle string concatenation to
static init inliner, so there won't be regression in handling constant
expressions in non-constant semantic. And also, future CL can simplify
typecheck.EvalConst logic.

Updates #58293
Updates #58339
Fixes #58439

Change-Id: I74068d99c245938e576afe9460cbd2b39677bbff
Reviewed-on: https://go-review.googlesource.com/c/go/+/466277
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
13 months agopath/filepath,cmd/go: skip tests involving double-symlinks on ios
Bryan C. Mills [Fri, 14 Apr 2023 15:59:40 +0000 (15:59 +0000)]
path/filepath,cmd/go: skip tests involving double-symlinks on ios

For #59586.

Change-Id: I092f7a4abce1074b8eef64a3ecf9fc187914709b
Reviewed-on: https://go-review.googlesource.com/c/go/+/484755
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Bypass: Bryan Mills <bcmills@google.com>

13 months agocmd/link: establish dependable package initialization order
Keith Randall [Fri, 13 Jan 2023 04:25:39 +0000 (20:25 -0800)]
cmd/link: establish dependable package initialization order

(This is a retry of CL 462035 which was reverted at 474976.
The only change from that CL is the aix fix SRODATA->SNOPTRDATA
at inittask.go:141)

As described here:

https://github.com/golang/go/issues/31636#issuecomment-493271830

"Find the lexically earliest package that is not initialized yet,
but has had all its dependencies initialized, initialize that package,
 and repeat."

Simplify the runtime a bit, by just computing the ordering required
in the linker and giving a list to the runtime.

Update #31636
Fixes #57411

RELNOTE=yes

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

13 months agoregexp: fix copy-paste typo on Regexp.UnmarshalText doc
Daniel Martí [Thu, 13 Apr 2023 12:17:26 +0000 (13:17 +0100)]
regexp: fix copy-paste typo on Regexp.UnmarshalText doc

I noticed that https://go.dev/cl/479401 called both methods MarshalText
in the godoc, so fix that.

While here, add more godoc links for better usability.

Change-Id: I8f10bafeca6a1ca1c1ed9be7a7dd9fdecfe991a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/484335
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
13 months agocmd/go: make go line declare minimum required Go version
Russ Cox [Mon, 13 Mar 2023 17:22:34 +0000 (13:22 -0400)]
cmd/go: make go line declare minimum required Go version

For #57001, enforce the go line as declaring the minimum required
version of Go that can compile a module.

Modules that maintain compatibility with old versions of Go
but want to make use of new features in //go:build-constrained files
will be able to do so: the //go:build constraint will be interpreted
as changing the minimum Go version for that file and will unlock
the Go features allowed in that version.

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

13 months agogo/types, cmd/compile/internal/types2: use per-file Go version
Russ Cox [Tue, 14 Mar 2023 01:06:49 +0000 (21:06 -0400)]
go/types, cmd/compile/internal/types2: use per-file Go version

For #57001, compilers and others tools will need to understand that
a different Go version can be used in different files in a program,
according to the //go:build lines in those files.

Update go/types and cmd/compile/internal/types2 to track and
use per-file Go versions. The two must be updated together because
of the files in go/types that are generated from files in types2.

The effect of the //go:build go1.N line depends on the Go version
declared in the 'go 1.M' line in go.mod. If N > M, the file gets go1.N
semantics when built with a Go 1.N or later toolchain
(when built with an earlier toolchain the //go:build line will keep
the file from being built at all).
If N < M, then in general we want the file to get go1.N semantics
as well, meaning later features are disabled. However, older Go 1.M
did not apply this kind of downgrade, so for compatibility, N < M
only has an effect when M >= 21, meaning when using semantics
from Go 1.21 or later.

For #59033.

Change-Id: I93cf07e6c687d37bd37a9461dc60cc032bafd01d
Reviewed-on: https://go-review.googlesource.com/c/go/+/476278
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>

13 months agoRevert "cmd/compile: allow more inlining of functions that construct closures"
Than McIntosh [Fri, 14 Apr 2023 13:08:34 +0000 (13:08 +0000)]
Revert "cmd/compile: allow more inlining of functions that construct closures"

This reverts commit http://go.dev/cl/c/482356.

Reason for revert: Reverting this change again, since it is causing additional failures in google-internal testing.

Change-Id: I9234946f62e5bb18c2f873a65e8b298d04af0809
Reviewed-on: https://go-review.googlesource.com/c/go/+/484735
Reviewed-by: Florian Zenker <floriank@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
Auto-Submit: Than McIntosh <thanm@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
13 months agodoc: correct spelling on placeholder
Daniel Frederick Crisman [Thu, 13 Apr 2023 21:34:31 +0000 (21:34 +0000)]
doc: correct spelling on placeholder

"placeholder" (no space) is already used in the spec and seems to be
the preferred option.

Removed space from "place holder".

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

13 months agocmd/go: parallelize part of loading test packages in list
Michael Matloob [Wed, 12 Apr 2023 23:00:30 +0000 (19:00 -0400)]
cmd/go: parallelize part of loading test packages in list

load.TestPackagesAndErrors is given an optional done func() argument.
If set, load.TestPackagesAndErrors will perform part of its work
asynchronously and call done when done. This allows go list to run
testPackagesAndErrors so that the parallelizable parts of
TestPackagesAndErrors run in parallel, making go list -e faster.

Fixes #59157
Change-Id: I11f45bbb3ea4ceda928983bcf9fd41bfdcc4fbd9
Reviewed-on: https://go-review.googlesource.com/c/go/+/484496
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
13 months agowasm: restrict supported types in go:wasmimport function signatures
Achille Roussel [Sun, 9 Apr 2023 16:11:52 +0000 (10:11 -0600)]
wasm: restrict supported types in go:wasmimport function signatures

Changes the set of types supported in functions declared with the
go:wasmimport directive to only allow 32 bits and 64 bits integers
and floats, as well as unsafe.Pointer in parameters only. Both the
compiler code and the standard library are updated because the new
restrictions require modifying the use of go:wasmimport in the
syscall and runtime packages.

In preparation of enabling packages outside of the standard library
to use the go:wasmimport directive, the error messages are modified
to carry more context and use ErrorfAt instead of Fatalf to avoid
printing the compiler stack trace when a function with an invalid
signature is encountered.

Fixes #59156

Change-Id: Ied8317f8ead9c28f0297060ac35a5b5255ab49db
Reviewed-on: https://go-review.googlesource.com/c/go/+/483415
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>

13 months agogo/parser: report //go:build-derived Go version in ast.File.GoVersion
Russ Cox [Mon, 13 Mar 2023 21:35:03 +0000 (17:35 -0400)]
go/parser: report //go:build-derived Go version in ast.File.GoVersion

For #57001, compilers and others tools will need to understand that
a different Go version can be used in different files in a program,
according to the //go:build lines in those files.

Update go/parser to populate the new ast.File.GoVersion field.

This requires running the go/scanner in ParseComments mode
always and then implementing discarding of comments in the
parser instead of the scanner. The same work is done either way,
since the scanner was already preparing the comment result
and then looping. The loop has just moved into go/parser.

Also make the same changes to cmd/compile/internal/syntax,
both because they're necessary and to keep in sync with go/parser.

For #59033.

Change-Id: I7b867f5f9aaaccdca94af146b061d16d9a3fd07f
Reviewed-on: https://go-review.googlesource.com/c/go/+/476277
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>

13 months agoslices: amortize allocations in Insert
Ian Lance Taylor [Wed, 12 Apr 2023 20:57:21 +0000 (13:57 -0700)]
slices: amortize allocations in Insert

Fixes #54948

Change-Id: I467afb940b539b100dcce687b05914a9da7b9ed2
Reviewed-on: https://go-review.googlesource.com/c/go/+/484159
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Valentin Deleplace <deleplace@google.com>
13 months agopath/filepath: add test cases for walking a symlink-to-symlink-to-dir
Bryan C. Mills [Thu, 13 Apr 2023 14:48:35 +0000 (14:48 +0000)]
path/filepath: add test cases for walking a symlink-to-symlink-to-dir

The "double link with slash" test is skipped on darwin due to an
apparent kernel / libc bug. If the bug is present on other platforms
too, I'd like to know about it.

For #59586.

Change-Id: I4bdd6a80a3ed7b0960ea6da30f91a655f317d512
Reviewed-on: https://go-review.googlesource.com/c/go/+/484395
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
13 months agomaps,runtime: improve maps.Clone
cuiweixie [Sun, 26 Feb 2023 23:15:50 +0000 (07:15 +0800)]
maps,runtime: improve maps.Clone

name         old time/op    new time/op    delta
MapClone-10    65.8ms ± 7%    10.3ms ± 2%  -84.30%  (p=0.000 n=10+9)

name         old alloc/op   new alloc/op   delta
MapClone-10    40.2MB ± 0%    40.5MB ± 0%   +0.57%  (p=0.000 n=10+9)

name         old allocs/op  new allocs/op  delta
MapClone-10      20.0 ± 0%      23.0 ± 0%  +15.00%  (p=0.000 n=10+10)

Updates #58740.

Change-Id: I148501e723cb2124f02045400e7ceb36af0871c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/471400
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: xie cui <523516579@qq.com>
Reviewed-by: Keith Randall <khr@google.com>
13 months agogo/types,types2: add a test for const initializer panic
Rob Findley [Thu, 13 Apr 2023 14:22:46 +0000 (10:22 -0400)]
go/types,types2: add a test for const initializer panic

Updates #59603

Change-Id: Iff99f45a72a259b57b2ebbc6c0f9ed710add3ae3
Reviewed-on: https://go-review.googlesource.com/c/go/+/484376
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
13 months agoRevert "go/types, types2: remove unnecessary tests for x.typ == Typ[Invalid]"
Robert Findley [Thu, 13 Apr 2023 13:55:42 +0000 (13:55 +0000)]
Revert "go/types, types2: remove unnecessary tests for x.typ == Typ[Invalid]"

This reverts commit 4c49d52439805c248f4a01d529b90b22e821b7d6.

Reason for revert: it is trickier than expected to enforce an invariant that x.typ == Typ[Invalid] => x.mode == invalid. For example, builtins have invalid type until their call is evaluated.

I think it is better to keep this defensive code for now. My bad for suggesting this strictness. I will send a follow-up CL with a test that exercises the panic discovered inside Google, and a bit more commentary about what 'invalid' means in both contexts.

Fixes #59603

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

13 months agointernal/types: rename 54942.go to issue54942.go
Rob Findley [Thu, 13 Apr 2023 15:05:57 +0000 (11:05 -0400)]
internal/types: rename 54942.go to issue54942.go

This filename was inconsistent with all others.

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

13 months agogo/doc/comment: remove unused fields
Daniel Martí [Sat, 8 Apr 2023 16:11:37 +0000 (17:11 +0100)]
go/doc/comment: remove unused fields

Change-Id: Ia5b73e6950d0c53144a97e1ad3f231d69dd74fe8
Reviewed-on: https://go-review.googlesource.com/c/go/+/483295
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Agniva De Sarker <agniva.quicksilver@gmail.com>
13 months agocmd/gofmt: apply a correct suggestion by gopls
Daniel Martí [Sat, 8 Apr 2023 21:52:21 +0000 (22:52 +0100)]
cmd/gofmt: apply a correct suggestion by gopls

I wrote this code a couple of years back,
and it's unnecessarily verbose for sure.

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

13 months agogo/types, types2: factor out inference cycle detector (cleanup)
Robert Griesemer [Wed, 12 Apr 2023 20:16:44 +0000 (13:16 -0700)]
go/types, types2: factor out inference cycle detector (cleanup)

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

13 months agogo/types, types2: generalize tparamIndex to arbitrary type parameter lists
Robert Griesemer [Wed, 12 Apr 2023 16:43:41 +0000 (09:43 -0700)]
go/types, types2: generalize tparamIndex to arbitrary type parameter lists

tparamIndex returns the index of a type parameter given the type
parameter and a list of type parameters. If an index >= 0 is returned,
it is the index assigned to the type parameter (TypeParam.index), and
the index of the type parameter in the provided list of parameters.
For it to work correctly, the type parameter list must be from a single
type parameter declaration.

To allow for lists of arbitrary type parameters (from different generic
signatures), change the implementation to do a linear search. The result
is the index of the type parameter in the provided type parameter list,
which may be different from the index assigned to the type parameter.

The linear search is likely fast enough since type parameter lists tend
to be very short.

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

13 months agocmd/internal/moddeps: preserve PWD more carefully in commands
Bryan C. Mills [Thu, 13 Apr 2023 03:19:20 +0000 (03:19 +0000)]
cmd/internal/moddeps: preserve PWD more carefully in commands

On macOS, TMPDIR is typically a symlink, and the GOROOT for the
buildlet is in TMPDIR as well. PWD must be preserved in order for
os.Getwd (and functions based on it) to report paths that remain
relative to GOROOT, and paths relative to GOROOT are necessary in
order for filepath.Rel to report subdirectories as subdirectories
(rather than paths with long "../../…" prefixes).

Fortunately, the (*Cmd).Environ method added for #50599 makes
preserving PWD somewhat easier.

This fixes 'go test cmd/internal/moddeps' on the new
darwin-amd64-longtest builder.

For #35678.

Change-Id: Ibaa458bc9a94b44ba455519bb8da445af07fe0d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/484295
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
13 months agocmd/go: skip TestScript/list_goroot_symlink on darwin
Bryan C. Mills [Wed, 12 Apr 2023 21:42:29 +0000 (21:42 +0000)]
cmd/go: skip TestScript/list_goroot_symlink on darwin

The list_goroot_symlink test relies on fsys.Walk (and ultimately
syscall.Lstat) conforming to POSIX pathname resolution semantics.
POSIX requires that symlinks ending in a slash be fully resolved,
but it appears that lstat in current darwin kernels does not fully
resolve the last pathname component when it is a symlink to a symlink.

For #59586.
For #35678.

Change-Id: I37526f012ba94fa1796b33109a41c3226c967d3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/484216
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Bypass: Bryan Mills <bcmills@google.com>

13 months agocmd/compile: fix reproducible build of aliased generic types
Matthew Dempsky [Wed, 12 Apr 2023 19:41:45 +0000 (12:41 -0700)]
cmd/compile: fix reproducible build of aliased generic types

Due to a missing "&& !alias" check, the unified linker was treating
type aliases the same as defined types for the purpose of exporting
method bodies. The methods will get exported anyway alongside the
aliased type, so this mistake is normally harmless.

However, if multiple type aliases instantiated the same generic type
but with different type arguments, this could result in the
same (generic) method body being exported multiple times under
different symbol names. Further, because bodies aren't expected to be
exported multiple times, we were sorting them simply based on index.
And consequently, the sort wasn't total and is sensitive to the map
iteration order used while ranging over linker.bodies.

The fix is simply to add the missing "&& !alias" check, so that we
don't end up with duplicate bodies in the first place.

Thanks rsc@ for providing a minimal repro case.

Fixes #59571.

Change-Id: Iaa55968cc7110b601e2f0f9b620901c2d55f7014
Reviewed-on: https://go-review.googlesource.com/c/go/+/484155
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
13 months agoruntime: cleanup ppc64le/linux library startup code
Paul E. Murphy [Wed, 15 Mar 2023 18:09:10 +0000 (13:09 -0500)]
runtime: cleanup ppc64le/linux library startup code

Fix the argument passing to runtime.newosproc0, the ABI0 argument
storing must account for the fixed frame size.

Cleanup the _rt0_ppc64le_linux_lib definition, the assembler
should not generate a stack frame.  And convert it to use the
new ABI wrappers.

Change-Id: Ibc0be8b37f6522900781a19980fa018dd89ba7b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/479796
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
13 months agolog/slog: catch panics in LogValue
Jonathan Amsterdam [Wed, 12 Apr 2023 14:07:35 +0000 (10:07 -0400)]
log/slog: catch panics in LogValue

If a LogValue call panics, recover and return an error instead.

The error contains some stack information to make it easier to
find the problem. A number of people complained that panics
in fmt.Formatter.Format functions are hard to debug because
there is no context.

This is an example of the error text:

    LogValue panicked
    called from log/slog.panickingLogValue.LogValue (/usr/local/google/home/jba/repos/go/src/log/slog/value_test.go:221)
    called from log/slog.Value.resolve (/usr/local/google/home/jba/repos/go/src/log/slog/value.go:465)
    called from log/slog.Value.Resolve (/usr/local/google/home/jba/repos/go/src/log/slog/value.go:446)
    called from log/slog.TestLogValue (/usr/local/google/home/jba/repos/go/src/log/slog/value_test.go:192)
    called from testing.tRunner (/usr/local/google/home/jba/repos/go/src/testing/testing.go:1595)
    (rest of stack elided)

Fixes #59141.

Change-Id: I62e6ff6968d1aa34873e955c2d606d25418a673b
Reviewed-on: https://go-review.googlesource.com/c/go/+/484097
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>

13 months agolog/slog: function argument to Record.Attrs returns bool
Jonathan Amsterdam [Wed, 12 Apr 2023 13:11:59 +0000 (09:11 -0400)]
log/slog: function argument to Record.Attrs returns bool

Record.Attrs stops as soon as its argument function returns false.

Fixes #59060.

Change-Id: I578d64635e0e52b0fcdbc57f6d5a27a6efac8c70
Reviewed-on: https://go-review.googlesource.com/c/go/+/484096
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>

13 months agolog/slog: require entire Attr to be empty to elide
Jonathan Amsterdam [Mon, 27 Mar 2023 13:27:43 +0000 (09:27 -0400)]
log/slog: require entire Attr to be empty to elide

Specify that Handlers should ignore zero-valued Attrs.

Implement that policy in the built-in handlers.

Fixes #59282.

Change-Id: I4430686b61f49bdac849ee300daaabfac9895849
Reviewed-on: https://go-review.googlesource.com/c/go/+/484095
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
13 months agocmd/internal/sys, cmd/dist, misc/cgo/testcshared: enable c-shared feature and test...
limeidan [Thu, 25 Aug 2022 03:14:15 +0000 (11:14 +0800)]
cmd/internal/sys, cmd/dist, misc/cgo/testcshared: enable c-shared feature and test on loong64

Linux kernel on loong64 has no Dup2 syscall support, so we use Dup3 to replace it like arm64 and riscv64.

Updates #53301
Fixes #58784

Change-Id: I4e0be140a71b86f4626ed39d76cf3ac78f842018
Reviewed-on: https://go-review.googlesource.com/c/go/+/425478
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: WANG Xuerui <git@xen0n.name>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: xiaodong liu <teaofmoli@gmail.com>
Reviewed-by: WANG Xuerui <git@xen0n.name>
13 months agoregexp: add Regexp.TextMarshaler/TextUnmarshaler
Jonathan Hall [Mon, 27 Mar 2023 11:23:36 +0000 (13:23 +0200)]
regexp: add Regexp.TextMarshaler/TextUnmarshaler

Fixes #46159

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

13 months agoembed: implement openFile.ReadAt
Nuno Cruces [Tue, 11 Apr 2023 23:25:07 +0000 (23:25 +0000)]
embed: implement openFile.ReadAt

Implementation copied from testing/fstest/mapfs.go

Fixes #57803

Change-Id: I531682b50ab6663511bac41fce7614ab9197bf38
GitHub-Last-Rev: d9bcc1c0bf4d339edcdabaf4d4d67b848ad8818d
GitHub-Pull-Request: golang/go#59489
Reviewed-on: https://go-review.googlesource.com/c/go/+/483235
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
13 months agolog/slog: don't call SetDefault in examples
Jonathan Amsterdam [Wed, 5 Apr 2023 10:13:17 +0000 (06:13 -0400)]
log/slog: don't call SetDefault in examples

Replace the default Logger in some examples with a locally constructed
Logger.

Calling SetDefault changes global state that could affect other tests.
Although we could use a defer to restore the state, that clutters
the example and would not work if tests were run concurrently.

Change-Id: Ib2595c57f8e6c3e0b39b982f682ba287c2ae249d
Reviewed-on: https://go-review.googlesource.com/c/go/+/482475
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
13 months agocmd/compile: fix ir.StaticValue for ORANGE
Junwei Zuo [Wed, 12 Apr 2023 10:53:51 +0000 (18:53 +0800)]
cmd/compile: fix ir.StaticValue for ORANGE

Range statement will mutate the key and value, so we should treat them as reassigned.

Fixes #59572

Change-Id: I9c6b67d938760a0c6a1d9739f2737c67af4a3a10
Reviewed-on: https://go-review.googlesource.com/c/go/+/483855
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
13 months agolog,log/slog: get correct source line when slog calls log
Jonathan Amsterdam [Tue, 4 Apr 2023 11:08:57 +0000 (07:08 -0400)]
log,log/slog: get correct source line when slog calls log

Before slog.SetDefault is called the first time, calls to slog's
default Logger invoke log's default Logger.

Originally, this was done by calling log.Output. This caused source
line information to be wrong sometimes, because log.Output requires a
call depth and the code invoking it could not know how many calls were
between it and the original logging call (slog.Info, etc.). The line
information would be right if the default handler was called directly,
but wrong if it was wrapped by another handler. The handler has the pc
of the logging call, but it couldn't give that pc to the log package.

This CL fixes the problem by adding a function in the log package
that uses the pc instead of a call depth, and making that function
available to slog.

The simplest way to add pc functionality to the log package is to add
a pc argument to Logger.output, which uses it only if it's not zero.

To make that function visible to slog without exporting it, we store
the function in a variable that lives in the new log/internal package.

Change-Id: I0bb6daebb4abc518a7ccc4e6d2f3c1093b1d0fe4
Reviewed-on: https://go-review.googlesource.com/c/go/+/482239
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Run-TryBot: Jonathan Amsterdam <jba@google.com>

13 months agolog/syslog: report hostname mismatch error details
Michael Pratt [Wed, 12 Apr 2023 15:56:14 +0000 (11:56 -0400)]
log/syslog: report hostname mismatch error details

The existing error log in check doesn't report the got/want hostname
even though that can be the cause of the error. Log those as well.

While we're here, also report os.Hostname() errors.

For #59568.

Change-Id: Ia277f85eddc541f2e78d719bc731db24e4513754
Reviewed-on: https://go-review.googlesource.com/c/go/+/483915
Run-TryBot: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
13 months agonet/http: avoid leaking writer goroutines in tests
Bryan C. Mills [Wed, 12 Apr 2023 13:58:54 +0000 (13:58 +0000)]
net/http: avoid leaking writer goroutines in tests

In TestTransportPrefersResponseOverWriteError and TestMaxBytesHandler,
the server may respond to an incoming request without ever reading the
request body. The client's Do method will return as soon as the
server's response headers are read, but the Transport will remain
active until it notices that the server has closed the connection,
which may be arbitrarily later.

When the server has closed the connection, it will call the Close
method on the request body (if it has such a method). So we can use
that method to find out when the Transport is close enough to done for
the test to complete without interfering too much with other tests.

For #57612.
For #59526.

Change-Id: Iddc7a3b7b09429113ad76ccc1c090ebc9e1835a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/483895
Run-TryBot: Bryan Mills <bcmills@google.com>
Commit-Queue: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
13 months agonet/http: only report the first leak of each test run
Bryan C. Mills [Wed, 12 Apr 2023 14:45:44 +0000 (14:45 +0000)]
net/http: only report the first leak of each test run

We don't have a way to terminate the leaked goroutines, and we can't
wait forever for them to exit (or else we would risk timing out the
test and losing the log line describing what exactly leaked).
So we have reason to believe that they will remain leaked while we run
the next test, and we don't want the goroutines from the first leak to
generate a spurious error when the second test completes.

This also removes a racy Parallel call I added in CL 476036, which was
flagged by the race detector in the duplicate-suppression check.
(I hadn't considered the potential interaction with the leak checker.)

For #59526.
Updates #56421.

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

13 months agocmd/dist: check for errors from filepath.Glob
wangjianwen [Tue, 11 Apr 2023 02:44:55 +0000 (02:44 +0000)]
cmd/dist: check for errors from filepath.Glob

Change-Id: Ib5bcd3d1e9618d65b4d4b0895d0e40dbd76646c6
GitHub-Last-Rev: 174084ca6c67ff99a4b3628d213b2de198f74dd0
GitHub-Pull-Request: golang/go#59516
Reviewed-on: https://go-review.googlesource.com/c/go/+/483435
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

13 months agosyscall: implement Fchdir on Windows
qmuntal [Wed, 29 Mar 2023 08:28:33 +0000 (10:28 +0200)]
syscall: implement Fchdir on Windows

This CL adds support for os.File.Chdir() on Windows by implementing
syscall.Fchdir, which is internally used by Chdir.

Windows does not provide a function that sets the working directory
using a file handle, so we have to fallback to retrieving the file
handle path and then use it in SetCurrentDirectory.

Change-Id: I2ae93575e50411e5a9426ea531541958d7c9e812
Reviewed-on: https://go-review.googlesource.com/c/go/+/480135
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
13 months agoall: update vendored golang.org/x/net
Tobias Klauser [Tue, 11 Apr 2023 22:28:06 +0000 (00:28 +0200)]
all: update vendored golang.org/x/net

Pull in CL 483375. This also updates golang.org/x/sys to v0.7.0 and thus
we also need to update it to that version in cmd to keep
TestDependencyVersionsConsistent happy.

Fixes #22927

Change-Id: Ice14cd66a5c2a621b373c3d29455c75494436045
Reviewed-on: https://go-review.googlesource.com/c/go/+/483595
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

13 months agocmd/dist: add -distpack flag to build distribution archives
Russ Cox [Thu, 19 Jan 2023 22:04:07 +0000 (17:04 -0500)]
cmd/dist: add -distpack flag to build distribution archives

We want to enable others to reproduce the exact distribution archives
we are serving on go.dev/dl. Today the code for building those
archives lives in golang.org/x/build, which is fundamentally tied to
running on the Go team build infrastructure and not easy for others to
run. This CL adds a new flag -distpack to cmd/dist, usually invoked as
make.bash -distpack, to build the distribution archives using code in
the main repository that anyone can run. Starting in Go 1.21,
the Go team build infrastructure will run this instead of its current
custom code to build those archives.

The current builds are not reproducible even given identical
infrastructure, because the archives are stamped with the current
time. It is helpful to have a timestamp in the archives indicating
when the code is from, but that time needs to be reproducible.
To ensure this, the new -distpack flag extends the VERSION file to
include a time stamp, which it uses as the modification time for all
files in the archive.

The new -distpack flag is implemented by a separate program,
cmd/distpack, instead of being in cmd/dist, so that it can be compiled
by the toolchain being distributed and not the bootstrap toolchain.
Otherwise details like the exact compression algorithms might vary
from one bootstrap toolchain to another and produce non-reproducible
builds. So there is a new 'go tool distpack', but it's omitted from
the distributions themselves, just as 'go tool dist' is.

make.bash already accepts any flags for cmd/dist, including -distpack.
make.bat is less sophisticated and looks for each known flag, so this
CL adds an update to look for -distpack. The CL also changes make.bat
to accept the idiomatic Go -flagname in addition to the non-idiomatic
(for Go) --flagname. Previously it insisted on the --flag form.

I have confirmed that using make.bash -distpack produces the
identical distribution archives for windows/amd64, linux/amd64,
darwin/amd64, and darwin/arm64 whether it is run on
windows/amd64, linux/amd64, or darwin/amd64 hosts.

For #24904.

Change-Id: Ie6d69365ee3d7294d05b4f96ffb9159b41918074
Reviewed-on: https://go-review.googlesource.com/c/go/+/470676
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Carlos Amedee <amedee@google.com>
13 months agosyscall: add a Go directive "go:nocheckptr" to forkAndExecInChild1
root [Sat, 1 Apr 2023 18:36:57 +0000 (18:36 +0000)]
syscall: add a Go directive "go:nocheckptr" to forkAndExecInChild1

forkAndExecInChild1 func must not acquire any locks in child, because
they might have been locked at the time of the fork. This implies to
no rescheduling, no malloc calls, and no new stack segments.

So, doing a "checkptrAlignment" is bad here, because checkptr
functions added by the instrumentation could grow the stack, which
should not be done between fork and exec calls.

Hence using a Go directive "go:nocheckptr" to forkAndExecInChild1
func,so that the compiler should not do "checkptrAlignment" when
functions marked with "go:norace".

This race detection bug was caught in go 1.21 on s390x.
Running a "./race.bash" script from "go/src" directory failed and the
bug details are provided in issue link mentioned below.

Fixes #58785

Change-Id: I254091368b0789d886acdf26f8aa8d8f5a986b24
Reviewed-on: https://go-review.googlesource.com/c/go/+/481415
Auto-Submit: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
13 months agocmd/dist: mark wasip1/wasm as working
Johan Brandhorst-Satzkorn [Tue, 4 Apr 2023 19:25:27 +0000 (12:25 -0700)]
cmd/dist: mark wasip1/wasm as working

Now that all preceding CLs are merged, the port should
be working.

Change-Id: Ic45eaf42564ea286d0a429aa992c5ec0166945e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/482255
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>

13 months agoall: add wasip1 support
Johan Brandhorst-Satzkorn [Sun, 26 Mar 2023 00:01:38 +0000 (17:01 -0700)]
all: add wasip1 support

Fixes #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: I49b66946acc90fdf09ed9223096bfec9a1e5b923
Reviewed-on: https://go-review.googlesource.com/c/go/+/479627
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Ian Lance Taylor <iant@golang.org>

13 months agotime: add wasip1 support
Johan Brandhorst-Satzkorn [Sat, 8 Apr 2023 01:26:50 +0000 (18:26 -0700)]
time: add wasip1 support

Fixes #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: I51dabbf17b8f5540c964f90223d18457f6f9fbef
Reviewed-on: https://go-review.googlesource.com/c/go/+/483236
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

13 months agonet: add wasip1 support
Johan Brandhorst-Satzkorn [Sat, 25 Mar 2023 23:57:07 +0000 (16:57 -0700)]
net: add wasip1 support

For #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: I09a7cf33e43cb0e17ab3793c22cbad90b9e83b62
Reviewed-on: https://go-review.googlesource.com/c/go/+/479626
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

13 months agonet/http, net/internal, net/smtp: add wasip1
Johan Brandhorst-Satzkorn [Sat, 25 Mar 2023 23:38:37 +0000 (16:38 -0700)]
net/http, net/internal, net/smtp: add wasip1

For #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: Ib49b7ccabe18de544455f7d09c7d715d6564a73d
Reviewed-on: https://go-review.googlesource.com/c/go/+/479625
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

13 months agocrypto: add wasip1 support
Johan Brandhorst-Satzkorn [Sat, 25 Mar 2023 17:35:11 +0000 (10:35 -0700)]
crypto: add wasip1 support

Adds crypto/dsa, crypto/rand, x509 files and changes for the new
wasip1 port.

For #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: I9609e3d021cd7e06b813eedf5912febc52cc0f2c
Reviewed-on: https://go-review.googlesource.com/c/go/+/479624
Reviewed-by: Cherry Mui <cherryyz@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>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

13 months agocrypto/internal/nistec: update generator for re-enabled s390x asm
Ian Lance Taylor [Tue, 11 Apr 2023 18:54:46 +0000 (11:54 -0700)]
crypto/internal/nistec: update generator for re-enabled s390x asm

CL 404058 modified the generated file p256.go without modifying
the generator program. This CL updates the generator program so
that it generates the p256.go file currently in the tree.

For #52709

Change-Id: I86927a8bb84b2e17426b7ba74a86f1aba781628e
Reviewed-on: https://go-review.googlesource.com/c/go/+/483715
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>

13 months agotime: update windows zoneinfo_abbrs
Ian Lance Taylor [Tue, 11 Apr 2023 18:57:47 +0000 (11:57 -0700)]
time: update windows zoneinfo_abbrs

While running "go generate" I noticed that there has been a change.

For #58113

Change-Id: Icca349d0a100dd4b11d34e4bbcfd1aef57346db7
Reviewed-on: https://go-review.googlesource.com/c/go/+/483716
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
13 months agoall: re-run stringer
Ian Lance Taylor [Tue, 11 Apr 2023 19:01:43 +0000 (12:01 -0700)]
all: re-run stringer

Re-run all go:generate stringer commands. This mostly adds checks
that the constant values did not change, but does add new strings
for the debug/dwarf and internal/pkgbits packages.

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

13 months agogo/ast: add File.GoVersion
Russ Cox [Mon, 13 Mar 2023 21:12:40 +0000 (17:12 -0400)]
go/ast: add File.GoVersion

For #57001, compilers and others tools will need to understand that
a different Go version can be used in different files in a program,
according to the //go:build lines in those files.

This CL adds a GoVersion string field to ast.File, to allow exposing this
per-file Go version information.

For #59033.

Change-Id: I3931ea86c237983d152964f48dce498bcb1f06aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/476276
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>

13 months agogo/build/constraint: add GoVersion
Russ Cox [Mon, 13 Mar 2023 21:23:13 +0000 (17:23 -0400)]
go/build/constraint: add GoVersion

For #57001, programs need to be able to deduce the Go version
implied by a given build constraint. GoVersion determines that,
by discarding all build tags other than Go versions and computing
the minimum Go version implied by the resulting expression.

For #59033.

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

13 months agocmd/go: rewrite collectDeps to only depend on imports' deps
Michael Matloob [Mon, 10 Apr 2023 20:13:14 +0000 (16:13 -0400)]
cmd/go: rewrite collectDeps to only depend on imports' deps

Change-Id: I0cac9f32855e49e9899709a2f4421083aa0e75cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/483515
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
13 months agoruntime: filter i/o async entries using completion key on windows
Will Hawkins [Wed, 5 Apr 2023 07:15:56 +0000 (03:15 -0400)]
runtime: filter i/o async entries using completion key on windows

In the case where a user program requests overlapped I/O directly on a
handlethat is managed by the runtime, it is possible that
runtime.netpoll will attempt to dereference a pointer with an invalid
value. This CL prevents the runtime from accessing the invalid pointer
value by adding a special key to each overlapped I/O operation that it
creates.

Fixes #58870

Co-authored-by: quimmuntal@gmail.com
Change-Id: Ib58ee757bb5555efba24c29101fc6d1a0dedd61a
Reviewed-on: https://go-review.googlesource.com/c/go/+/482495
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

13 months agocmd/asm,cmd/internal/obj/x86: add RDPID instruction to x86 assembler
Joel Sing [Thu, 6 Apr 2023 20:15:59 +0000 (06:15 +1000)]
cmd/asm,cmd/internal/obj/x86: add RDPID instruction to x86 assembler

Add support for the Read Processor ID (RDPID) instruction to the x86
assembler. This returns the current logical processor's ID in the
specified register, as a faster alternative to RDTSCP.

Fixes #56525

Change-Id: I43482e42431dfc385ce2e7f6d44b9746b0cc4548
Reviewed-on: https://go-review.googlesource.com/c/go/+/482955
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
13 months agonet: allow TestDialListenerAddr without an external network
Bryan C. Mills [Tue, 11 Apr 2023 16:26:53 +0000 (16:26 +0000)]
net: allow TestDialListenerAddr without an external network

As of CL 482163, this test now works when only a loopback network is
available.

Updates #59497.

Change-Id: I32be4b74bbc663eb109763ea19d79f22c63f50ae
Reviewed-on: https://go-review.googlesource.com/c/go/+/483696
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>

13 months agodoc: add missing oxford comma in Constants
Daniel Frederick Crisman [Mon, 10 Apr 2023 23:14:56 +0000 (23:14 +0000)]
doc: add missing oxford comma in Constants

In the language specification under "Constants" the lists matching default
types to untyped contstant types is missing an Oxford comma in the first
list. I found a number of other places in the spec and #23442 that use the
Oxford comma to support its use.

Add missing Oxford comma in Constants default type list.

Change-Id: I4562d692610334bc82452db076145d2414617a04
GitHub-Last-Rev: 8acdb60d6e255f73fdeb908d2540d4ee35db3fd7
GitHub-Pull-Request: golang/go#59528
Reviewed-on: https://go-review.googlesource.com/c/go/+/483555
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@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>

13 months agocmd/go/internal/cache: return and check errors from Trim
Bryan C. Mills [Thu, 6 Apr 2023 12:31:57 +0000 (12:31 +0000)]
cmd/go/internal/cache: return and check errors from Trim

It's fine to ignore errors when reading trim.txt, since it might not
exist or might be corrupted. However, if we encounter an error in
writing the file, we will end up trimming again at every cmd/go
invocation, which will cause invocations to become progressively
slower (because each command will check more and more cache files for
trimming).

Although that situation would not cause the output of any 'go' command
to be invalid, it still seems better to escalate the problem to the
user to be fixed instead of proceeding in a degraded state.

Returning an explicit error also allows TestCacheTrim to skip if the
Trim error indicates that a required operation (in this case, file
locking) is not supported by the platform or filesystem.

For #58141.
Updates #35220.
Updates #26794.

Change-Id: Iedb94bff4544fd9914f5ac779a783a116372c80f
Reviewed-on: https://go-review.googlesource.com/c/go/+/482795
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Bryan Mills <bcmills@google.com>

13 months agocmd/internal/obj/loong64, cmd/internal/objabi, cmd/link: add support for --buildmode...
limeidan [Thu, 25 Aug 2022 03:13:10 +0000 (11:13 +0800)]
cmd/internal/obj/loong64, cmd/internal/objabi, cmd/link: add support for --buildmode=c-shared on loong64

Updates #53301
Updates #58784

Change-Id: Ifcb40871f609531dfd8b568db9ac14da9b451742
Reviewed-on: https://go-review.googlesource.com/c/go/+/425476
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Run-TryBot: WANG Xuerui <git@xen0n.name>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Reviewed-by: WANG Xuerui <git@xen0n.name>
13 months agoRevert "go/printer: reuse go/token.FileSet.PositionFor calls in setPos"
Than McIntosh [Tue, 11 Apr 2023 14:15:36 +0000 (14:15 +0000)]
Revert "go/printer: reuse go/token.FileSet.PositionFor calls in setPos"

This reverts commit http://go.dev/cl/461739

Reason for revert: Causes longtest failures due to odd formatting.

Change-Id: I7e31ff107e730b6d667866ea7718bc8632760422
Reviewed-on: https://go-review.googlesource.com/c/go/+/483676
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

13 months agoruntime,cmd/internal/obj/ppc64: cleanup ppc64le runtime.racecallbackthunk
Paul E. Murphy [Mon, 13 Mar 2023 22:02:15 +0000 (17:02 -0500)]
runtime,cmd/internal/obj/ppc64: cleanup ppc64le runtime.racecallbackthunk

Update to use the common macros to ensure all ELFv2 callee-save registers
are saved properly when transitioning from ELFv2 to Go calling/stack
conventions. Simplify the inlined Go function call, and remove the asm
hacks which inhibited implicit stack frame management.

Change-Id: Iee118a4069962a791436c6fe19370e1929404a8d
Reviewed-on: https://go-review.googlesource.com/c/go/+/479795
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

13 months agoos: adjust wait6/waitid comment for netbsd
Tobias Klauser [Sun, 9 Apr 2023 11:39:12 +0000 (13:39 +0200)]
os: adjust wait6/waitid comment for netbsd

CL 431855 changed (*Process).blockUntilWaitable on netbsd to use wait6
again.

Update #48789

Change-Id: I948f5445a44ab2e82c02560480a2a244d2b5f473
Reviewed-on: https://go-review.googlesource.com/c/go/+/483396
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
13 months agodebug/elf: avoid decompress of section twice
Meng Zhuo [Sun, 2 Apr 2023 12:01:28 +0000 (20:01 +0800)]
debug/elf: avoid decompress of section twice

In rare cases, elf will get a corrupted section starts with 0x1,
which happens to be COMPRESS_ZLIB that causing decompress twice.
This CL drops sectionData decompress data after open section.

Fixes #59208

Change-Id: I7999a55868b3b3481509e1ac35985f7580f0f688
Reviewed-on: https://go-review.googlesource.com/c/go/+/480895
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: M Zhuo <mzh@golangcn.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
13 months agocmd/internal/obj/loong64: auto-align loop heads to 16-byte boundaries
WANG Xuerui [Tue, 28 Mar 2023 13:10:16 +0000 (21:10 +0800)]
cmd/internal/obj/loong64: auto-align loop heads to 16-byte boundaries

CL 479816 took care of loops in hand-written assembly, but did not
account for those written in Go, that may become performance-sensitive
as well.

In this patch, all loop heads are automatically identified and aligned
to 16-byte boundaries, by inserting a synthetic `PCALIGN $16` before
them. "Loop heads" are defined as targets of backward branches.

While at it, tweak some of the local comments so the flow is hopefully
clearer.

Because LoongArch instructions are all 32 bits long, at most 3 NOOPs
can be inserted for each target Prog. This may sound excessive, but
benchmark results indicate the current approach is overall profitable
anyway.

Benchmark results on Loongson 3A5000 (LA464):

goos: linux
goarch: loong64
pkg: test/bench/go1
                      │  CL 479816  │              this CL               │
                      │   sec/op    │   sec/op     vs base               │
BinaryTree17             14.10 ± 1%    14.06 ± 1%       ~ (p=0.280 n=10)
Fannkuch11               3.579 ± 0%    3.419 ± 0%  -4.45% (p=0.000 n=10)
FmtFprintfEmpty         94.73n ± 0%   94.44n ± 0%  -0.31% (p=0.000 n=10)
FmtFprintfString        151.9n ± 0%   149.1n ± 0%  -1.84% (p=0.000 n=10)
FmtFprintfInt           158.3n ± 0%   155.2n ± 0%  -1.96% (p=0.000 n=10)
FmtFprintfIntInt        241.4n ± 0%   235.4n ± 0%  -2.49% (p=0.000 n=10)
FmtFprintfPrefixedInt   320.2n ± 0%   314.7n ± 0%  -1.73% (p=0.000 n=10)
FmtFprintfFloat         414.3n ± 0%   398.7n ± 0%  -3.77% (p=0.000 n=10)
FmtManyArgs             949.9n ± 0%   929.8n ± 0%  -2.12% (p=0.000 n=10)
GobDecode               15.24m ± 0%   15.30m ± 0%  +0.38% (p=0.035 n=10)
GobEncode               18.10m ± 2%   17.59m ± 1%  -2.81% (p=0.002 n=10)
Gzip                    429.9m ± 0%   421.5m ± 0%  -1.97% (p=0.000 n=10)
Gunzip                  88.31m ± 0%   87.39m ± 0%  -1.04% (p=0.000 n=10)
HTTPClientServer        85.71µ ± 0%   87.24µ ± 0%  +1.79% (p=0.000 n=10)
JSONEncode              19.74m ± 0%   18.55m ± 0%  -6.00% (p=0.000 n=10)
JSONDecode              78.60m ± 1%   77.93m ± 0%  -0.84% (p=0.000 n=10)
Mandelbrot200           7.208m ± 0%   7.217m ± 0%       ~ (p=0.481 n=10)
GoParse                 7.616m ± 1%   7.630m ± 2%       ~ (p=0.796 n=10)
RegexpMatchEasy0_32     133.0n ± 0%   134.1n ± 0%  +0.83% (p=0.000 n=10)
RegexpMatchEasy0_1K     1.362µ ± 0%   1.364µ ± 0%  +0.15% (p=0.000 n=10)
RegexpMatchEasy1_32     161.8n ± 0%   163.7n ± 0%  +1.17% (p=0.000 n=10)
RegexpMatchEasy1_1K     1.497µ ± 0%   1.497µ ± 0%       ~ (p=1.000 n=10)
RegexpMatchMedium_32    1.420µ ± 0%   1.446µ ± 0%  +1.83% (p=0.000 n=10)
RegexpMatchMedium_1K    42.25µ ± 0%   42.53µ ± 0%  +0.65% (p=0.000 n=10)
RegexpMatchHard_32      2.108µ ± 0%   2.116µ ± 0%  +0.38% (p=0.000 n=10)
RegexpMatchHard_1K      62.65µ ± 0%   63.23µ ± 0%  +0.93% (p=0.000 n=10)
Revcomp                  1.192 ± 0%    1.198 ± 0%  +0.55% (p=0.000 n=10)
Template                115.6m ± 2%   116.9m ± 1%       ~ (p=0.075 n=10)
TimeParse               418.1n ± 1%   414.7n ± 0%  -0.81% (p=0.000 n=10)
TimeFormat              517.9n ± 0%   513.7n ± 0%  -0.81% (p=0.000 n=10)
geomean                 103.5µ        102.6µ       -0.79%

                     │  CL 479816   │               this CL               │
                     │     B/s      │     B/s       vs base               │
GobDecode              48.04Mi ± 0%   47.86Mi ± 0%  -0.38% (p=0.035 n=10)
GobEncode              40.44Mi ± 2%   41.61Mi ± 1%  +2.89% (p=0.001 n=10)
Gzip                   43.04Mi ± 0%   43.91Mi ± 0%  +2.02% (p=0.000 n=10)
Gunzip                 209.6Mi ± 0%   211.8Mi ± 0%  +1.05% (p=0.000 n=10)
JSONEncode             93.76Mi ± 0%   99.75Mi ± 0%  +6.39% (p=0.000 n=10)
JSONDecode             23.55Mi ± 1%   23.75Mi ± 0%  +0.85% (p=0.000 n=10)
GoParse                7.253Mi ± 1%   7.238Mi ± 2%       ~ (p=0.698 n=10)
RegexpMatchEasy0_32    229.4Mi ± 0%   227.6Mi ± 0%  -0.82% (p=0.000 n=10)
RegexpMatchEasy0_1K    717.3Mi ± 0%   716.2Mi ± 0%  -0.15% (p=0.000 n=10)
RegexpMatchEasy1_32    188.6Mi ± 0%   186.4Mi ± 0%  -1.13% (p=0.000 n=10)
RegexpMatchEasy1_1K    652.2Mi ± 0%   652.3Mi ± 0%  +0.01% (p=0.005 n=10)
RegexpMatchMedium_32   21.49Mi ± 0%   21.11Mi ± 0%  -1.73% (p=0.000 n=10)
RegexpMatchMedium_1K   23.11Mi ± 0%   22.96Mi ± 0%  -0.62% (p=0.000 n=10)
RegexpMatchHard_32     14.48Mi ± 0%   14.42Mi ± 0%  -0.40% (p=0.000 n=10)
RegexpMatchHard_1K     15.59Mi ± 0%   15.44Mi ± 0%  -0.98% (p=0.000 n=10)
Revcomp                203.4Mi ± 0%   202.3Mi ± 0%  -0.55% (p=0.000 n=10)
Template               16.00Mi ± 2%   15.83Mi ± 1%       ~ (p=0.078 n=10)
geomean                60.72Mi        60.89Mi       +0.29%

The slight regression on the Regexp cases is likely because the previous
numbers are just coincidental: indeed, large regressions or improvements
(of roughly ±10%) happen with definitely irrelevant changes during
development. This CL should (hopefully) bring such random performance
fluctuations down a bit.

Change-Id: I8bdda6e65336da00d4ad79650937b3eeb9db0e7c
Reviewed-on: https://go-review.googlesource.com/c/go/+/479817
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: WANG Xuerui <git@xen0n.name>

13 months agogo/printer: reuse go/token.FileSet.PositionFor calls in setPos
Daniel Martí [Thu, 12 Jan 2023 18:29:28 +0000 (18:29 +0000)]
go/printer: reuse go/token.FileSet.PositionFor calls in setPos

setPos is called for most nodes, and in a number of cases,
the position is already the same.
PositionFor is a relatively expensive call,
as it needs to "unpack" a token.Pos into a token.Position.

If we can tell that the position is the same in a cheap way,
we can then avoid calling setPos and PositionFor.
Luckily, we can get the position's offset within the file,
and it doesn't involve the relatively expensive unpacking.

name          old time/op    new time/op    delta
PrintFile-16    4.79ms ± 1%    4.36ms ± 1%  -8.88%  (p=0.008 n=5+5)

name          old speed      new speed      delta
PrintFile-16  10.8MB/s ± 1%  11.9MB/s ± 1%  +9.73%  (p=0.008 n=5+5)

name          old alloc/op   new alloc/op   delta
PrintFile-16     106kB ± 1%     106kB ± 1%    ~     (p=0.167 n=5+5)

name          old allocs/op  new allocs/op  delta
PrintFile-16     2.42k ± 0%     2.42k ± 0%    ~     (all equal)

This does assume that the positions of a node being printed are all
within a file, as go/token.Position.Offset is relative to each file.
This seems like a perfectly fine assumption to make right now,
as the largest node which can be printed is an *ast.File.

Change-Id: I2ae55f507ba8ba9f280898c9c8e01c994d9b2a26
Reviewed-on: https://go-review.googlesource.com/c/go/+/461739
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
13 months agocmd/compile: split DIVV/DIVVU op on loong64
Wayne Zuo [Thu, 2 Mar 2023 07:55:03 +0000 (15:55 +0800)]
cmd/compile: split DIVV/DIVVU op on loong64

Previously, we need calculate both quotient and remainder together.
However, in most cases, only one result is needed. By separating these
instructions, we can save one instruction in most cases.

Change-Id: I0a2d4167cda68ab606783ba1aa2720ede19d6b53
Reviewed-on: https://go-review.googlesource.com/c/go/+/475315
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
13 months agodoc: fix "are" to "or" in core types
cui fliter [Sun, 9 Apr 2023 14:51:47 +0000 (22:51 +0800)]
doc: fix "are" to "or" in core types

Fixes #59506

Change-Id: I2f8b92e93b706b061ca0eb0bd52e5cf798ce9ede
Reviewed-on: https://go-review.googlesource.com/c/go/+/483358
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

13 months agocmd/internal/obj/arm64: improve comment and signature of pcAlignPadLength
WANG Xuerui [Fri, 7 Apr 2023 18:06:18 +0000 (02:06 +0800)]
cmd/internal/obj/arm64: improve comment and signature of pcAlignPadLength

The function just calculates the number of needed padding bytes,
instead of actually carrying out the alignment operation. And it has
the context argument at the end of the argument list, while contexts
idiomatically come first. Indeed, this is the only case in
cmd/internal/obj where ctxt is not the only argument and does not come
first.

Fix those two nits; no functional change intended.

Suggested by Ian during review of CL 479815 (that introduces a copy of
this helper into the loong64 port).

Change-Id: Ieb221ead23282abe6e04804d537e1234c7ab21d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/483155
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
14 months agonet: avoid opening an external port in TestDialListenerAddr
Bryan C. Mills [Mon, 10 Apr 2023 13:59:12 +0000 (13:59 +0000)]
net: avoid opening an external port in TestDialListenerAddr

The behavior in #18806 can be tested with a localhost-only port,
provided that we're willing to assume what format the listener would
report for an external dual-stack port.

Fixes #59497.

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

14 months agocmd/doc: format field doc comments when printing entire struct
Ian Lance Taylor [Fri, 7 Apr 2023 02:36:01 +0000 (19:36 -0700)]
cmd/doc: format field doc comments when printing entire struct

cmd/doc passes structs to go/format, but that means that comments
on fields within those structs don't look like what cmd/doc prints
when asked for a struct field directly. Tweak the field comments
so that they look the same either way.

Fixes #56592

Change-Id: I198cb7a58e3d8558406c386072c630332f91c6b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/483055
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>