1
0
mirror of https://github.com/golang/go synced 2024-09-30 22:48:32 -06:00
Commit Graph

57932 Commits

Author SHA1 Message Date
Jonathan Amsterdam
3602465954 net/http: pattern.conflictsWith
Add the conflictsWith method, which determines whether two patterns
conflict with each other.

Updates #61410.

Change-Id: Id4f9a471dc9d0420d927a68d2864128a096b74f4
Reviewed-on: https://go-review.googlesource.com/c/go/+/526616
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Eli Bendersky <eliben@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-12 17:45:33 +00:00
Michael Pratt
4f9fe6d509 runtime: allow update of system stack bounds on callback from C thread
[This is a redo of CL 525455 with the test fixed on darwin by defining
_XOPEN_SOURCE, and disabled with android, musl, and openbsd, which do
not provide getcontext.]

Since CL 495855, Ms are cached for C threads calling into Go, including
the stack bounds of the system stack.

Some C libraries (e.g., coroutine libraries) do manual stack management
and may change stacks between calls to Go on the same thread.

Changing the stack if there is more Go up the stack would be
problematic. But if the calls are completely independent there is no
particular reason for Go to care about the changing stack boundary.

Thus, this CL allows the stack bounds to change in such cases. The
primary downside here (besides additional complexity) is that normal
systems that do not manipulate the stack may not notice unintentional
stack corruption as quickly as before.

Note that callbackUpdateSystemStack is written to be usable for the
initial setup in needm as well as updating the stack in cgocallbackg.

Fixes #62440.
For #62130.

Change-Id: I0fe0134f865932bbaff1fc0da377c35c013bd768
Reviewed-on: https://go-review.googlesource.com/c/go/+/527715
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-09-12 17:08:55 +00:00
Than McIntosh
2399302a25 cmd/compile/internal/base: keep Ctxt.Flag_optimize in sync with Flag.N
This patch fixes an inconsistency in compiler flag handling introduced
accidentally in CL 521699. In the compiler we have both base.Flag.N
(which records whether the user has supplied the "-N" flag to disable
optimization) and base.Ctxt.Flag_optimize (which tracks whether
optimization is turned on). In this case Flag.N was updated without a
corresponding change to Ctxt.Flag_optimize, which led to problems with
DWARF generation for the runtime.

This CL doesn't include a regression test; a test will be added later
in the x/debug repo in a subsequent CL.

Updates #62523.

Change-Id: I0c383bb43ec0a0e7c12e7e2852c0590731416d6f
Reviewed-on: https://go-review.googlesource.com/c/go/+/527319
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Alessandro Arzilli <alessandro.arzilli@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-12 17:01:03 +00:00
qmuntal
94200bf85c all: fix Microsoft links
This CL fixes the links to Microsoft documentation in the Go source
code. Some links were broken and some others were outdated.

Change-Id: I4c3bcd3aa3c07a31be1b7f94c25339dcc2e771e8
Reviewed-on: https://go-review.googlesource.com/c/go/+/527556
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Auto-Submit: Quim Muntal <quimmuntal@gmail.com>
2023-09-12 16:42:41 +00:00
Cuong Manh Le
e50bbae2de cmd/compile: remove typecheck.Orig* functions
Same as CL 526397, but for typecheck.

Change-Id: Ia8f19a54ffaa2ae3b86a4c66cbe6d973482796cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/526236
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-12 16:07:23 +00:00
Matthew Dempsky
aa381c538a cmd/compile/internal/types: remove Type.vargen
The unified frontend diasmbiguates local types by putting vargen
directly into their symbol name instead. We no longer need a separate
int field for it.

Change-Id: I556c588ed68c5e2cb324cd46abd934894b5aaef9
Reviewed-on: https://go-review.googlesource.com/c/go/+/527517
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-12 15:41:17 +00:00
Matthew Dempsky
d9aca84da0 cmd/compile: stop changing Field.Sym for parameters
Field.Sym now always contains the original symbol as it appeared in Go
source, so we don't need OrigSym anymore.

Instead, when the mangled name is desired, Field.Nname.Sym() can be
used instead, which is always non-nil if Nname is non-nil.

Change-Id: I96cd61db6458d4a2e07ec5810239236e3dfba747
Reviewed-on: https://go-review.googlesource.com/c/go/+/527516
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2023-09-12 15:41:15 +00:00
Cherry Mui
e924ea03cc cmd/link: disable DWARF by default in c-shared mode on darwin
Currently, linking a Go c-shared object with C code using Apple's
new linker, it fails with

% cc a.c go.so
ld: segment '__DWARF' filesize exceeds vmsize in 'go.so'

Apple's new linker has more checks for unmapped segments. It is
very hard to make it accept a Mach-O shared object with an
additional DWARF segment.

We may want to stop combinding DWARF into the shared object (see
also #62577). For now, disable DWARF by default in c-shared mode
on darwin. (One can still enable it with -ldflags=-w=0, which will
contain DWARF, but it will need the old C linker to link against
with.)

For #61229.

Change-Id: I4cc77da54fac10e2c2cbcffa92779cba82706d75
Reviewed-on: https://go-review.googlesource.com/c/go/+/527415
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-12 15:31:24 +00:00
Matthew Dempsky
905b58b537 cmd/compile/internal/typecheck: remove HasNamedResults check
types2 has already checked for us that bare returns are valid, so no
need to duplicate the effort in typecheck.

Change-Id: I13b2387173966ba44058fbc841327896e04184e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/527515
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-12 04:52:25 +00:00
Matthew Dempsky
70fc87ee24 cmd/compile: rename OEFACE to OMAKEFACE and remove OCONVIDATA
The "eface" in OEFACE suggests it's only for empty interfaces, and the
documentation suggests that too. But it's actually used for both empty
and non-empty interfaces, so rename to OMAKEFACE and adjust docs
accordingly.

Also, remove OCONVIDATA. This was used by the 1.18 frontend for
constructing interfaces containing derived types, but the unified
frontend always uses OCONVIFACE instead, so this is unused now.

Change-Id: I6ec5c62f909b26027f2804e5b3373b7a00029246
Reviewed-on: https://go-review.googlesource.com/c/go/+/527336
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-12 04:50:32 +00:00
Meng Zhuo
5e31f78c8a internal/cpu: fix wrong cache line size of riscv64
All of riscv CPU using 64B for cache-line size.
i.e. U540 of Hifive Unleashed (https://www.sifive.com/boards/hifive-unleashed)

Change-Id: I0d72d88ac026f45383c3b3eb3a77233d3c2e4004
Reviewed-on: https://go-review.googlesource.com/c/go/+/526659
Run-TryBot: M Zhuo <mzh@golangcn.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-12 01:18:38 +00:00
Ian Lance Taylor
8221f90f13 Revert "os/exec: avoid calling LookPath in cmd.Start for resolved paths"
This reverts CL 512155.

Reason for revert: CL 512155 introduced a race in that it caused
cmd.Start to set cmd.Path. Previously it was fine if code looked
at cmd.Path in one goroutine while calling cmd.Start in a different
goroutine.

A test case for this race is in CL 527495.

Change-Id: Ic18fdadf6763727f8ea748280d5f0e601b9bf374
Reviewed-on: https://go-review.googlesource.com/c/go/+/527337
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-09-12 00:57:26 +00:00
Matthew Dempsky
06138963a2 cmd/compile/internal/ir: remove OSIZEOF, etc
These are no longer needed after the previous CL, which moved handling
of unsafe.Sizeof, etc. directly into the unified frontend.

Change-Id: Ieb35ffca0bc25319e58132fb5d035c5b441acea7
Reviewed-on: https://go-review.googlesource.com/c/go/+/527098
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
2023-09-11 20:48:10 +00:00
Matthew Dempsky
2e457b3868 cmd/compile/internal/noder: handle unsafe.Sizeof, etc in unified IR
Previously, the unified frontend implemented unsafe.Sizeof, etc that
involved derived types by constructing a normal OSIZEOF, etc
expression, including fully instantiating their argument. (When
unsafe.Sizeof is applied to a non-generic type, types2 handles
constant folding it.)

This worked, but involves unnecessary work, since all we really need
to track is the argument type (and the field selections, for
unsafe.Offsetof).

Further, the argument expression could generate temporary variables,
which would then go unused after typecheck replaced the OSIZEOF
expression with an OLITERAL. This results in compiler failures after
CL 523315, which made later passes stricter about expecting the
frontend to not construct unused temporaries.

Fixes #62515.

Change-Id: I37baed048fd2e35648c59243f66c97c24413aa94
Reviewed-on: https://go-review.googlesource.com/c/go/+/527097
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
2023-09-11 20:48:07 +00:00
Andy Pan
f72693d3e9 log/slog: generate valid JSON string with empty attributes in Groups
Fixes #62152

Change-Id: I1f76ab26eae3a44292ebe6003006258d5e31d50f
Reviewed-on: https://go-review.googlesource.com/c/go/+/521135
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Andy Pan <panjf2000@gmail.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-11 20:29:15 +00:00
David Anderson
94f24fd054 net/netip: add AddrPort.Compare and Prefix.Compare
Fixes #61642

Change-Id: I2262855dbe75135f70008e5df4634d2cfff76550
GitHub-Last-Rev: 949685a9e4
GitHub-Pull-Request: golang/go#62387
Reviewed-on: https://go-review.googlesource.com/c/go/+/524616
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2023-09-11 20:26:41 +00:00
qiulaidongfeng
dfb2e4265b cmd/go: cache results of exec.LookPath
This CL package exec.LookPath to internal/cfg.LookPath and adds cache.

BenchmarkLookPath-4     24149096                50.48 ns/op            0 B/op          0 allocs/op

Fixes #36768

Change-Id: I199a780d1eab9bd5397bb3759bb42191fff716e9

Change-Id: I199a780d1eab9bd5397bb3759bb42191fff716e9
GitHub-Last-Rev: d67aa826f4
GitHub-Pull-Request: golang/go#61464
Reviewed-on: https://go-review.googlesource.com/c/go/+/511458
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-11 20:12:18 +00:00
Matthew Dempsky
afa3f8e104 cmd/compile/internal/staticinit: make staticopy safe
Currently, cmd/compile optimizes `var a = true; var b = a` into `var a
= true; var b = true`. But this may not be safe if we need to
initialize any other global variables between `a` and `b`, and the
initialization involves calling a user-defined function that reassigns
`a`.

This CL changes staticinit to keep track of the initialization
expressions that we've seen so far, and to stop applying the
staticcopy optimization once we've seen an initialization expression
that might have modified another global variable within this package.

To help identify affected initializers, this CL adds a -d=staticcopy
flag to warn when a staticcopy is suppressed and turned into a dynamic
copy.

Currently, `go build -gcflags=all=-d=staticcopy std` reports only four
instances:

```
encoding/xml/xml.go:1600:5: skipping static copy of HTMLEntity+0 with map[string]string{...}
encoding/xml/xml.go:1869:5: skipping static copy of HTMLAutoClose+0 with []string{...}
net/net.go:661:5: skipping static copy of .stmp_31+0 with poll.ErrNetClosing
net/http/transport.go:2566:5: skipping static copy of errRequestCanceled+0 with ~R0
```

Fixes #51913.

Change-Id: Iab41cf6f84c44f7f960e4e62c28a8aeaade4fbcf
Reviewed-on: https://go-review.googlesource.com/c/go/+/395541
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2023-09-11 20:12:05 +00:00
Matthew Dempsky
1cdabf0c8b runtime: avoid staticinit dependency with sigsetAllExiting
Currently, package runtime runs `osinit` before dynamic initialization
of package-scope variables; but on GOOS=linux, `osinit` involves
mutating `sigsetAllExiting`.

This currently works because cmd/compile and gccgo have
non-spec-conforming optimizations that statically initialize
`sigsetAllExiting`, but disabling that optimization causes
`sigsetAllExiting` to be dynamically initialized instead. This in turn
causes the mutations in `osinit` to get lost.

This CL moves the initialization of `sigsetAllExiting` from `osinit`
into its initialization expression, and then removes the special case
for continuing to perform the static-initialization optimization for
package runtime.

Updates #51913.

Change-Id: I3be31454277c103372c9701d227dc774b2311dad
Reviewed-on: https://go-review.googlesource.com/c/go/+/405549
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-11 20:10:52 +00:00
Matthew Dempsky
3556d3b9bf cmd/compile/internal/ir: add missing SetTypecheck
This was missed earlier, because NewConstAt is only used now to
construct the predeclared "true" and "false" constants. But these
constants are no longer actually accessed with unified IR.

For constant expressions, types2 (and go/types) sets
TypeAndValue.Value for the expression to the appropriate constant
value. The unified writer recognizes when expressions are constants,
and simply writes the underlying value, regardless of the original
expression. As a result, we never end up actually referencing the
*named* "true" and "false" constants; we just always construct
anonymous constant "true" and "false" values.

However, a manually constructed tree that includes an *ir.Name that
"Uses" the predeclared true/false Const Objects, yet doesn't set
TypeAndValue.Value will instead end up trying to use named constants
constructed with NewConstAt.

Thanks to Russ for reporting the issue on CL 510541, and to Cuong for
identifying the fix.

Change-Id: I0614105379d63ea76d7244ebd1e4db5c239d4670
Reviewed-on: https://go-review.googlesource.com/c/go/+/524357
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-11 20:08:58 +00:00
Jonathan Amsterdam
09465129bd net/http: extended routing patterns
This is the first of several CLs implementing the proposal
for enhanced ServeMux routing, https://go.dev/issue/61410.

Define a type to represent extended routing patterns and a function to
parse a string into one.

Updates #61410.

Change-Id: I779689acf1f14b20d12c9264251f7dc002b68c49
Reviewed-on: https://go-review.googlesource.com/c/go/+/526815
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Eli Bendersky <eliben@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-11 17:11:17 +00:00
Than McIntosh
a86ef0409b cmd/compile/internal/inline/inlheur: fixup tests for NewBasicLit change
Fix a regression test to use the correct new signature for
ir.NewBasicLit.

Change-Id: I06c849e83a5edfce784c780b5490f461f6c3b129
Reviewed-on: https://go-review.googlesource.com/c/go/+/527318
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Than McIntosh <thanm@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-11 16:46:17 +00:00
Michael Pratt
ea8c05508b Revert "runtime: allow update of system stack bounds on callback from C thread"
This reverts CL 525455. The test fails to build on darwin, alpine, and
android.

For #62440.

Change-Id: I39c6b1e16499bd61e0f166de6c6efe7a07961e62
Reviewed-on: https://go-review.googlesource.com/c/go/+/527317
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-09-11 16:35:56 +00:00
Michael Pratt
c0c4a59816 Revert "runtime: set stackguard1 on extra M g0"
This reverts CL 527056.

CL 525455 breaks darwin, alpine, and android. This CL must be reverted
in order to revert that CL.

For #62440.

Change-Id: I4e1b16e384b475a605e0214ca36c918d50faa22c
Reviewed-on: https://go-review.googlesource.com/c/go/+/527316
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-11 16:35:54 +00:00
Michael Pratt
298e848864 runtime: don't clear procid on netbsd
This is a partial revert of CL 526118.

NetBSD uses mp.procid in locking (semawake). unminit is called
surprisingly early in mexit, and there is definitely locking after that
point, so it isn't safe to clear procid so early.

Fixes #62524.
Fixes #62531.

Change-Id: Iefbef63e84fc0395e255970a301401e1187a910d
Reviewed-on: https://go-review.googlesource.com/c/go/+/527057
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-09-11 16:15:14 +00:00
Matthew Dempsky
972fc055eb cmd/compile/internal/ir: add Type param to NewBasicLit
This CL adds an explicit Type parameter to NewBasicLit so that callers
can directly construct typed OLITERAL nodes.

Change-Id: I0ab50ac3d7ddb7adcc903633a62ac496921165e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/527096
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-09-11 16:04:33 +00:00
Matthew Dempsky
e3ce312621 cmd/compile/internal/typecheck: fix closure field naming
When creating the struct type to hold variables captured by a function
literal, we currently reuse the captured variable names as fields.

However, there's no particular reason to do this: these struct types
aren't visible to users, and it adds extra complexity in making sure
fields belong to the correct packages.

Further, it turns out we were getting that subtly wrong. If two
function literals from different packages capture variables with
identical names starting with an uppercase letter (and in the same
order and with corresponding identical types) end up in the same
function (e.g., due to inlining), then we could end up creating
closure struct types that are "different" (i.e., not types.Identical)
yet end up with equal LinkString representations (which violates
LinkString's contract).

The easy fix is to just always use simple, exported, generated field
names in the struct. This should allow further struct reuse across
packages too, and shrink binary sizes slightly.

Fixes #62498.

Change-Id: I9c973f5087bf228649a8f74f7dc1522d84a26b51
Reviewed-on: https://go-review.googlesource.com/c/go/+/527135
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: 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>
2023-09-11 16:02:11 +00:00
Michael Pratt
9af74e711a runtime: set stackguard1 on extra M g0
Standard Ms set g0.stackguard1 to the same value as stackguard0 in
mstart0. For consistency, extra Ms should do the same for their g0. Do
this in needm -> callbackUpdateSystemStack.

Background: getg().stackguard1 is used as the stack guard for the stack
growth prolouge in functions marked //go:systemstack [1]. User Gs set
stackguard1 to ^uintptr(0) so that the check always fail, calling
morestackc, which throws to report a //go:systemstack function call on a
user stack.

g0 setting stackguard1 is unnecessary for this functionality. 0 would be
sufficient, as g0 is always allowed to call //go:systemstack functions.
However, since we have the check anyway, setting stackguard1 to the
actual stack bound is useful to detect actual stack overflows on g0
(though morestackc doesn't detect this case and would report a
misleading message about user stacks).

[1] cmd/internal/obj calls //go:systemstack functions AttrCFunc. This is
a holdover from when the runtime contained actual C functions. But since
CL 2275, it has simply meant "pretend this is a C function, which would
thus need to use the system stack". Hence the name morestackc. At this
point, this terminology is pretty far removed from reality and should
probably be updated to something more intuitive.

Change-Id: I8d0e5628ce31ac6a189a7d7a4124be85aef89862
Reviewed-on: https://go-review.googlesource.com/c/go/+/527056
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-09-11 14:46:55 +00:00
Michael Pratt
a46b1ad357 runtime: allow update of system stack bounds on callback from C thread
Since CL 495855, Ms are cached for C threads calling into Go, including
the stack bounds of the system stack.

Some C libraries (e.g., coroutine libraries) do manual stack management
and may change stacks between calls to Go on the same thread.

Changing the stack if there is more Go up the stack would be
problematic. But if the calls are completely independent there is no
particular reason for Go to care about the changing stack boundary.

Thus, this CL allows the stack bounds to change in such cases. The
primary downside here (besides additional complexity) is that normal
systems that do not manipulate the stack may not notice unintentional
stack corruption as quickly as before.

Note that callbackUpdateSystemStack is written to be usable for the
initial setup in needm as well as updating the stack in cgocallbackg.

Fixes #62440.
For #62130.

Change-Id: I7841b056acea1111bdae3b718345a3bd3961b4a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/525455
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-11 14:46:41 +00:00
qiulaidongfeng
5eb382fc08 cmd/compile/internal/typecheck: use constant.MakeUnknown()
Complete a TODO.

Change-Id: I1bd23f0be725c9dd81b8316a7abba1bceecc346f

Change-Id: I1bd23f0be725c9dd81b8316a7abba1bceecc346f
GitHub-Last-Rev: 51523084a3
GitHub-Pull-Request: golang/go#62553
Reviewed-on: https://go-review.googlesource.com/c/go/+/527178
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
2023-09-10 23:21:34 +00:00
Kirill Che
ee788dbae0 cmd/go/internal/generate: error if failed to find a package
Add check for package loader to print error and fail `go generate` command,
if package can not be found.

Fixes #60079

Change-Id: Ib9e730c2b69df6e5ac307c7bdfea0ee993ab6ed8
GitHub-Last-Rev: d93332425a
GitHub-Pull-Request: golang/go#60178
Reviewed-on: https://go-review.googlesource.com/c/go/+/494836
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-09 01:48:44 +00:00
Jes Cok
267323ef2d all: calculate the median uniformly
Like sort.Search, use "h := int(uint(i+j) >> 1)" style code to calculate
the median.

Change-Id: Ifb1a19dde1c6ed6c1654bc642fc9565a8b6c5fc4
GitHub-Last-Rev: e2213b7388
GitHub-Pull-Request: golang/go#62503
Reviewed-on: https://go-review.googlesource.com/c/go/+/526496
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-09-09 01:46:03 +00:00
Dmitri Shuralyov
4651c0c6d9 cmd/compile/internal/inline/inlheur: delete ConstExpr case
ir.ConstExpr was deleted in CL 526395, so no need to check for it.
Fixes the build error.

Change-Id: I642dab70d17369bc7c9ae880666ef42ff099b770
Reviewed-on: https://go-review.googlesource.com/c/go/+/526196
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-09-08 23:42:54 +00:00
Than McIntosh
b7a2f62c71 Revert "cmd/cgo: silence unaligned-access"
This reverts commit http://go.dev/cl/c/go/+/526915

Reason for revert: darwin builders unhappy with '-Wunaligned-access' C compiler flag

Change-Id: I5e6ca7c9a0ca08b7e758b7f603da70a2fca79b58
Reviewed-on: https://go-review.googlesource.com/c/go/+/526978
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Than McIntosh <thanm@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-08 23:22:51 +00:00
Than McIntosh
3997fb9243 runtime: test change to adapt to new inliner
The new inliner tries to de-prioritize inlining of call sites on panic
paths, e.g. for a call such as the one to "foo" below, the inliner
will use a much lower size threshold when deciding whether to inline,
since the path is very likely to be "cold".

   if mumble() {
      foo()           <<-- here
      panic("bad")
   }

This patch reworks one of the traceback tests is relying on the old
inliner's "inline F everywhere if F inlinable" strategy by tweaking
the code slightly (no change in test functionality).

Change-Id: I83a686b0cc4d94a6cfc63d1e84e45455c1afd5b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/519196
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-09-08 23:04:18 +00:00
Than McIntosh
746f7e1744 cmd/compile/internal/inline/inlheur: assign scores to callsites
Assign scores to callsites based on previously computed function
properties and callsite properties. This currently works by taking the
size score for the function (as computed by CanInline) and then making
a series of adjustments, positive or negative based on various
function and callsite properties.

NB: much work also remaining on deciding what are the best score
adjustment values for specific heuristics. I've picked a bunch of
arbitrary constants, but they will almost certainly need tuning and
tweaking to arrive at something that has good performance.

Updates #61502.

Change-Id: I887403f95e76d7aa2708494b8686c6026861a6ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/511566
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-08 23:03:48 +00:00
Than McIntosh
dc0548f92f cmd/compile/internal/inline: add call site flag generation
Add code to detect call sites that are nested in loops, call sites
that are on an unconditional path to panic/exit, and call sites within
"init" functions. The panic-path processing reuses some of the
logic+state already present for the function flag version of "calls
panic/exit".

Updates #61502.

Change-Id: I1d728e0763282d3616a9cbc0a07c5cda115660f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/511565
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-08 23:03:23 +00:00
Than McIntosh
19ca2337c5 cmd/compile/internal/inline: build call site table
Build up a table of (potentially) inlinable call sites during inline
heuristic analysis, and introduce a framework for analyzing each call
site to collect applicable flags (for example, is call nested in
loop). This patch doesn't include any of the flag analysis, just the
machinery to collect the callsites and a regression test harness.

Updates #61502.

Change-Id: Ieaf4a008ac9868e9762c63f5b59bd264dc71ab30
Reviewed-on: https://go-review.googlesource.com/c/go/+/511564
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-08 23:03:03 +00:00
Than McIntosh
d2024a091d cmd/compile/internal/inline: extend flag calculation via export data
Extend the code that computes various properties and parameter flags
to incorporate information from export data in addition to things we
can get from the current package. Specifically:

 - when deciding whether the current function always calls panic/exit,
   check to see whether it has an unconditional call to some other
   function that has that flag.

 - when computing "parameter feeds" properties, look not just for
   cases where a parameter feeds an interesting construct (if/switch,
   indirect/interface call, etc) but where it feeds a call whose
   corresponding param has that flag.

 - when computing return properties, if a given return is always the
   results of a call to X, then set the return properties to those
   of X.

Updates #61502.

Change-Id: I6472fe98759cccad05b8eed58e4fc568201d88ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/511563
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-08 23:02:38 +00:00
Than McIntosh
323cf73091 cmd/compile: write "properties" to export data for inlinable funcs
Augment the ir.Inline container to include an entry for function
properties (currently serialized as a string), and if
GOEXPERIMENT=newinliner is set, compute and store function
properties for all inline candidates processed by the inliner.

The idea here is that if the function properties are going to drive
inlining decisions, we'd like to have the same info from non-local /
imported functions as for local / in-package functions, hence we need
to include the properties in the export data.

Hand testing on the compiler itself and with k8s kubelet shows that
this increases the size of export data overall by about 2-3 percent,
so a pretty modest increase.

Updates #61502.

Change-Id: I9d1c311aa8418d02ffea3629c3dd9d8076886d15
Reviewed-on: https://go-review.googlesource.com/c/go/+/511562
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-09-08 23:02:15 +00:00
Than McIntosh
906a073b0b cmd/compile/internal/inline: analyze function param properties
Add code to analyze properties of function params, specifically
heuristics to look for cases where unmodified params feed into "if"
and "switch" statements in ways that might enable constant folding
and/or dead code elimination if the call were inlined at a callsite
that passes a constant to the correct param. We also look for cases
where a function parameter feeds unmodified into an interface method
call or indirect call.

Updates #61502.

Change-Id: Iaf7297e19637daeabd0ec72be88d654b545546ae
Reviewed-on: https://go-review.googlesource.com/c/go/+/511561
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-09-08 23:01:53 +00:00
Egon Elbre
2fe2f08542 cmd/cgo: silence unaligned-access
Clang 14+ introduced a warning when using mixed packed and unpacked structs.
This can cause problems when taking an address of the unpacked struct, which
may end up having a different alignment than expected.

This is not a problem in cgo, which does not take pointers from the packed
struct.

Fixes #62480

Change-Id: If5879eea5e1b77bc6dc7430f68f8c916bff9b090
Reviewed-on: https://go-review.googlesource.com/c/go/+/526915
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-08 22:57:46 +00:00
Bryan C. Mills
2e7e1d2e8d net: synchronize calls to Close in the withTCPConnPair test helper
withTCPConnPair is supposed to return only when both peer functions
have completed. However, due to the use of "defer" it was closing the
peers' connections after the synchronization point instead of before.

Fixes #62542.

Change-Id: I3e06c78984664172ff2d28b0fc582b8182f710f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/526977
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Commit-Queue: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-08 20:56:46 +00:00
Jonathan Amsterdam
a742ae493f testing/slogtest: add Run to run cases as subtests
This is an implementation of proposal #61758.

It adds a function to slogtest that runs each test case in a subtest,
instead of running them all at once.

That allows the caller to control which cases are run.

Fixes #61706.
Fixes #61758.

Change-Id: I95108b7b753675203ca7f0f00ccbc242bd9c2a9f
Reviewed-on: https://go-review.googlesource.com/c/go/+/516076
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
2023-09-08 20:37:12 +00:00
Michael Pratt
af3bf866b1 runtime: dump rdx on windows
CL 177090043 accidentally dropped RDX when converting from C.

Change-Id: I6bf9dc1b1d0c2850967005c048245d1185dcede4
Reviewed-on: https://go-review.googlesource.com/c/go/+/526976
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
2023-09-08 20:27:22 +00:00
Cherry Mui
dfbf809f2a runtime: unskip TestG0StackOverflow
The stack bounds from pthread are not always accurate, and could
cause seg fault if we run out of the actual stack space before
reaching the bounds. Here we use an artificially small stack bounds
to check overflow without actually running out of the system stack.

Change-Id: I8067c5e1297307103b315d9d0c60120293b57aab
Reviewed-on: https://go-review.googlesource.com/c/go/+/523695
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-08 19:14:29 +00:00
Matthew Dempsky
5d9e0be159 cmd/compile/internal/ssa: replace Frontend.Auto with Func.NewLocal
Change-Id: I0858568d225daba1c318842dc0c9b5e652dff612
Reviewed-on: https://go-review.googlesource.com/c/go/+/526519
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2023-09-08 19:09:14 +00:00
Matthew Dempsky
5d6f835b3e cmd/compile/internal/ssagen: call AllocFrame after ssa.Compile
This indirection is no longer necessary.

Change-Id: Ibb5eb1753febdc17a93ea9c35130e3d2b26c360e
Reviewed-on: https://go-review.googlesource.com/c/go/+/526518
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
2023-09-08 19:05:18 +00:00
Joe Tsai
dac9b9ddbd encoding: modernize Go documentation
Across all encoding packages, linkify declarations if possible.
In some cases, we convert a code block into a bulleted list,
which then further allows for more linkification.

Change-Id: I68fedf362615b34228bab5d4859b7d87d831c570
Reviewed-on: https://go-review.googlesource.com/c/go/+/524977
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: qiulaidongfeng <2645477756@qq.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-09-08 19:04:28 +00:00
Matthew Dempsky
45d3d10071 cmd/compile/internal/ssa: rename ssagen.TypeOK as CanSSA
No need to indirect through Frontend for this.

Change-Id: I5812eb4dadfda79267cabc9d13aeab126c1479e3
Reviewed-on: https://go-review.googlesource.com/c/go/+/526517
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-08 19:03:54 +00:00