]> Cypherpunks repositories - gostls13.git/log
gostls13.git
2 months agoruntime: handle system goroutines later in goroutine profiling
Michael Anthony Knyszek [Tue, 10 Jun 2025 16:42:59 +0000 (16:42 +0000)]
runtime: handle system goroutines later in goroutine profiling

Before CL 650697, there was only one system goroutine that could
dynamically change between being a user goroutine and a system
goroutine, and that was the finalizer/cleanup goroutine. In goroutine
profiles, it was handled explicitly. It's status would be checked during
the first STW, and its stack would be recorded. This let the goroutine
profiler completely ignore system goroutines once the world was started
again.

CL 650697 added dedicated cleanup goroutines (there may be more than
one), and with this, the logic for finalizer goroutines no longer
scaled. In that CL, I let the isSystemGoroutine check be dynamic and
dropped the special case, but this was based on incorrect assumptions.
Namely, it's possible for the scheduler to observe, for example, the
finalizer goroutine as a system goroutine and ignore it, but then later
the goroutine profiler itself sees it as a user goroutine. At that point
it's too late and already running. This violates the invariant of the
goroutine profile that all goroutines are handled by the profiler before
they start executing. In practice, the result is that the goroutine
profiler can crash when it checks this invariant (not checking the
invariant means racily reading goroutine stack memory).

The root cause of the problem is that these system goroutines do not
participate in the goroutine profiler's state machine. Normally, when
profiling, goroutines transition from 'absent' to 'in-progress' to
'satisfied'. However with system goroutines, the state machine is
ignored entirely. They always stay in the 'absent' state. This means
that if a goroutine transitions from system to user, it is eligible for
a profile record when it shouldn't be. That transition shouldn't be
allowed to occur with respect to the goroutine profiler, because the
goroutine profiler is trying to snapshot the state of every goroutine.

The fix to this problem is simple: don't ignore system goroutines. Let
them participate in the goroutine profile state machine. Instead, decide
whether or not to record the stack after the goroutine has been acquired
for goroutine profiling. This means if the scheduler observes the
finalizer goroutine as a system goroutine, it will get promoted in the
goroutine profiler's state machine, and no other part of the goroutine
profiler will observe the goroutine again. Simultaneously, the
stack record for the goroutine will be correctly skipped.

Fixes #74090.

Change-Id: Icb9a164a033be22aaa942d19e828e895f700ca74
Reviewed-on: https://go-review.googlesource.com/c/go/+/680477
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agotesting/synctest, runtime: avoid panic when using linker-alloc WG from bubble
Damien Neil [Thu, 5 Jun 2025 20:47:06 +0000 (13:47 -0700)]
testing/synctest, runtime: avoid panic when using linker-alloc WG from bubble

We associate WaitGroups with synctest bubbles by attaching a
special to the WaitGroup. It is not possible to attach a special
to a linker-allocated value, such as:

    var wg sync.WaitGroup

Avoid panicking when accessing a linker-allocated WaitGroup
from a bubble. We have no way to associate these WaitGroups
with a bubble, so just treat them as always unbubbled.
This is probably fine, since the WaitGroup was always
created outside the bubble in this case.

Fixes #74005

Change-Id: Ic71514b0b8d0cecd62e45cc929ffcbeb16f54a55
Reviewed-on: https://go-review.googlesource.com/c/go/+/679695
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agointernal/trace: pass GOTRACEBACK=crash to testprogs
Michael Anthony Knyszek [Mon, 9 Jun 2025 22:54:54 +0000 (22:54 +0000)]
internal/trace: pass GOTRACEBACK=crash to testprogs

The failures in #70310 are hard to decipher. The cases where the lock is
being held either don't really make sense (the STW failures) or the
goroutine that fails is 'running on another thread' and we don't get a
stack trace. In fact, such a goroutine exists even in the STW cases.
Since reproducing this is going to be hard (very few failures over a 2
year span) let's set GOTRACEBACK=crash for these testprogs so next time
it happens we can see why.

For #70310.

Change-Id: I81a780aa82b173d42973f06911cb243f33352be1
Reviewed-on: https://go-review.googlesource.com/c/go/+/680476
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
2 months agoos: do not follow dangling symlinks in Root when O_CREATE|O_EXCL on AIX
Damien Neil [Fri, 30 May 2025 21:05:10 +0000 (14:05 -0700)]
os: do not follow dangling symlinks in Root when O_CREATE|O_EXCL on AIX

OpenFile with O_CREATE|O_EXCL should not follow dangling symlinks.
On AIX it does, because AIX's openat(2) apparently returns ELOOP
in this case. Most Unices return EEXIST.

Ensure that we never follow symlinks in the final component of
the path when opening a file with O_CREATE|O_EXCL.

Fixes #73924

Change-Id: I869afb7faefccb0bb29d155553a7d7e5be80467d
Reviewed-on: https://go-review.googlesource.com/c/go/+/677735
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2 months agonet/http: make the zero value of CrossOriginProtection work
Austin Clements [Tue, 10 Jun 2025 16:26:03 +0000 (12:26 -0400)]
net/http: make the zero value of CrossOriginProtection work

Currently, CrossOriginProtection must be constructed by
NewCrossOriginProtection. If you try to use the zero value, most
methods will panic with a nil dereference.

This CL makes CrossOriginProtection use on-demand initialization
instead, so the zero value has the same semantics as the value
currently returned by NewCrossOriginProtection. Now,
NewCrossOriginProtection just constructs the zero value.

We keep NewCrossOriginProtection by analogy to NewServeMux.

Updates #73626
Fixes #74089.

Change-Id: Ia80183eb6bfdafb0e002271c0b25c2d6230a159a
Reviewed-on: https://go-review.googlesource.com/c/go/+/680396
Auto-Submit: Austin Clements <austin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2 months agocmd/dist: only install necessary tools when doing local test
Michael Matloob [Tue, 10 Jun 2025 15:12:10 +0000 (11:12 -0400)]
cmd/dist: only install necessary tools when doing local test

Instead of installing all of cmd, install only the tools that cmd/dist
would normally install.

Also, remove the addition of the buildid tool to the list of commands in
the toolchain in debug mode. The uses of buildid were removed in CL 451360.

For #71867

Change-Id: I062909d23c18294aa23ea43b9f7eeb69bfa80c8c
Reviewed-on: https://go-review.googlesource.com/c/go/+/680475
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Matloob <matloob@google.com>

2 months agoruntime: don't do a direct G handoff in semrelease on systemstack
Michael Anthony Knyszek [Mon, 9 Jun 2025 21:45:33 +0000 (21:45 +0000)]
runtime: don't do a direct G handoff in semrelease on systemstack

semrelease is safe to call on the system stack (since it just readies
goroutines) except for the fact that it might perform a direct G
handoff and call into the scheduler. If handoff is set to false this is
exceptionally rare, but could happen, and has happened for the trace
reader goroutine which releases a trace.doneSema.

Fixes #73469.

Change-Id: I37ece678bc4721bbb6e5879d74daac762b7d742a
Reviewed-on: https://go-review.googlesource.com/c/go/+/680315
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
2 months agoall.{bash,rc}: use "../bin/go tool dist" instead of "%GOTOOLDIR%/dist" print build...
Guoqi Chen [Mon, 9 Jun 2025 09:04:55 +0000 (17:04 +0800)]
all.{bash,rc}: use "../bin/go tool dist" instead of "%GOTOOLDIR%/dist" print build info

After CL 677558, when running all.bash, the binaries of commands such
as dist, nm, and pprof are no longer built by default, so when running
all.bash, "./all.bash: line 13: /home/golang/pkg/tool/linux_amd64/dist:
No such file or directory" will be printed, and the return result of
the all.bash script is non-zero.

Although the "dist" command  won't be installed in $GOTOOLDIR anymore,
but it will be built and cached, and ../bin/go tool dist will reuse the
cached binary.

For #71867

Change-Id: I802eeafdb866e7d80c42da3e0955bb32def7b037
Reviewed-on: https://go-review.googlesource.com/c/go/+/680135
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2 months agocmd/compile/internal/ssa: fix PPC64 merging of (AND (S[RL]Dconst ...)
Paul Murphy [Wed, 4 Jun 2025 13:51:11 +0000 (08:51 -0500)]
cmd/compile/internal/ssa: fix PPC64 merging of (AND (S[RL]Dconst ...)

CL 622236 forgot to check the mask was also a 32 bit rotate mask. Add
a modified version of isPPC64WordRotateMask which valids the mask is
contiguous and fits inside a uint32.

I don't this is possible when merging SRDconst, the first check should
always reject such combines. But, be extra careful and do it there
too.

Fixes #73153

Change-Id: Ie95f74ec5e7d89dc761511126db814f886a7a435
Reviewed-on: https://go-review.googlesource.com/c/go/+/679775
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Jayanth Krishnamurthy <jayanth.krishnamurthy@ibm.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
2 months agoruntime: use small struct TestSynctest to ensure cleanups run
Damien Neil [Fri, 6 Jun 2025 19:59:04 +0000 (12:59 -0700)]
runtime: use small struct TestSynctest to ensure cleanups run

Finalizers and cleanup funcs weren't running on the windows-arm64
builder. Put finalizers/cleanups on a small struct containing a pointer
rather than an *int, which fixes the problem.

Also uncomment a synctest.Wait that was accidentally commented out.

Fixes #73977

Change-Id: Ia6f18d74d6fccf2c5a9222317977c7458d67f158
Reviewed-on: https://go-review.googlesource.com/c/go/+/679696
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2 months agoruntime: clarify stack traces for bubbled goroutines
Damien Neil [Thu, 5 Jun 2025 21:21:47 +0000 (14:21 -0700)]
runtime: clarify stack traces for bubbled goroutines

Use the synctest bubble ID to identify bubbles in traces,
rather than the goroutine ID of the bubble's root goroutine.

Some waitReasons include a "(synctest)" suffix to distinguish
a durably blocking state from a non-durable one. For example,
"chan send" vs. "chan send (synctest)". Change this suffix
to "(durable)".

Always print a "(durable)" sufix for the state of durably
blocked bubbled goroutines. For example, print "sleep (durable)".

Drop the "[not] durably blocked" text from goroutine states,
since this is now entirely redundant with the waitReason.

Old:
  goroutine 8 [chan receive (synctest), synctest bubble 7, durably blocked]:
  goroutine 9 [select (no cases), synctest bubble 7, durably blocked]:

New:
  goroutine 8 [chan receive (durable), synctest bubble 1]:
  goroutine 9 [select (no cases) (durable), synctest bubble 1]:

Change-Id: I89112efb25150a98a2954f54d1910ccec52a5824
Reviewed-on: https://go-review.googlesource.com/c/go/+/679376
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2 months agoruntime: return a different bubble deadlock error when main goroutine is done
Damien Neil [Thu, 5 Jun 2025 20:55:35 +0000 (13:55 -0700)]
runtime: return a different bubble deadlock error when main goroutine is done

The synctest.Test function waits for all goroutines in a bubble to
exit before returning. If there is ever a point when all goroutines
in a bubble are durably blocked, it panics and reports a deadlock.

Panic with a different message depending on whether the bubble's
main goroutine has returned or not. The main goroutine returning
stops the bubble clock, so knowing whether it is running or not
is useful debugging information.

The new panic messages are:
deadlock: all goroutines in bubble are blocked
deadlock: main bubble goroutine has exited but blocked goroutines remain

Change-Id: I94a69e79121c272d9c86f412c1c9c7de57ef27ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/679375
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agocmd/internal/doc: increase version of pkgsite doc command that's run
Michael Matloob [Mon, 9 Jun 2025 15:10:53 +0000 (11:10 -0400)]
cmd/internal/doc: increase version of pkgsite doc command that's run

This will incorporate the changes in CL 675957, CL 677596, and
CL 675958.

For #73848

Change-Id: Ie3d313e055a36b5b7aafec4a7462a1ced8a9f923
Reviewed-on: https://go-review.googlesource.com/c/go/+/680176
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agocmd/compile: relax reshaping condition
Cuong Manh Le [Tue, 3 Jun 2025 14:35:20 +0000 (21:35 +0700)]
cmd/compile: relax reshaping condition

CL 641955 changes the Unified IR reader to not doing shapify when
reading reshaping expression. However, this condition only matters with
pointer type shaping, which will lose the original type, causes the
reshaping ends up with a completely different type.

This CL relaxes the condition, always allow non-pointer types shaping.

Updates #71184
Fixes #73947

Change-Id: Ib0bafd8932c52d99266f311b6cbfc75c00383f9b
Reviewed-on: https://go-review.googlesource.com/c/go/+/678335
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
2 months agolog/slog: fix level doc on handlers
Jonathan Amsterdam [Sun, 8 Jun 2025 12:49:25 +0000 (08:49 -0400)]
log/slog: fix level doc on handlers

Fixed doc on {JSON,Text}Handler.Handle: the level is never omitted.

Fixes #73943.

Change-Id: Ia470cbe5d713ab18dd80eeea1c0ab8f5e6d30f3f
Reviewed-on: https://go-review.googlesource.com/c/go/+/680055
Auto-Submit: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
2 months agoruntime: check for gsignal in racecall on loong64
Guoqi Chen [Thu, 5 Jun 2025 11:23:55 +0000 (19:23 +0800)]
runtime: check for gsignal in racecall on loong64

This issue has been fixed for amd64, arm64 and other platforms
in CL 643875, but it was missed when the race support was
submitted for loong64.

Fixes #71395.

Change-Id: I678f381e868214f1b3399be43187db49e1660933
Reviewed-on: https://go-review.googlesource.com/c/go/+/679055
Reviewed-by: Meidan Li <limeidan@loongson.cn>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
2 months agoos/signal: doc link to syscall.EPIPE
Olivier Mengué [Thu, 24 Apr 2025 14:46:44 +0000 (16:46 +0200)]
os/signal: doc link to syscall.EPIPE

Add godoc link for EPIPE error.

Change-Id: I5df35f700684510328f92bb5d4946c5123ba5f2c
Reviewed-on: https://go-review.googlesource.com/c/go/+/667757
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agoall: update vendored dependencies [generated]
Carlos Amedee [Wed, 4 Jun 2025 19:35:31 +0000 (15:35 -0400)]
all: update vendored dependencies [generated]

The Go 1.25 RC is due soon. This is the time to once again update all
golang.org/x/... module versions that contribute packages to the std and
cmd modules in the standard library to latest master versions.

For #36905.

[git-generate]
go install golang.org/x/build/cmd/updatestd@latest
go install golang.org/x/tools/cmd/bundle@latest
updatestd -goroot=$(pwd) -branch=master

cat << EOF | patch
diff --git a/src/cmd/go/testdata/script/test_json_build.txt b/src/cmd/go/testdata/script/test_json_build.txt
index df8863ae03..2a572ace72 100644
--- a/src/cmd/go/testdata/script/test_json_build.txt
+++ b/src/cmd/go/testdata/script/test_json_build.txt
@@ -56,7 +56,7 @@ stdout '"Action":"fail","Package":"m/cycle/p","Elapsed":.*,"FailedBuild":"m/cycl
 ! go test -json -o=$devnull ./veterror
 stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"# m/veterror\\n"'
 stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"# \[m/veterror\]\\n"'
-stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"veterror(/|\\\\)main_test.go:9:9: fmt.Printf format %s reads arg #1, but call has 0 args\\n"'
+stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"veterror(/|\\\\)main_test.go:9:21: fmt.Printf format %s reads arg #1, but call has 0 args\\n"'
 stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-fail"'
 stdout '"Action":"start","Package":"m/veterror"'
 stdout '"Action":"output","Package":"m/veterror","Output":"FAIL\\tm/veterror \[build failed\]\\n"'
EOF

Change-Id: I6a8d35acdeab90c3bbd6395b8b1abb021673b5cb
Reviewed-on: https://go-review.googlesource.com/c/go/+/678556
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2 months agonet/http: strip sensitive proxy headers from redirect requests
Neal Patel [Wed, 21 May 2025 18:11:44 +0000 (14:11 -0400)]
net/http: strip sensitive proxy headers from redirect requests

Similarly to Authentication entries, Proxy-Authentication entries should be stripped to ensure sensitive information is not leaked on redirects outside of the original domain.

https://fetch.spec.whatwg.org/#authentication-entries

Thanks to Takeshi Kaneko (GMO Cybersecurity by Ierae, Inc.) for reporting this issue.

For #73816
Fixes CVE-2025-4673

Change-Id: Ied7b641f6531f1d340ccba3c636d3c30dd5547d9
Reviewed-on: https://go-review.googlesource.com/c/go/+/679257
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2 months agoruntime: make bubbled timers more consistent with unbubbled
Damien Neil [Mon, 2 Jun 2025 16:26:27 +0000 (09:26 -0700)]
runtime: make bubbled timers more consistent with unbubbled

This CL makes two changes to reduce the predictability
with which bubbled timers fire.

When asynctimerchan=0 (the default), regular timers with an associated
channel are only added to a timer heap when some channel operation
is blocked on that channel. This allows us to garbage collect
unreferenced, unstopped timers. Timers in a synctest bubble, in
contrast, are always added to the bubble's timer heap.

This CL changes bubbled timers with a channel to be handled the
same as unbubbled ones, adding them to the bubble's timer heap only
when some channel operation is blocked on the timer's channel.
This permits unstopped bubbled timers to be garbage collected,
but more importantly it makes all timers past their deadline
behave identically, regardless of whether they are in a bubble.

This CL also changes timer scheduling to execute bubbled timers
immediately when possible rather than adding them to a heap.
Timers in a bubble's heap are executed when the bubble is idle.
Executing timers immediately avoids creating a predictable
order of execution.

For #73850
Fixes #73934

Change-Id: If82e441546408f780f6af6fb7f6e416d3160295d
Reviewed-on: https://go-review.googlesource.com/c/go/+/678075
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agoRevert "cmd/compile: Enable inlining of tail calls"
Cherry Mui [Tue, 3 Jun 2025 19:44:32 +0000 (15:44 -0400)]
Revert "cmd/compile: Enable inlining of tail calls"

This reverts CL 650455 and CL 655816.

Reason for revert: it causes #73747. Properly fixing it gets into
trickiness with defer/recover, wrapper, and inlining. We're late
in the Go 1.25 release cycle.

Fixes #73747.

Change-Id: Ifb343d522b18fec3fec73a7c886678032ac8e4df
Reviewed-on: https://go-review.googlesource.com/c/go/+/678575
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2 months agocmd/trace: handle Sync event at the beginning of the trace
Michael Anthony Knyszek [Tue, 3 Jun 2025 20:30:43 +0000 (20:30 +0000)]
cmd/trace: handle Sync event at the beginning of the trace

Currently the code assumes that there's no Sync event at the start of
the trace, but this hasn't been correct for some time. Count Syncs and
look for at least one instead of looking for zero.

Fixes #73962.

Change-Id: I2b4199a21c699c5b50b3d5add37dc46a515108c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/678555
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2 months agoruntime: reduce per-P memory footprint when greenteagc is disabled
Michael Anthony Knyszek [Tue, 3 Jun 2025 19:28:00 +0000 (19:28 +0000)]
runtime: reduce per-P memory footprint when greenteagc is disabled

There are two additional sources of memory overhead per P that come from
greenteagc. One is for ptrBuf, but on platforms other than Windows it
doesn't actually cost anything due to demand-paging (Windows also
demand-pages, but the memory is 'committed' so it still counts against
OS RSS metrics). The other is for per-sizeclass scan stats. However when
greenteagc is disabled, most of these scan stats are completely unused.

The worst-case memory overhead from these two sources is relatively
small (about 10 KiB per P), but for programs with a small memory
footprint running on a machine with a lot of cores, this can be
significant (single-digit percent).

This change does two things. First, it puts ptrBuf initialization behind
the greenteagc experiment, so now that memory is never allocated by
default. Second, it abstracts the implementation details of scan stat
collection and emission, such that we can have two different
implementations depending on the build tag. This lets us remove all the
unused stats when the greenteagc experiment is disabled, reducing the
memory overhead of the stats from ~2.6 KiB per P to 536 bytes per P.
This is enough to make the difference no longer noticable in our
benchmark suite.

Fixes #73931.

Change-Id: I4351f1cbb3f6743d8f5922d757d73442c6d6ad3f
Reviewed-on: https://go-review.googlesource.com/c/go/+/678535
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2 months agotest: add another regression test for issue 73309
Cuong Manh Le [Tue, 3 Jun 2025 17:04:26 +0000 (00:04 +0700)]
test: add another regression test for issue 73309

Fixed #73309

Change-Id: Id715b9c71c95c92143a7fdb5a66b24305346dd3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/678415
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 months agocmd/compile: better error message when import embed package
qiulaidongfeng [Tue, 3 Jun 2025 15:01:27 +0000 (23:01 +0800)]
cmd/compile: better error message when import embed package

Fixes #73955

Change-Id: I7cf3ab4c70dc2e2765b54b88ae8cfc77a3073344
Reviewed-on: https://go-review.googlesource.com/c/go/+/678355
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agocmd/dist: don't install tools that won't be shipped in distribution
Michael Matloob [Fri, 30 May 2025 16:53:42 +0000 (12:53 -0400)]
cmd/dist: don't install tools that won't be shipped in distribution

We shouldn't be installing these tools because we will remove them in
distpack. Installing the tools will also prevent us from testing what
happens when the tools are missing.

The changes below this on the stack, CL 677775 (cmd/doc: build cmd/doc
directly into the go command) and CL 677636 (cmd/go/internal/cfg: fix
GOROOT setting when forcing host config) are needed for this change to
pass tests. The doc change is being done so we preserve the properties
in the tests that doc can be invoked without doing a build. It's not
strictly necessary (we could just remove the tests) but it's nice to
have. The GOROOT setting is a significant bug in switching the
configuration to host mode: the value of GOROOT wasn't being reset,
which caused issues for go commands built with trimpath, because
runtime.GOROOT wouldn't have the correct goroot value.

For #71867

Change-Id: I4181711ba117066b7d62d7d013ad4b186871cfb7
Reviewed-on: https://go-review.googlesource.com/c/go/+/677558
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
2 months agocmd/doc: build cmd/doc directly into the go command
Michael Matloob [Fri, 30 May 2025 22:20:05 +0000 (18:20 -0400)]
cmd/doc: build cmd/doc directly into the go command

There are a couple of places where our tests expect that 'go doc'
doesn't need to do a build. Invoke the cmd/doc code directly by the go
command instead of starting the doc tool in a separate process so we can
preserve that property.

This change moves most of the doc code into the package
cmd/internal/doc, and exposes a Main function from that function that's
called both by the cmd/doc package, and by go doc.

This change makes couple of additional changes to intergrate doc into
the go command:

The counter.Open call and the increment of invocations counter are only
needed by cmd/doc. The go command will open the counters file and
increment a counter for the doc subcommand.

We add a cmd_go_bootstrap tagged variant of the file that defines go doc
so that we don't end up linking net into the bootstrap version of the go
command. We don't need doc in that version of the command.

We create a new flagSet rather than using flag.CommandLine because when
running as part of the go command, the flags to "go doc" won't be the top
level flags.

We change TestGoListTest in go_test.go to use gofmt instead of doc as an
example of a main package in cmd with an in-package test.

For #71867

Change-Id: I3e3df83e5fa266559606fdc086b461165e09f037
Reviewed-on: https://go-review.googlesource.com/c/go/+/677775
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
2 months agogo/token: remove unreachable code
Michael Pratt [Tue, 3 Jun 2025 17:08:06 +0000 (13:08 -0400)]
go/token: remove unreachable code

Reported by go vet.

Change-Id: I6a6a636c79923fafd8c649c583383cdf455c6ce2
Reviewed-on: https://go-review.googlesource.com/c/go/+/678317
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agogo/token: tweak comment
Alan Donovan [Tue, 3 Jun 2025 14:43:55 +0000 (10:43 -0400)]
go/token: tweak comment

(accidentally omitted from CL 675736)

Change-Id: I05ed8fcb7bb4109862a47701c427d8efc17b9f31
Reviewed-on: https://go-review.googlesource.com/c/go/+/678315
TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>

2 months agocmd/go/internal/cfg: fix GOROOT setting when forcing host config
Michael Matloob [Fri, 30 May 2025 20:16:27 +0000 (16:16 -0400)]
cmd/go/internal/cfg: fix GOROOT setting when forcing host config

We manage the state using a bunch of global config, so we need to make
sure we're doing things in the right order. In this case, the SetGOROOT
function was being called in init, setting the GOROOT on the global
Context, but when we reset the context in ForceHost we lost the goroot
configuration. We need to call SetGOROOT in ForceHost to re-set the
GOROOT on the new context.

This was uncovered by CL 677558 because a go command that was built with
trimpath would try to use its runtime.GOROOT(), which wouldn't be valid
in trimpath mode. Setting GOROOT properly with SetGOROOT will use the
value from findGOROOT, assuming GOROOT isn't set in the environment,
and findGOROOT will try to determine GOROOT using the path of the go
command executable.

For #71867

Change-Id: I731b6c5d859b4504fc128b29ab904e3a2886ff3c
Reviewed-on: https://go-review.googlesource.com/c/go/+/677636
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2 months agoruntime: additional memmove benchmarks
Keith Randall [Mon, 2 Jun 2025 23:24:07 +0000 (16:24 -0700)]
runtime: additional memmove benchmarks

For testing out duffcopy changes.

Change-Id: I93b4a52d75418a6e31aae5ad99f95d1870812b69
Reviewed-on: https://go-review.googlesource.com/c/go/+/678215
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2 months agogo/token: FileSet: hold Files in a balanced tree
Alan Donovan [Fri, 23 May 2025 02:06:13 +0000 (22:06 -0400)]
go/token: FileSet: hold Files in a balanced tree

This CL changes the representation of FileSet from a slice
to a tree, specifically an AVL tree keyed by the File's
base-end range. This makes a sequence of insertions using
AddExistingFiles much more efficient: creating a FileSet
of size n by a sequence of calls costs O(n log n), whereas
before it was O(n^2 log n) because of the repeated sorting.

The AVL tree is based on Russ' github.com/rsc/omap,
simplified for clarity and to reduce unnecessary dynamism.
We use an AVL tree as it is more strongly balanced than an
RB tree, optimising lookups at the expense of insertions.

The CL includes a basic unit test of the tree using
operations on pseudorandom values.

Benchmarks of Position lookups actually improve because
the tree avoids BinarySearchFunc's dynamic dispatch to cmp,
and the benchmark of AddExistingFiles is about 1000x (!) faster:

goos: darwin
goarch: arm64
pkg: go/token
cpu: Apple M1 Pro
                                    â”‚     old.txt     â”‚               new.txt               â”‚
                                    â”‚     sec/op      â”‚    sec/op     vs base               â”‚
FileSet_Position/random-8                51.60n Â±  1%   39.99n Â±  1%  -22.50% (p=0.000 n=9)
FileSet_Position/file-8                  27.10n Â±  3%   26.64n Â±  1%        ~ (p=0.168 n=9)
FileSet_Position/manyfiles-8             209.9n Â± 17%   154.1n Â±  9%  -26.58% (p=0.000 n=9)
FileSet_AddExistingFiles/sequence-8   395930.3µ Â±  4%   280.8µ Â± 10%  -99.93% (p=0.000 n=9)

Updates #73205

Change-Id: Iea59c624a6cedadc2673987a5eb0ebece67af9e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/675736
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agoruntime: randomize order of timers at the same instant in bubbles
Damien Neil [Thu, 29 May 2025 18:48:06 +0000 (11:48 -0700)]
runtime: randomize order of timers at the same instant in bubbles

In synctest bubbles, fire timers scheduled for the same instant
in a randomized order.

Pending timers are added to a heap ordered by the timer's wakeup time.
Add a per-timer random value, set when the timer is added to a heap,
to break ties between timers scheduled for the same instant.

Only inject this randomness in synctest bubbles. We could do so
for all timers at the cost of one cheaprand call per timer,
but given that it's effectively impossible to create two timers
scheduled for the same instant outside of a fake-time environment,
don't bother.

Fixes #73876
For #73850

Change-Id: Ie96c86a816f548d4c31e4e014bf9293639155bd4
Reviewed-on: https://go-review.googlesource.com/c/go/+/677276
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2 months agogo/{ast,parser,types}: add signpost to golang.org/x/tools/go/packages
Alan Donovan [Thu, 29 May 2025 14:29:39 +0000 (10:29 -0400)]
go/{ast,parser,types}: add signpost to golang.org/x/tools/go/packages

Change-Id: I5d5036e7b41df67d0c1ab42163fdceed8f9c42a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/677137
Reviewed-by: Matt Proud <mtp@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agocmd/compile/internal/noder: document quirk of string elements
Mark Freeman [Fri, 30 May 2025 19:44:11 +0000 (15:44 -0400)]
cmd/compile/internal/noder: document quirk of string elements

Change-Id: Ifc3bf896aaaf7c6ce06a01e3dd43780d203638cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/677755
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Mark Freeman <mark@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
2 months agocmd/compile/internal/noder: stub type section and adjust others
Mark Freeman [Fri, 30 May 2025 18:45:38 +0000 (14:45 -0400)]
cmd/compile/internal/noder: stub type section and adjust others

The type definition and object definition sections have nearly the same
structure - help illustrate that through consistent naming.

Change-Id: Ibed374fca4883a293a7fc16b36034e1acb38362a
Reviewed-on: https://go-review.googlesource.com/c/go/+/677378
Auto-Submit: Mark Freeman <mark@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agocmd/compile/internal/noder: begin filling in SectionObj
Mark Freeman [Thu, 29 May 2025 20:06:27 +0000 (16:06 -0400)]
cmd/compile/internal/noder: begin filling in SectionObj

SectionObj has to encode the definition information for each object
type, so it will be a bit long.

Change-Id: I9b9514d58a284a4e64020f99fd1b2a92f7752338
Reviewed-on: https://go-review.googlesource.com/c/go/+/677377
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Mark Freeman <mark@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agocmd/compile/internal/noder: fill in SectionName
Mark Freeman [Thu, 29 May 2025 19:43:47 +0000 (15:43 -0400)]
cmd/compile/internal/noder: fill in SectionName

Change-Id: Ib99d40a546cb095c1b6c2d33e0735f3b5c681539
Reviewed-on: https://go-review.googlesource.com/c/go/+/677237
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Mark Freeman <mark@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agotesting: add Output method to TB
Mateusz Poliwczak [Sat, 31 May 2025 14:41:15 +0000 (16:41 +0200)]
testing: add Output method to TB

Updates #59928
Fixes #73937

Change-Id: Ibf7ec61758edccd245841c3acc9096563b44fcd2
Reviewed-on: https://go-review.googlesource.com/c/go/+/677875
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2 months agoslices,sort: explicitly discard results in benchmarks
Alan Donovan [Mon, 2 Jun 2025 15:27:08 +0000 (11:27 -0400)]
slices,sort: explicitly discard results in benchmarks

The unusedresult analyzer will report failure to use the results
of these pure functions.

Updates #73950

Change-Id: I783cb92ad913105afd46c782bedf6234410c645d
Reviewed-on: https://go-review.googlesource.com/c/go/+/677995
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agointernal/trace: expose the go version read by the reader
Carlos Amedee [Fri, 30 May 2025 20:05:04 +0000 (16:05 -0400)]
internal/trace: expose the go version read by the reader

This change adds a function to expose the version set by the trace
reader after reading the trace header (in tests). The trace validator
needs to be able to determine what version of the trace it needs to
validate against. Clock snapshot checks have been disabled for
Windows and WASM.

For #63185

Change-Id: Ia3d63e6ed7a5ecd87e63292b84cc417d982aaa5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/677695
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Carlos Amedee <carlos@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2 months agocmd/distpack: add test case for pack tool being excluded
Michael Matloob [Fri, 30 May 2025 19:23:36 +0000 (15:23 -0400)]
cmd/distpack: add test case for pack tool being excluded

For #71867

Change-Id: Ic4c6304b9a6b35c45bf35342523930924c68545a
Reviewed-on: https://go-review.googlesource.com/c/go/+/677635
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2 months agocmd/distpack: don't keep the pack tool
Michael Matloob [Fri, 30 May 2025 16:22:23 +0000 (12:22 -0400)]
cmd/distpack: don't keep the pack tool

This was an oversight: the pack tool isn't actually used in builds.

For #71867

Change-Id: Ib1f1cce0b574cf1d2c1002b2f2ab9ef9d750d0fb
Reviewed-on: https://go-review.googlesource.com/c/go/+/677557
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2 months agoruntime: set HeapGoal to zero when the GC is disabled
Carlos Amedee [Thu, 2 Jan 2025 19:41:59 +0000 (14:41 -0500)]
runtime: set HeapGoal to zero when the GC is disabled

When the GC is disabled, the tracer should emit a heap goal of 0. Not
setting the heap goal to 0 causes an inaccurate NextGC value to be
emmited.

Fixes #63864

Change-Id: Iecceaca86c0a43c1cc4d9433f1f9bb736f01ccbc
Reviewed-on: https://go-review.googlesource.com/c/go/+/639417
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2 months agotesting, testing/synctest: report correct duration after panics
Damien Neil [Fri, 23 May 2025 23:21:19 +0000 (16:21 -0700)]
testing, testing/synctest: report correct duration after panics

Report the correct wall-clock test duration after handling a
panic in a synctest.Test bubble.

Fixes #73852

Change-Id: I053262e5eac2dd9d5938b17c3093cbc3fa115a0d
Reviewed-on: https://go-review.googlesource.com/c/go/+/676695
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agoos: add implementation of fs.ReadLinkFS to *rootFS
Roxy Light [Sat, 24 May 2025 23:07:58 +0000 (16:07 -0700)]
os: add implementation of fs.ReadLinkFS to *rootFS

Fixes #73887

Change-Id: I43f3f4324d740b5381615bce864b7ec31415a635
Reviewed-on: https://go-review.googlesource.com/c/go/+/676135
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2 months agocmd/compile/internal/noder: rename RelIndex to match codebase
Mark Freeman [Thu, 29 May 2025 18:54:23 +0000 (14:54 -0400)]
cmd/compile/internal/noder: rename RelIndex to match codebase

Change-Id: I06b64ea3c1c02b46e242852f8f0b56d77df42161
Reviewed-on: https://go-review.googlesource.com/c/go/+/677236
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Mark Freeman <mark@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
2 months agocmd/compile: update default PGO profile
Cherry Mui [Thu, 29 May 2025 19:42:23 +0000 (15:42 -0400)]
cmd/compile: update default PGO profile

Since last time the default.pgo profile is collected, there has
been a lot of development in the compiler. It's time to refresh
the compiler's PGO profile.

Profile collected by running the cmd/compile/profile.sh script on
the gotip-linux-amd64_c3h88-perf_vs_release gomote.

Benchmark results on Linux/AMD64:

         â”‚  nopgo.txt  â”‚              old.txt               â”‚              new.txt               â”‚
         â”‚   sec/op    â”‚   sec/op     vs base               â”‚   sec/op     vs base               â”‚
Template   110.4m Â± 2%   108.4m Â± 1%       ~ (p=0.121 n=20)   107.8m Â± 1%  -2.37% (p=0.006 n=20)
Unicode    98.78m Â± 0%   95.16m Â± 1%  -3.67% (p=0.000 n=20)   93.87m Â± 1%  -4.98% (p=0.000 n=20)
GoTypes    553.8m Â± 0%   548.3m Â± 0%  -0.99% (p=0.000 n=20)   542.1m Â± 0%  -2.11% (p=0.000 n=20)
Compiler   88.12m Â± 1%   83.22m Â± 1%  -5.56% (p=0.000 n=20)   81.81m Â± 1%  -7.17% (p=0.000 n=20)
SSA         3.592 Â± 1%    3.499 Â± 0%  -2.58% (p=0.000 n=20)    3.445 Â± 0%  -4.08% (p=0.000 n=20)
Flate      64.48m Â± 1%   64.99m Â± 1%       ~ (p=0.341 n=20)   63.10m Â± 2%  -2.15% (p=0.000 n=20)
GoParser   129.8m Â± 1%   127.3m Â± 1%  -1.88% (p=0.004 n=20)   126.2m Â± 1%  -2.75% (p=0.000 n=20)
Reflect    286.0m Â± 1%   282.3m Â± 1%  -1.30% (p=0.000 n=20)   280.1m Â± 1%  -2.06% (p=0.000 n=20)
Tar        129.3m Â± 1%   128.4m Â± 2%       ~ (p=0.565 n=20)   126.3m Â± 1%  -2.32% (p=0.000 n=20)
XML        152.1m Â± 1%   148.2m Â± 1%  -2.55% (p=0.000 n=20)   147.9m Â± 1%  -2.79% (p=0.000 n=20)
geomean    197.4m        193.4m       -2.04%                  190.9m       -3.29%

On Linux/ARM64:

         â”‚  nopgo.txt  â”‚              old.txt               â”‚              new.txt               â”‚
         â”‚   sec/op    â”‚   sec/op     vs base               â”‚   sec/op     vs base               â”‚
Template   80.78m Â± 2%   78.78m Â± 1%  -2.47% (p=0.000 n=20)   78.15m Â± 1%  -3.25% (p=0.000 n=20)
Unicode    80.57m Â± 1%   75.79m Â± 1%  -5.94% (p=0.000 n=20)   74.85m Â± 0%  -7.11% (p=0.000 n=20)
GoTypes    426.4m Â± 0%   416.1m Â± 0%  -2.42% (p=0.000 n=20)   411.0m Â± 0%  -3.62% (p=0.000 n=20)
Compiler   66.54m Â± 1%   64.01m Â± 1%  -3.79% (p=0.000 n=20)   62.86m Â± 1%  -5.53% (p=0.000 n=20)
SSA         2.905 Â± 0%    2.772 Â± 0%  -4.56% (p=0.000 n=20)    2.759 Â± 0%  -5.01% (p=0.000 n=20)
Flate      46.68m Â± 0%   45.40m Â± 1%  -2.75% (p=0.000 n=20)   45.20m Â± 0%  -3.16% (p=0.000 n=20)
GoParser   95.17m Â± 1%   93.54m Â± 1%  -1.71% (p=0.000 n=20)   92.50m Â± 0%  -2.80% (p=0.000 n=20)
Reflect    212.4m Â± 0%   206.6m Â± 1%  -2.72% (p=0.000 n=20)   205.4m Â± 1%  -3.31% (p=0.000 n=20)
Tar        95.64m Â± 1%   93.19m Â± 1%  -2.57% (p=0.000 n=20)   92.55m Â± 0%  -3.23% (p=0.000 n=20)
XML        111.0m Â± 0%   108.0m Â± 1%  -2.67% (p=0.000 n=20)   107.2m Â± 1%  -3.38% (p=0.000 n=20)
geomean    148.9m        144.2m       -3.17%                  142.9m       -4.05%

For #60234.

Change-Id: I6c4f0609ba578a2848ce6cfcc748dfdda7222182
Reviewed-on: https://go-review.googlesource.com/c/go/+/677375
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agocmd/internal/obj/s390x: fix potential recursive String call
Michael Anthony Knyszek [Thu, 29 May 2025 19:04:08 +0000 (19:04 +0000)]
cmd/internal/obj/s390x: fix potential recursive String call

This String method can potentially recurse infinitely, since %#x will
apparently call String if the method exists. This isn't well documented,
but cmd/vet will be updated soon to check this (when we update the
vendored x/tools dependency) so cut off the recursion by converting to
the underlying type first.

Change-Id: Ia6fc046c9eb56a5dd6a33772afd23da443a06116
Reviewed-on: https://go-review.googlesource.com/c/go/+/677261
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agoruntime, testing/synctest: breaking bubble isolation with Cond is fatal
Damien Neil [Thu, 22 May 2025 18:14:53 +0000 (11:14 -0700)]
runtime, testing/synctest: breaking bubble isolation with Cond is fatal

sync.Cond.Wait is durably blocking. Waking a goroutine out of Cond.Wait
from outside its bubble panics.

Make this panic a fatal panic, since it leaves the notifyList in an
inconsistent state. We could do some work to make this a recoverable
panic, but the complexity doesn't seem worth the outcome.

For #67434

Change-Id: I88874c1519c2e5c0063175297a9b120cedabcd07
Reviewed-on: https://go-review.googlesource.com/c/go/+/675617
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Damien Neil <dneil@google.com>

2 months agotesting, testing/synctest: write bubble errors to parent test log
Damien Neil [Wed, 28 May 2025 17:55:26 +0000 (10:55 -0700)]
testing, testing/synctest: write bubble errors to parent test log

Ensure that log messages written to the testing.T created by
synctest.Test appear in the test output when a test fails.

Fixes #73902

Change-Id: Ie97f5efe54eb003e6c0a5394c2def4cac1520ecb
Reviewed-on: https://go-review.googlesource.com/c/go/+/676995
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agointernal/pkgbits: explain the rationale for reference tables
Mark Freeman [Thu, 22 May 2025 15:06:23 +0000 (11:06 -0400)]
internal/pkgbits: explain the rationale for reference tables

The primary benefit of reference tables is to the linker, though they
are also reasonably compact as compared to absolute element indices. It
is worth also checking if reference table structure is similarly
exploited past the IR linking stage.

Ideally, the reference table definition would live in / near the linker.
As it stands, it's a bit hard to infer the purpose of the reference
tables when looking at pkgbits in isolation.

Change-Id: I496aca5a4edcf28e66fa7863ddfa4d825e1b2e89
Reviewed-on: https://go-review.googlesource.com/c/go/+/675596
Auto-Submit: Mark Freeman <mark@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agoslices: document and test nilness behavior of all functions
Alan Donovan [Mon, 12 May 2025 17:16:23 +0000 (13:16 -0400)]
slices: document and test nilness behavior of all functions

This change documents the current nilness behavior of all
functions in the package, and asserts each with a test.

There is no change to behavior, but the postcondition is
strengthened, so this may require a proposal.

Fixes #73604
Fixes #73048

Change-Id: Ieb68e609a1248bd81c8507d3795785622a65f8cb
Reviewed-on: https://go-review.googlesource.com/c/go/+/671996
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Austin Clements <austin@google.com>
2 months agoruntime: add vgetrandom lock rank
Michael Pratt [Thu, 29 May 2025 16:41:21 +0000 (12:41 -0400)]
runtime: add vgetrandom lock rank

vgetrandomGetState can call malloc, so this is not a leaf lock.

Our staticlockrank builder doesn't support vgetrandom, so it didn't
catch this.

Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-staticlockranking
Change-Id: I6a6a636c36c9172e4ebf9493c10cb23cac29a13f
Reviewed-on: https://go-review.googlesource.com/c/go/+/677255
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2 months agoruntime: guarantee no GOMAXPROCS update syscalls after GOMAXPROCS call
Michael Pratt [Wed, 28 May 2025 20:01:33 +0000 (16:01 -0400)]
runtime: guarantee no GOMAXPROCS update syscalls after GOMAXPROCS call

We already guarantee that no automatic updates to GOMAXPROCS occur after
a GOMAXPROCS call returns. This is easily achieved by having the update
goroutine double-check that updates are still allowed during STW before
committing the new value.

However, it is possible for sysmon to concurrently run defaultGOMAXPROCS
to compute a new GOMAXPROCS value after GOMAXPROCS returns. This new
value will be discarded later, but we'll still perform the system calls
necessary to compute the new value.

Normally this distinction doesn't matter, but if you want to sandbox a
Go program, then you may want to disable GOMAXPROCS updates to reduce
the system call footprint. A call to GOMAXPROCS will disable updates,
but without a guarantee on when sysmon will observe the change it is
somewhat fragile.

Add explicit synchronization between GOMAXPROCS and sysmon to guarantee
that sysmon won't run defaultGOMAXPROCS after GOMAXPROCS returns.

The synchronization is a bit complex because we can't hold a mutex
across STW, nor take a semaphore from sysmon, but the result isn't too
bad.

One oddity is that sched.customGOMAXPROCS and gomaxprocs are no longer
updated in lockstep (even though both are protected by sched.lock), but
I don't believe anything should depend on that.

For #73193.

Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-staticlockranking
Change-Id: I6a6a636cff243a9b69ac1b5d2f98925648e60236
Reviewed-on: https://go-review.googlesource.com/c/go/+/677037
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2 months agodoc/next: delete
Gopher Robot [Thu, 29 May 2025 17:10:09 +0000 (10:10 -0700)]
doc/next: delete

The release note fragments have been merged and added
as _content/doc/go1.25.md in x/website in CL 677175.

For #71661.

Change-Id: Ie1a895de03c20941a38b0a6a45f4cf6bc21278e1
Reviewed-on: https://go-review.googlesource.com/c/go/+/677335
Auto-Submit: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: David Chase <drchase@google.com>
2 months agointernal/synctest: speed up TestWeak
Damien Neil [Fri, 23 May 2025 00:18:12 +0000 (17:18 -0700)]
internal/synctest: speed up TestWeak

Run TestWeak for fewer iterations. Five is enough reproduce #73817,
which was the motivation for this test. runtime.GC is ridiculously
slow on wasm, and not especially fast anywhere else.

Change-Id: Ieb5235d064b123cbc22a306425e385c273b54493
Reviewed-on: https://go-review.googlesource.com/c/go/+/675716
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agoruntime, internal/synctest, sync: associate WaitGroups with bubbles
Damien Neil [Tue, 20 May 2025 22:56:43 +0000 (15:56 -0700)]
runtime, internal/synctest, sync: associate WaitGroups with bubbles

Add support to internal/synctest for managing associations between
arbitrary pointers and synctest bubbles. (Implemented internally to
the runtime package by attaching a special to the pointer.)

Associate WaitGroups with bubbles.
Since WaitGroups don't have a constructor,
perform the association when Add is called.
All Add calls must be made from within the same bubble,
or outside any bubble.

When a bubbled goroutine calls WaitGroup.Wait,
the wait is durably blocking iff the WaitGroup is associated
with the current bubble.

Change-Id: I77e2701e734ac2fa2b32b28d5b0c853b7b2825c9
Reviewed-on: https://go-review.googlesource.com/c/go/+/676656
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>

2 months agoruntime: increment updatemaxprocs metric only when disabled
Michael Pratt [Wed, 28 May 2025 18:34:52 +0000 (14:34 -0400)]
runtime: increment updatemaxprocs metric only when disabled

The updatemaxprocs metric logic is currently backwards. We only
increment the metric when we update GOMAXPROCS, but that only occurs if
updatemaxprocs is enabled.

Instead, the metric is supposed to increment when updatemaxprocs is
disabled and there would be different behavior if it were enabled.

Theoretically we should run the entire update system in a dry run mode,
and only bail out right before committing updates. But that is an awful
lot of effort for a feature that is disabled. Plus some users (like
sandboxes) want to completely disable the update syscalls
(sched_getaffinity and pread64). If we still do dry run updates then we
need an additional GODEBUG for completely disabling functionality.

This CL also avoids starting the update goroutine at all if disabled,
since it isn't needed.

For #73193.

Change-Id: I6a6a636ceec8fced44e36cb27dcb1b4ba51fce33
Reviewed-on: https://go-review.googlesource.com/c/go/+/677036
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Pratt <mpratt@google.com>

2 months agogo/doc: NewFromFiles: fix panic on Files with SkipObjectResolution
Alan Donovan [Wed, 21 May 2025 15:21:31 +0000 (11:21 -0400)]
go/doc: NewFromFiles: fix panic on Files with SkipObjectResolution

This CL fixes a panic in NewFromFiles when it is provided files
produced by the parser in SkipObjectResolution mode, which skips
the step of connecting ast.Idents to (deprecated) ast.Objects.
Instead of calling ast.NewPackage, which performs a number of
unnecessary steps, we just construct the ast.Package directly.

Fixes #66290

Change-Id: Id55bd30d8afb9d396c3901070e7607c5a22030d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/675036
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agoapi: promote next to go1.25
Gopher Robot [Wed, 28 May 2025 16:38:20 +0000 (09:38 -0700)]
api: promote next to go1.25

Change-Id: I96dd383ea0bf0b69d2d9058334b4bbcfbe50c77c
Reviewed-on: https://go-review.googlesource.com/c/go/+/676895
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2 months agocmd/compile: do nil check before calling duff functions, on arm64 and amd64
Keith Randall [Thu, 29 May 2025 00:09:05 +0000 (17:09 -0700)]
cmd/compile: do nil check before calling duff functions, on arm64 and amd64

On these platforms, we set up a frame pointer record below
the current stack pointer, so when we're in duffcopy or duffzero,
we get a reasonable traceback. See #73753.

But because this frame pointer record is below SP, it is vulnerable.
Anything that adds a new stack frame to the stack might clobber it.
Which actually happens in #73748 on amd64. I have not yet come across
a repro on arm64, but might as well be safe here.

The only real situation this could happen is when duffzero or duffcopy
is passed a nil pointer. So we can just avoid the problem by doing the
nil check outside duffzero/duffcopy. That way we never add a frame
below duffzero/duffcopy. (Most other ways to get a new frame below the
current one, like async preempt or debugger-generated calls, don't
apply to duffzero/duffcopy because they are runtime functions; we're
not allowed to preempt there.)

Longer term, we should stop putting stuff below SP. #73753 will
include that as part of its remit. But that's not for 1.25, so we'll
do the simple thing for 1.25 for this issue.

Fixes #73748

Change-Id: I913c49ee46dcaee8fb439415a4531f7b59d0f612
Reviewed-on: https://go-review.googlesource.com/c/go/+/676916
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2 months agoruntime: rename updateGOMAXPROCS to updateMaxProcsG
Michael Pratt [Wed, 28 May 2025 18:10:38 +0000 (14:10 -0400)]
runtime: rename updateGOMAXPROCS to updateMaxProcsG

There are other parts to updating GOMAXPROCS than just the helper
goroutine, so make the naming more specific.

For #73193.

Change-Id: I6a6a636c31ac80c8d76afe90c0bfc29d3086af4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/677035
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agodoc/next: add release note for riscv64 plugin build mode
Michael Anthony Knyszek [Wed, 28 May 2025 17:48:40 +0000 (17:48 +0000)]
doc/next: add release note for riscv64 plugin build mode

Change-Id: I9df20038cc1d6bf86f789e962903766856555a13
Reviewed-on: https://go-review.googlesource.com/c/go/+/676956
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 months agogo/types, types2: dump position stack for non-bailout panics
Mark Freeman [Wed, 28 May 2025 15:10:53 +0000 (11:10 -0400)]
go/types, types2: dump position stack for non-bailout panics

We make sure to dump to stderr since that's where the panic information
ends up. Long traces get truncated with a "..." in the middle. We pick
an arbitrary limit of 10 positions, but this could be changed.

For #51603

Change-Id: I02326a93181e94e1c48afc05684240540c2c90ba
Reviewed-on: https://go-review.googlesource.com/c/go/+/676815
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Mark Freeman <mark@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agocmd/link: allow linkname reference to a TEXT symbol regardless of size
Cherry Mui [Wed, 21 May 2025 18:32:21 +0000 (14:32 -0400)]
cmd/link: allow linkname reference to a TEXT symbol regardless of size

In CL 660696, we made the linker to choose the symbol of the
larger size in case there are multiple contentless declarations of
the same symbol. We also made it emit an error in the case that
there are a contentless declaration of a larger size and a
definition with content of a smaller size. In this case, we should
choose the definition with content, but the code accesses it
through the declaration of the larger size could fall into the
next symbol, potentially causing data corruption. So we disallowed
it.

There is one spcial case, though, that some code uses a linknamed
variable declaration to reference a function in assembly, in order
to take its address. The variable is often declared as uintptr.
The function symbol is the definition, which could sometimes be
shorter. This would trigger the error case above, causing existing
code failing to build.

This CL allows it as a special case. It is still not safe to
access the variable's content. But it is actually okay to just
take its address, which the existing code often do.

Fixes #73617.

Change-Id: I467381bc5f6baa16caee6752a0a824c7185422f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/676636
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agodoc/next: tweak runtime release notes
Michael Anthony Knyszek [Wed, 28 May 2025 17:39:14 +0000 (17:39 +0000)]
doc/next: tweak runtime release notes

- Add section headings to make the section easier to read.
- Reorder features to better reflect their impact and importance.
- Tweak some awkward wording here and there.

Change-Id: If72c526f4b3a26a7a4584d6c59857db02c0c1338
Reviewed-on: https://go-review.googlesource.com/c/go/+/676818
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agolib/time: update to 2025b/2025b
Dmitri Shuralyov [Wed, 28 May 2025 15:23:36 +0000 (11:23 -0400)]
lib/time: update to 2025b/2025b

Commit generated by update.bash.

For #22487.

Change-Id: If4132dc12296b23b85a221bffdb1b854d0332010
Reviewed-on: https://go-review.googlesource.com/c/go/+/676855
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agoos: don't follow symlinks on Windows when O_CREATE|O_EXCL and read-only
Damien Neil [Tue, 27 May 2025 21:16:17 +0000 (14:16 -0700)]
os: don't follow symlinks on Windows when O_CREATE|O_EXCL and read-only

Fix a bug in CL 672396, where we add FILE_FLAG_OPEN_REPARSE_POINT to
the attributes passed to CreateFile, but then overwrite the attributes
with FILE_ATTRIBUTE_READONLY when opening a file with a read-only
permissions mode.

For #73702

Change-Id: I6c10bf470054592bafa031732585fc3155c61341
Reviewed-on: https://go-review.googlesource.com/c/go/+/676655
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2 months agoruntime, testing/synctest: verify cleanups/finalizers run outside bubbles
Damien Neil [Wed, 21 May 2025 22:08:08 +0000 (15:08 -0700)]
runtime, testing/synctest: verify cleanups/finalizers run outside bubbles

Cleanup functions and finalizers must not run in a synctest bubble.
If they did, a function run by the GC at an unpredictable time
could unblock a bubble that synctest believes is durably
blocked.

Add a test verifying that cleanups and finalizers are always
run by non-bubbled goroutines. (This is already the case because
we never add system goroutines to a bubble.)

For #67434

Change-Id: I5a48db2b26f9712c3b0dc1f425d99814031a2fc1
Reviewed-on: https://go-review.googlesource.com/c/go/+/675257
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>

2 months agoruntime: define lock ranking between weak pointers and synctest
Damien Neil [Wed, 21 May 2025 20:02:59 +0000 (13:02 -0700)]
runtime: define lock ranking between weak pointers and synctest

Fixes #73817

Change-Id: I0101bdc797237b4c7eb58b414c71b009b0b44447
Reviewed-on: https://go-review.googlesource.com/c/go/+/675176
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Damien Neil <dneil@google.com>

2 months agocmd/compile/internal/walk: use original type for composite literals in addrTemp
thepudds [Tue, 27 May 2025 17:32:36 +0000 (13:32 -0400)]
cmd/compile/internal/walk: use original type for composite literals in addrTemp

When creating a new *ir.Name or *ir.LinksymOffsetExpr to represent
a composite literal stored in the read-only data section, we should
use the original type of the expression that was found via
ir.ReassignOracle.StaticValue. (This is needed because the StaticValue
method can traverse through OCONVNOP operations to find its final
result.)

Otherwise, the compilation may succeed, but the linker might erroneously
conclude that a type is not used and prune an itab when it should not,
leading to a call at execution-time to runtime.unreachableMethod, which
throws "fatal error: unreachable method called. linker bug?".

The tests exercise both the case of a zero value struct literal that
can be represented by the read-only runtime.zeroVal, which was the case
of the simplified example from #73888, and also modifies that example to
test the non zero value struct literal case.

This CL makes two similar changes for those two cases. We can get either
of the tests we are adding to fail independently if we only make
a single corresponding change.

Fixes #73888
Updates #71359

Change-Id: Ifd91f445cc168ab895cc27f7964a6557d5cc32e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/676517
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2 months agoruntime/trace: add a trace validation test for different trace orders
Carlos Amedee [Fri, 23 May 2025 20:41:51 +0000 (16:41 -0400)]
runtime/trace: add a trace validation test for different trace orders

This adds a test which validates the traces generated by the execution
tracer and the flight recorder depending on the order where they are
stopped and started. This test uncovered that under certain
circumstances, the traces which were produced would possibly be
missing the trace header. All traces have the trace headers included
now. Clock snapshot checks have been disabled for Windows and WASM.

Change-Id: I5be719d228300469891fc56817fbce4ba5453fff
Reviewed-on: https://go-review.googlesource.com/c/go/+/675975
Auto-Submit: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2 months agocmd/go: fix get with the new 'work' pattern
Michael Matloob [Fri, 23 May 2025 17:19:44 +0000 (13:19 -0400)]
cmd/go: fix get with the new 'work' pattern

Before this change, go get didn't have support for the work pattern. The
work pattern is new in Go 1.25 and evaluates to the packages in the work
(also called main) modules. 'go get work' would cause a panic because
'work' would be incorrectly considered a path pattern and then queryPath
would would try to query a metapackage pattern (resulting in the
internal error panic). This change properly supports the work pattern in
go get.

It's pretty simple: First, we need to seprate the work pattern from the
other patterns. Then in performWorkQueries, which maps queries to the
modules that satisfy them, we return the single main module because by
definition the work pattern is the set of packages in the work modules,
and go get always runs in single module mode. (The exception is when the
work module contains no packages, in which case we report a warning, and
return no candidates because nothing is needed to resolve nothing).

The rest of the work is already done by loading the packages matching
the query and finding missing imports in the call to
findAndUpgradeImports in runGet.

Change-Id: I3c4610878b3d930a1d106cc59d9a0be194d966cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/675895
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2 months agolog/slog: fix longtests with empty source
Sean Liao [Tue, 27 May 2025 18:11:28 +0000 (19:11 +0100)]
log/slog: fix longtests with empty source

Tests broken by CL 674875

Updates #73808

Change-Id: I7ad93e4a8ba1977d136f99b9d4963fa8a9c159ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/676595
Auto-Submit: Michael Knyszek <mknyszek@google.com>
TryBot-Bypass: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2 months agodoc/next: add small header to TODO
David Chase [Tue, 27 May 2025 18:21:11 +0000 (14:21 -0400)]
doc/next: add small header to TODO

Change-Id: I91c03f455fff8e4078f3297ea357cd1e1dd09f66
Reviewed-on: https://go-review.googlesource.com/c/go/+/676536
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agogo/token: benchmark FileSet.{Position,AddExistingFiles}
Alan Donovan [Fri, 23 May 2025 15:35:41 +0000 (11:35 -0400)]
go/token: benchmark FileSet.{Position,AddExistingFiles}

This CL adds a benchmark of FileSet.Position, the lookup
operation, and the new AddExistingFiles. It is evident
that its behavior is quadratic in important cases:

(Apple M1)
BenchmarkFileSet_AddExistingFiles/sequence-8                 3  362768139 ns/op

Change-Id: I256fdc776135e1924666d127afb37dacbefc860f
Reviewed-on: https://go-review.googlesource.com/c/go/+/675875
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>

2 months agogo/ast: deprecate FilterPackage, PackageExports, MergePackageFiles
Alan Donovan [Mon, 19 May 2025 18:11:51 +0000 (14:11 -0400)]
go/ast: deprecate FilterPackage, PackageExports, MergePackageFiles

(More symbols that belong to the ast.Object deprecation.)

Fixes #73088
Fixes #7124
Updates #52463
Updates #71122

Change-Id: I10e3ef35b587da2f3f0a65e9154e33bd53e7a093
Reviewed-on: https://go-review.googlesource.com/c/go/+/674176
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2 months agoruntime: skip nil Ps in allp during cleanup flush
Michael Pratt [Tue, 27 May 2025 14:37:50 +0000 (10:37 -0400)]
runtime: skip nil Ps in allp during cleanup flush

cleanupQueue.Flush is reachable from mallocgc via sweepAssist. Normally
allp will continue all valid Ps, but procresize itself increases the
size of allp and then allocates new Ps to place in allp. If we get
perfectly unlucky, the new(p) allocations will complete sweeping and
cleanupQueue.Flush will dereference a nil pointer from allp. Avoid this
by skipping nil Ps.

I've looked through every other use of allp and none of them appear to
be reachable from procresize.

Change-Id: I6a6a636cab49ef268eb8fcd9ff9a96790d9c5685
Reviewed-on: https://go-review.googlesource.com/c/go/+/676515
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2 months agocrypto/tls: enable signature algorithm BoGo tests (and fix two bugs)
Filippo Valsorda [Fri, 23 May 2025 16:04:36 +0000 (18:04 +0200)]
crypto/tls: enable signature algorithm BoGo tests (and fix two bugs)

The two bugs are very minor:

- We were trying to set the ConnectionState CurveID field even if the
  RSA key exchange was in use

- We were sending the wrong alert from TLS 1.2 clients if none of the
  certificate signature algorithms were supported

Change-Id: I6a6a46564f5a9f1a5d44e54fc59a650118ad67d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/675918
Auto-Submit: Filippo Valsorda <filippo@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2 months agoerrors: add joinError Unwrap example
jiahua wang [Tue, 20 May 2025 05:40:18 +0000 (13:40 +0800)]
errors: add joinError Unwrap example

Change-Id: Id7489247e9bdd413f82fdf5a70197856c47abfb5
Reviewed-on: https://go-review.googlesource.com/c/go/+/674336
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Sean Liao <sean@liao.dev>

2 months agoio/fs: add examples for Glob,ReadFile and ValidPath
cuishuang [Sun, 18 May 2025 08:28:13 +0000 (16:28 +0800)]
io/fs: add examples for Glob,ReadFile and ValidPath

Change-Id: I8451179bc0fa88b7e60afbc6fd9e06a22a94f3aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/673835
Reviewed-by: Sean Liao <sean@liao.dev>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
2 months agolog/slog: make TextHandler discard empty Source
Antonio Pitasi [Wed, 21 May 2025 09:58:13 +0000 (11:58 +0200)]
log/slog: make TextHandler discard empty Source

Fixes #73808

Change-Id: Ica4b7a63eebbf0fff41d68f4de928f9da90c8ada
Reviewed-on: https://go-review.googlesource.com/c/go/+/674875
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agotesting/synctest: correct duration in doc example
Sean Liao [Sat, 24 May 2025 11:10:12 +0000 (12:10 +0100)]
testing/synctest: correct duration in doc example

Fixes #73839

Change-Id: I961641c6d8244cdeb101a3c9ae91931828a893ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/676035
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2 months agohash: mention the new Cloner interface in Hash docs.
Mateusz Poliwczak [Fri, 23 May 2025 17:28:37 +0000 (19:28 +0200)]
hash: mention the new Cloner interface in Hash docs.

We mention that already in Cloner docs, but to be consistent, also
mention that in Hash.

Change-Id: Iee33d545662b7054973666bd45998a37f3037a51
Reviewed-on: https://go-review.googlesource.com/c/go/+/675915
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2 months agocrypto/tls: signature_algorithms in CertificateRequest can't be empty
Filippo Valsorda [Wed, 21 May 2025 20:41:54 +0000 (22:41 +0200)]
crypto/tls: signature_algorithms in CertificateRequest can't be empty

Change-Id: I6a6a4656ab97e1f247df35b2589cd73461b4ac76
Reviewed-on: https://go-review.googlesource.com/c/go/+/675917
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agonet: use runtime.AddCleanup instead of runtime.SetFinalizer
Carlos Amedee [Mon, 23 Dec 2024 16:52:43 +0000 (11:52 -0500)]
net: use runtime.AddCleanup instead of runtime.SetFinalizer

Adds TODO for replacement of runtime.SetFinalizer.

Fixes #70907

Change-Id: Ic009018a93ccc46a776ae34afac44635d2340cbf
Reviewed-on: https://go-review.googlesource.com/c/go/+/638557
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Carlos Amedee <carlos@golang.org>

2 months agoruntime/trace: match traceClockNow types
Michael Pratt [Fri, 23 May 2025 21:31:53 +0000 (17:31 -0400)]
runtime/trace: match traceClockNow types

runtime.traceClockNow returns a (named) uint64. Make the declaration in
runtime/trace match this type.

Change-Id: I6a6a636ce3596cbc6fc5bac3590703b7b4839c4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/675976
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agodoc/next: add crudely processed todos
David Chase [Fri, 23 May 2025 18:49:13 +0000 (14:49 -0400)]
doc/next: add crudely processed todos

This is the output of relnote -goroot=... todo,
with each todo in a comment, followed by summary
text from the issue and perhaps the CL, lightly
processed into markdown.

For #71661.

Change-Id: I855c4c4ee02491b5b6113822baf69dbafb4e54ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/675877
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agonet/http: document that ServeMux.Handler can also synthetize a 405
Filippo Valsorda [Fri, 23 May 2025 10:44:24 +0000 (12:44 +0200)]
net/http: document that ServeMux.Handler can also synthetize a 405

Also, fix a minor typo in ServeMux.Handle and ServeMux.HandleFunc.

Change-Id: I6a6a46565719104cb8f2484daf0e39f35b55a078
Reviewed-on: https://go-review.googlesource.com/c/go/+/675835
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agoruntime/trace: fix flaky test for SetMinAge
Carlos Amedee [Thu, 22 May 2025 17:33:28 +0000 (13:33 -0400)]
runtime/trace: fix flaky test for SetMinAge

This change fixes the flaky test which expects setting SetMinAge to a
small ammount. It expects two sync events but should realistically
expect up to 3.

Change-Id: Ibd02fe55ebca99eb880025eb968fcebae9cb09c9
Reviewed-on: https://go-review.googlesource.com/c/go/+/675597
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agodoc: fix TBD mark
Keith Randall [Thu, 22 May 2025 22:17:37 +0000 (15:17 -0700)]
doc: fix TBD mark

Change-Id: I2133e3c62b4de0cec08eeb120d593c644643a62c
Reviewed-on: https://go-review.googlesource.com/c/go/+/675755
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2 months agodoc: mention stack allocation of variable-sized make calls
Keith Randall [Wed, 16 Apr 2025 20:50:44 +0000 (13:50 -0700)]
doc: mention stack allocation of variable-sized make calls

Also mention the bisect tool and flag used to track down
incorrect uses.

Change-Id: Id36a236e1bb2733b8611b22a5b16916e7d9f5522
Reviewed-on: https://go-review.googlesource.com/c/go/+/666075
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agoruntime: don't spin looking for a tiny alloc address with asan or race
Michael Anthony Knyszek [Thu, 22 May 2025 00:29:14 +0000 (00:29 +0000)]
runtime: don't spin looking for a tiny alloc address with asan or race

CL 674655 modified the checkfinalizers test to spin looking for an
appropriate address to trip the detector, but this doesn't work with
ASAN or in race mode, which both disable the tiny allocator.

Fixes #73834.

Change-Id: I27416da1f29cd953271698551e9ce9724484c683
Reviewed-on: https://go-review.googlesource.com/c/go/+/675395
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2 months agocmd/compile: do not shapify when reading reshaping expr
Cuong Manh Le [Fri, 10 Jan 2025 05:49:59 +0000 (12:49 +0700)]
cmd/compile: do not shapify when reading reshaping expr

Fixes #71184

Change-Id: I22e7ae5203311e86a90502bfe155b0597007887d
Reviewed-on: https://go-review.googlesource.com/c/go/+/641955
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2 months agocmd/compile: fix ICE with recursive alias type parameter
Cuong Manh Le [Fri, 25 Apr 2025 12:13:52 +0000 (19:13 +0700)]
cmd/compile: fix ICE with recursive alias type parameter

CL 585399 fixed an initialization loop during IR contruction that
involving alias type, by avoiding publishing alias declarations until
the RHS type expression has been constructed.

There's an assertion to ensure that the alias's type must be the same
during the initialization. However, that assertion is too strict, since
we may construct different instances of the same type, if the type is an
instantination of generic type.

To fix this, we could use types.IdenticalStrict to ensure that these
types matching exactly.

Updates #66873.
Updates #73309.

Change-Id: I2559bed37e21615854333fb1057d7349406e6a1b
Reviewed-on: https://go-review.googlesource.com/c/go/+/668175
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2 months agocmd/doc: properly set GOPROXY to avoid deprecation checks
Michael Matloob [Thu, 22 May 2025 16:40:51 +0000 (12:40 -0400)]
cmd/doc: properly set GOPROXY to avoid deprecation checks

This change fixes a bug that was introduced in CL 675155. Instead of
doing the two step download and run with GOPROXY=off, do the run with
GOPROXY=<download cache>:$GOPROXY, so that we use the previously
downloaded version of pkgsite as the latest.

Fixes #73833

Change-Id: I8803426498ab026602805d6448a130eb11458c99
Reviewed-on: https://go-review.googlesource.com/c/go/+/675576
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

2 months agoRevert "cmd/doc: better support for no network"
Michael Matloob [Thu, 22 May 2025 16:12:48 +0000 (09:12 -0700)]
Revert "cmd/doc: better support for no network"

This reverts commit 988eb0d11e8d96e8ca150f401ed82326b276f653.

Reason for revert: breaks viewing documentation for unfetched modules

For #73833

Change-Id: I89bc459e820c85e96837d1707058501488a14eef
Reviewed-on: https://go-review.googlesource.com/c/go/+/675575
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
2 months agocmd/compile: fix ICE when transforming loopvar
Cuong Manh Le [Thu, 22 May 2025 11:06:27 +0000 (18:06 +0700)]
cmd/compile: fix ICE when transforming loopvar

When transforming for loop variables, the compiler does roughly
following steps:

(1) prebody = {z := z' for z in leaked}
        ...
        (4) init' = (init : s/z/z' for z in leaked)

However, the definition of z is not updated to `z := z'` statement,
causing ReassignOracle incorrectly use the new init statement with z'
instead of z, trigger the ICE.

Fixing this by updating the correct/new definition statement for z
during the prebody initialization.

Fixes #73823

Change-Id: Ice2a6741be7478506c58f4000f591d5582029136
Reviewed-on: https://go-review.googlesource.com/c/go/+/675475
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
2 months agoruntime: use the immortal weak handle map for sbrk mode
Michael Anthony Knyszek [Tue, 20 May 2025 20:56:46 +0000 (20:56 +0000)]
runtime: use the immortal weak handle map for sbrk mode

Currently weak pointers break in sbrk mode. We can just use the immortal
weak handle map for weak pointers in this case, since nothing is ever
freed.

Fixes #69729.

Change-Id: Ie9fa7e203c22776dc9eb3601c6480107d9ad0c99
Reviewed-on: https://go-review.googlesource.com/c/go/+/674656
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
TryBot-Bypass: Michael Knyszek <mknyszek@google.com>