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

53780 Commits

Author SHA1 Message Date
hopehook
396b153ec4 testing: add Elapsed method to testing.B
Elapsed returns the measured elapsed time of the benchmark,
but does not change the running state of the timer.

Fixes #43620.

Change-Id: Idd9f64c4632518eec759d2ffccbf0050d84fcc03
Reviewed-on: https://go-review.googlesource.com/c/go/+/420254
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: hopehook <hopehook@qq.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-08-25 17:58:32 +00:00
Robert Griesemer
83b5fe6351 go/types: match types2 string when printing composite literals
Given a composite literal type S, rather than always printing
(S literal) for a composite literals, print S{} if the literal
has no elements, and print S{…} as a short form (suitable for
error messages) if there are elements. This matches types2 and
also Go1.17 compiler behavior (except that the original compiler
would print ... rather than …). Using … rather than ... makes
it clearer that we don't have real Go syntax, and it's also more
compact.

For #54511.

Change-Id: I5991e8060232f16ecbf4a1fe4ae091598fc76b68
Reviewed-on: https://go-review.googlesource.com/c/go/+/425006
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-08-25 17:31:33 +00:00
Filippo Valsorda
1df2a03b17 crypto/tls: support ECDHE when ec_point_formats is missing
Fixes #49126

Change-Id: I9d6f6392b1a6748bdac1d2c6371b22d75829a2b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/425295
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Alex Scheel <alex.scheel@hashicorp.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2022-08-25 16:35:38 +00:00
Cherry Mui
e4be2ac79f runtime: mark morestack_noctxt SPWRITE on LR architectures
On LR architectures, morestack (and morestack_noctxt) are called
with a special calling convention, where the caller doesn't save
LR on stack but passes it as a register, which morestack will save
to g.sched.lr. The stack unwinder currently doesn't understand it,
and would fail to unwind from it. morestack already writes SP (as
it switches stack), but morestack_noctxt (which tailcalls
morestack) doesn't. If a profiling signal lands right in
morestack_noctxt, the unwinder will try to unwind the stack and
go off, and possibly crash.

Marking morestack_noctxt SPWRITE stops the unwinding.

Ideally we could teach the unwinder about the special calling
convention, or change the calling convention to be less special
(so the unwinder doesn't need to fetch a register from the signal
context). This is a stop-gap solution, to stop the unwinder from
crashing.

Fixes #54332.

Change-Id: I75295f2e27ddcf05f1ea0b541aedcb9000ae7576
Reviewed-on: https://go-review.googlesource.com/c/go/+/425396
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2022-08-25 14:56:18 +00:00
Lynn Boger
d4ff25ac69 misc/cgo/testsanitizers: determine compiler version for tsan tests on ppc64le
Some tests in misc/cgo/testsanitizers had been disabled on ppc64le
until recently, due to an intermittent error in the tsan tests,
with the goal of trying to understand the failure.

After further investigation, I found that the code for tsan within
gcc does not work consistently when ASLR is enabled on ppc64le. A
fix for that problem was integrated in gcc 9.

This adds a check to testsanitizers to determine the gcc compiler
version on ppc64le and skip the test if the version is too old.

A similar check is needed for asan too.

Updates #54645

Change-Id: I70717d1aa9e967cf1e871566e72b3862b91fea3f
Reviewed-on: https://go-review.googlesource.com/c/go/+/425355
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Archana Ravindar <aravind5@in.ibm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
2022-08-25 11:40:57 +00:00
Robert Griesemer
8c8429fe41 go/types, types2: add more tests for unsafe.Slice/SliceData/String/StringData
Also:
- fine-tune the implementation for some of the new builtin functions
- make sure the go/types code is an exact as possible copy of the
  types2 code
- fix the description and examples for errorcodes.go

Follow-up on CL 423754.

For #53003.

Change-Id: I5c70b74e90c724cf6c842cedc6f8ace26fde372b
Reviewed-on: https://go-review.googlesource.com/c/go/+/425454
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-08-25 04:00:07 +00:00
cuiweixie
ba5deb408f go/types,types2: add support for unsafe.{String,StringData,SliceData}
For #53003
Change-Id: Id3125268523fed855ffac20cde6128010e3513f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/423754
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-24 22:39:01 +00:00
Matthew Dempsky
e4bed415ea go/internal/gcimporter: call Complete on cloned Interfaces too
For "type T interface{ M() }", go/types users expect T's underlying
interface type to specify T as the receiver parameter type (#49906).
The unified importer handles this by cloning the interface to rewrite
the receiver parameters before calling SetUnderlying.

I missed in CL 425360 that these interfaces would need to have
Complete called too.

Manually tested to confirm that this actually fixes "go test -race
golang.org/x/tools/go/analysis/internal/checker" now (when both CLs
are ported to the x/tools importer).

Updates #54653.

Change-Id: I51e6db925db56947cd39dbe880230f14734ca01c
Reviewed-on: https://go-review.googlesource.com/c/go/+/425365
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-08-24 21:09:24 +00:00
Matthew Dempsky
bdf2db7255 go/internal/gcimporter: call Interface.Complete in unified importer
To support concurrent use of the go/types API, importers need to call
Interface.Complete on constructed interfaces before returning.

There's an issue that the interfaces may contain embedded defined
types, whose underlying type isn't known yet. This issue will
eventually go away once CL 424876 lands, but that CL needs to wait for
CL 424854 to re-land, which needs to wait for CL 421879 to land...

In the mean time, this CL implements the same solution used by the
indexed importer: maintaining a list of constructed interfaces, and
calling Interface.Complete on them after the SetUnderlying loop and
just before returning the imported package.

Updates #54653.

Change-Id: I0f42c915a4b7d28c628bbab7ac2eab2415c7858f
Reviewed-on: https://go-review.googlesource.com/c/go/+/425360
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-08-24 19:39:31 +00:00
Dmitri Shuralyov
8188bf69f0 doc/go1.20: populate initial TODOs via relnote
Add content generated by 'relnote -html'. This covers all of known
TODOs available by 2022-08-24 such that relnote produces no output
when -exclude-from=doc/go1.20.html flag is used.

For #54202.

Change-Id: Icd9be5364bc73c3de56d5d3039e6f313908af38e
Reviewed-on: https://go-review.googlesource.com/c/go/+/425354
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
2022-08-24 18:36:56 +00:00
Wayne Zuo
b60432df14 cmd/compile: deadcode for LoweredMuluhilo on riscv64
This is a follow up of CL 425101 on RISCV64.

According to RISCV Volume 1, Unprivileged Spec v. 20191213 Chapter 7.1:
If both the high and low bits of the same product are required, then the
recommended code sequence is: MULH[[S]U] rdh, rs1, rs2; MUL rdl, rs1, rs2
(source register specifiers must be in same order and rdh cannot be the
same as rs1 or rs2). Microarchitectures can then fuse these into a single
multiply operation instead of performing two separate multiplies.

So we should not split Muluhilo to separate instructions.

Updates #54607

Change-Id: If47461f3aaaf00e27cd583a9990e144fb8bcdb17
Reviewed-on: https://go-review.googlesource.com/c/go/+/425203
Auto-Submit: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-08-24 18:08:33 +00:00
Dmitri Shuralyov
cfae70ccb1 doc: start draft Go 1.20 release notes
This initial release notes template is based on previous releases.
CL 425354 adds initial content generated by 'relnote -html'.

For #54202.

Change-Id: I36e15723edc9610d61986ba226ee84c2b30a33af
Reviewed-on: https://go-review.googlesource.com/c/go/+/425334
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-24 17:56:56 +00:00
Alexander Yastrebov
8a86b94aef net/http: remove unused doneChan
The https://golang.org/cl/43230 removed use of `getDoneChan`.

Change-Id: I33390c0e3aea6d98367363773ebe39d9c1f64ae9
GitHub-Last-Rev: fe1e4154ea
GitHub-Pull-Request: golang/go#53172
Reviewed-on: https://go-review.googlesource.com/c/go/+/409538
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: hopehook <hopehook@qq.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-24 17:12:07 +00:00
Bryan C. Mills
2fc21b50e4 cmd/go: skip link_syso tests in short mode
These tests invoke the system C compiler and linker.
Skipping them saves a little over half a second of time in short mode.

Updates #54423.

Change-Id: I3e8aa7b53c0c91f7d1e001ec2cd5f7b4954de52d
Reviewed-on: https://go-review.googlesource.com/c/go/+/425206
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-08-24 16:06:46 +00:00
Bryan C. Mills
55d96f98ef cmd/go/internal/work: make NewBuilder safe for concurrent and repeated use
Ever since 'go build' was added (in CL 5483069), it has used an atexit
handler to clean up working directories. At some point (prior to CL
95900044), Init was called multiple times per builder, registering
potentially many atexit handlers that execute asynchronously and make
debugging more difficult.

The use of an AtExit handler also makes the Builder (and anything that
uses it) prone to races: the base.AtExit API is not designed for
concurrent use, but cmd/go is becoming increasingly concurrent over
time. The AtExit handler also makes the Builder inappropriate to use
within a unit-test, since the handlers do not run during the test
function and accumulate over time.

This change makes NewBuilder safe for concurrent use by registering
the AtExit handler only once (during BuildInit, which was already not
safe for concurrent use), and using a sync.Map to store the set of
builders that need cleanup in case of an unclean exit. In addition, it
causes the test variant of cmd/go to fail if any Builder instance
leaks from a clean exit, helping to ensure that functions that create
Builders do not leak them indefinitely, especially in tests.

Updates #54423.

Change-Id: Ia227b15b8fa53c33177c71271d756ac0858feebe
Reviewed-on: https://go-review.googlesource.com/c/go/+/425254
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-08-24 16:06:13 +00:00
Bryan C. Mills
3083529367 cmd/go: avoid overwriting cached Origin metadata
Fixes #54631.

Change-Id: I17d2fa282642aeb1ae2a6e29a0756b8960bea34b
Reviewed-on: https://go-review.googlesource.com/c/go/+/425255
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2022-08-24 16:00:07 +00:00
Bryan C. Mills
d5aa088d82 cmd/go: avoid registering AtExit handlers in tests
Ever since 'go build' was added (in CL 5483069), it has used an atexit
handler to clean up working directories.

CL 154109 introduced 'cc' command to the script test framework that
called Init on a builder once per invocation. Unfortunately, since
base.AtExit is unsynchronized, the Init added there caused any script
that invokes that command to be unsafe for concurrent use.

This change fixes the race by having the 'cc' command pass in its
working directory instead of allowing the Builder to allocate one.
Following modern Go best practices, it also replaces the in-place Init
method (which is prone to typestate and aliasing bugs) with a
NewBuilder constructor function.

Fixes #54423.

Change-Id: I8fc2127a7d877bb39a1174e398736bb51d03d4d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/425205
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2022-08-24 15:37:38 +00:00
Matthew Dempsky
f983a9340d cmd/compile: defer transitive inlining until after AST is edited
This CL changes the inliner to process transitive inlining iteratively
after the AST has actually been edited, rather than recursively and
immediately. This is important for handling indirect function calls
correctly, because ir.reassigned walks the function body looking for
reassignments; whereas previously the inlined reassignments might not
have been actually added to the AST yet.

Fixes #54632.

Change-Id: I0dd69813c8a70b965174e0072335bc00afedf286
Reviewed-on: https://go-review.googlesource.com/c/go/+/425257
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
2022-08-24 14:31:08 +00:00
Nigel Tao
b5a9459cd0 image/png: have DecodeConfig read tRNS chunks
Fixes #54325

Change-Id: Ie468180c4d6f21db7672dd71bd2a40f3a5881b7d
Reviewed-on: https://go-review.googlesource.com/c/go/+/424917
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-08-24 12:12:12 +00:00
Joe Tsai
1ab6b790be reflect: optimize Value.IsZero
If a struct or array is comparable, then we can leverage rtype.equal,
which is almost always faster than what Go reflection can achieve.

As a secondary optimization, pre-compute Value.Len and Value.NumField
outside of the loop conditional.

Performance:

	name                       old time/op  new time/op  delta
	IsZero/ArrayComparable      136ns ± 4%    16ns ± 1%  -88.28%  (p=0.008 n=5+5)
	IsZero/ArrayIncomparable    197ns ±10%   123ns ± 1%  -37.74%  (p=0.008 n=5+5)
	IsZero/StructComparable    26.4ns ± 0%   9.6ns ± 1%  -63.68%  (p=0.016 n=4+5)
	IsZero/StructIncomparable  43.5ns ± 1%  27.8ns ± 1%  -36.21%  (p=0.008 n=5+5)

The incomparable types gain a performance boost since
they are generally constructed from nested comparable types.

Change-Id: If2c1929f8bb1b5b19306ef0c69f3c95a27d4b60d
Reviewed-on: https://go-review.googlesource.com/c/go/+/411478
Reviewed-by: Dan Kortschak <dan@kortschak.io>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-24 08:17:52 +00:00
Andy Pan
1a8dfadbfe encoding/json: move some misplaced benchmark tests to bench_test.go
Change-Id: I5987eed00ee825421abe62699a06e9b66499f35f
Reviewed-on: https://go-review.googlesource.com/c/go/+/425016
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-24 05:40:28 +00:00
Cuong Manh Le
75cdd2c75d internal/singleflight: make DoChan only return Result channel
So next CL can delete "internal/singleflight" and vendor
"golang.org/x/sync/singleflight" instead.

For #31697

Change-Id: I020da1e5a48d484637b538c010029218f5a4a744
Reviewed-on: https://go-review.googlesource.com/c/go/+/423655
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-24 02:54:32 +00:00
Cuong Manh Le
7ee220c567 net: avoid relying on singleflight.Group.DoChan to detect hook called
So next CLs can revert changes to "internal/singleflight" in CL #82795,
then replace it with "golang.org/x/sync/singleflight" instead.

For #31697

Change-Id: I873ce30d7e051539aa6dc5d4f21e558869a6d132
Reviewed-on: https://go-review.googlesource.com/c/go/+/423654
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-08-24 02:23:58 +00:00
Wayne Zuo
1dcef7b3bd cmd/internal/obj/loong64: add MASKEQZ and MASKNEZ instructions support
Change-Id: Ied16c3be47c863a94d46bd568191057ded4b7d0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/416734
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: xiaodong liu <teaofmoli@gmail.com>
2022-08-23 23:17:55 +00:00
Keith Randall
aa4299735b runtime/pprof: remove round-to-file-start adjustment
This causes a problem in the test sometimes. With a mapping like:

00400000-00411000 r--p 00000000 fe:01 4459044                            /tmp/go-build1710804385/b001/pprof.test
00411000-00645000 r-xp 00011000 fe:01 4459044                            /tmp/go-build1710804385/b001/pprof.test

The removed code would make the first mapping 0x400000-0x645000. Tests
then grab the first few addresses to use as PCs, thinking they are in
an executable range. But those addresses are really not in an
executable range, causing the tests to fail.

Change-Id: I5a69d0259d1fd70ff9745df1cbad4d54c5898e7b
Reviewed-on: https://go-review.googlesource.com/c/go/+/424295
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
2022-08-23 23:11:53 +00:00
Jorropo
ab8a2c5e44 cmd/compile: generic constant folding: Floor Ceil Trunc RoundToEven
Change-Id: I553a6d0bd3ae45e5bf62191411e71102b3f44cd8
Reviewed-on: https://go-review.googlesource.com/c/go/+/411215
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2022-08-23 22:44:18 +00:00
Damien Neil
0765da5884 net/url: consistently remove ../ elements in JoinPath
JoinPath would fail to remove relative elements from the start of
the path when the first path element is "".

In addition, JoinPath would return the original path unmodified
when provided with no elements to join, violating the documented
behavior of always cleaning the resulting path.

Correct both these cases.

    JoinPath("http://go.dev", "../go")
    // before: http://go.dev/../go
    // after:  http://go.dev/go

    JoinPath("http://go.dev/../go")
    // before: http://go.dev/../go
    // after:  http://go.dev/go

Fixes #54385.

Change-Id: I6d22cd160d097c50703dd96e4f453c6c118fd5d9
Reviewed-on: https://go-review.googlesource.com/c/go/+/423514
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-08-23 22:01:05 +00:00
Keith Randall
60ad3c48f5 cmd/compile: move SSA rotate instruction detection to arch-independent rules
Detect rotate instructions while still in architecture-independent form.
It's easier to do here, and we don't need to repeat it in each
architecture file.

Change-Id: I9396954b3f3b3bfb96c160d064a02002309935bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/421195
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Eric Fang <eric.fang@arm.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: Ruinan Sun <Ruinan.Sun@arm.com>
Run-TryBot: Keith Randall <khr@golang.org>
2022-08-23 21:24:14 +00:00
Jorropo
a36a0c440e cmd/compile: fix error message formatting in decomposeBuiltInPhi
Change-Id: Ib2b2eb6bebb59134f671a79739ee1acaf32ed443
Reviewed-on: https://go-review.googlesource.com/c/go/+/411217
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
2022-08-23 21:22:15 +00:00
Daniel Martí
790d60537e all: append(bytes, str...) works out of the box
From the append docs in the builtin package:

	As a special case, it is legal to append a string to a byte slice, like this:

	slice = append([]byte("hello "), "world"...)

Change-Id: Ib14039a7476873b12a3aefccd8863e8d628b9249
Reviewed-on: https://go-review.googlesource.com/c/go/+/425102
Reviewed-by: hopehook <hopehook@qq.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
2022-08-23 21:04:06 +00:00
Miguel Ángel Jimeno
44d057d581 net/http/httputil: do not duplicate 'Connection: close' headers
Fixes #54616.

Change-Id: I46f41bbccff7b49f26f60c1edf65acfd1701aed5
Reviewed-on: https://go-review.googlesource.com/c/go/+/425155
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
2022-08-23 20:40:54 +00:00
qmuntal
d88560afd3 syscall: rely on utf16.AppendRune
Using utf16.AppendRune instead of utf16.Encode safe a bunch
of allocations across the board, as many higher level functions
use it to call Windows syscalls, for example to `os` package:

name                old alloc/op   new alloc/op   delta
Readdirname-12        15.6kB ± 0%    15.6kB ± 0%   +0.26%  (p=0.008 n=5+5)
Readdir-12            29.4kB ± 0%    29.4kB ± 0%   +0.14%  (p=0.008 n=5+5)
ReadDir-12            29.4kB ± 0%    29.4kB ± 0%   +0.14%  (p=0.016 n=4+5)
StatDot-12              552B ± 0%      560B ± 0%   +1.45%  (p=0.008 n=5+5)
StatFile-12             512B ± 0%      336B ± 0%  -34.38%  (p=0.008 n=5+5)
StatDir-12              432B ± 0%      288B ± 0%  -33.33%  (p=0.008 n=5+5)
LstatDot-12             552B ± 0%      560B ± 0%   +1.45%  (p=0.008 n=5+5)
LstatFile-12            512B ± 0%      336B ± 0%  -34.38%  (p=0.008 n=5+5)
LstatDir-12             432B ± 0%      288B ± 0%  -33.33%  (p=0.008 n=5+5)
StatFile-12             4.00 ± 0%      2.00 ± 0%  -50.00%  (p=0.008 n=5+5)
StatDir-12              4.00 ± 0%      2.00 ± 0%  -50.00%  (p=0.008 n=5+5)
LstatFile-12            4.00 ± 0%      2.00 ± 0%  -50.00%  (p=0.008 n=5+5)
LstatDir-12             4.00 ± 0%      2.00 ± 0%  -50.00%  (p=0.008 n=5+5)

Updates #51786

Change-Id: I0a088cf1a96e9c304da9311bb3895b70443c1637
Reviewed-on: https://go-review.googlesource.com/c/go/+/425054
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-08-23 20:36:49 +00:00
Ian Lance Taylor
fc0d423789 debug/plan9obj: don't crash on EOF before symbol type
No debug/plan9obj test case because the problem can only happen for
invalid data. Let the fuzzer find cases like this.

For #47653
Fixes #54585

Change-Id: I8d3e15725b9bc09dd0e6f2750769987021f5e982
Reviewed-on: https://go-review.googlesource.com/c/go/+/425115
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
2022-08-23 20:32:50 +00:00
Ian Lance Taylor
b72521ee50 debug/macho: don't use narch for seenArches map size
If narch is very large we would allocate a lot of memory for seenArches.
In practice we aren't going to see many different architectures so
don't bother to specify a size for the seenArches map.

No debug/macho test case because the problem can only happen for
invalid data. Let the fuzzer find cases like this.

For #47653
For #52523

Change-Id: I5a3b0e3aa6172ddffd6f44d9ae513c39a00d8764
Reviewed-on: https://go-review.googlesource.com/c/go/+/425114
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
2022-08-23 20:31:52 +00:00
Joe Tsai
cf26fbb1f6 strconv: optimize Parse for []byte arguments
When one has a []byte on hand, but desires to call the Parse functions,
the conversion from []byte to string would allocate.

    var b []byte = ...
    v, err := strconv.ParseXXX(string(b), ...)

This changes it such that the input string never escapes from
any of the Parse functions. Together with the compiler optimization
where the compiler stack allocates any string smaller than 32B
this makes most valid inputs for strconv.ParseXXX(string(b), ...)
not require an allocation for the input string.
For example, the longest int64 or uint64 encoded in decimal is 20B.
Also, the longest decimal formatting of a float64 in appendix B
of RFC 8785 is 25B.

Previously, this was not possible since the input leaked to the error,
which causes the prover to give up and instead heap copy the []byte.
We fix this by copying the input string in the error case.
The advantage of this change is that you can now call strconv.ParseXXX
with a []byte without allocations (most times) in the non-error case.
The detriment is that the error-case now has an extra allocation.
We should optimize for the non-error path, rather than the error path.

The effects of this change is transitively seen through packages
that must use strconv.ParseXXX on a []byte such as "encoding/json":

    name              old time/op    new time/op    delta
    UnmarshalFloat64  186ns          157ns          -15.89%  (p=0.000 n=10+10)

    name              old alloc/op   new alloc/op   delta
    UnmarshalFloat64  148B           144B            -2.70%  (p=0.000 n=10+10)

    name              old allocs/op  new allocs/op  delta
    UnmarshalFloat64  2.00           1.00           -50.00%  (p=0.000 n=10+10)

In order for "encoding/json" to benefit, there needs to be a
small change made to how "encoding/json" calls strconv.ParseXXX.
That will be a future change.

Credit goes to Jeff Wendling for a similar patch.

Fixes #42429

Change-Id: I512d6927f965f82e95bd7ec14a28a587f23b7203
Reviewed-on: https://go-review.googlesource.com/c/go/+/345488
Reviewed-by: Martin Möhrmann <martin@golang.org>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-08-23 20:29:22 +00:00
Joe Tsai
70de482d17 bytes: rely on utf8.AppendRune
This is both simpler and more performant.

WriteRune                                 23.9µs ± 1%   22.8µs ± 8%   -4.43%  (p=0.006 n=8+10)
ToUpper/longɐstringɐwithɐnonasciiⱯchars    573ns ± 4%    474ns ± 6%  -17.27%  (p=0.000 n=10+10)
ToUpper/ɐɐɐɐɐ                              236ns ± 6%    202ns ± 5%  -14.12%  (p=0.000 n=10+10)
ToUpper/a\u0080\U0010ffff                 98.8ns ± 6%   91.2ns ± 3%   -7.67%  (p=0.000 n=10+10)
ToLower/LONGⱯSTRINGⱯWITHⱯNONASCIIⱯCHARS    511ns ± 3%    409ns ± 4%  -20.02%  (p=0.000 n=10+10)
ToLower/ⱭⱭⱭⱭⱭ                              178ns ± 4%    173ns ± 2%   -2.76%  (p=0.005 n=10+10)
ToLower/A\u0080\U0010ffff                  100ns ± 3%     91ns ± 2%   -8.55%  (p=0.000 n=10+10)

Change-Id: I968ef194da2c115cbdcac2d3575c34c65e6a8a56
Reviewed-on: https://go-review.googlesource.com/c/go/+/412337
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
2022-08-23 20:26:47 +00:00
Andy Pan
556c978400 runtime: name nil semaphore of pollDesc
Use explicit name pdNil for nil semaphore of a pollDesc to make it self-explanatory like pdReady and pdWait.

Change-Id: Ibfb246e14419d366edadbccac4d3717f0c135cb0
Reviewed-on: https://go-review.googlesource.com/c/go/+/424923
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-08-23 20:24:52 +00:00
Joe Tsai
723a27994d strings: rely on utf8.AppendRune
This is both simpler and more performant.

Change-Id: I66ef8e49c059a722932392ee3ecfb951d9b8e121
Reviewed-on: https://go-review.googlesource.com/c/go/+/412339
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-08-23 20:24:43 +00:00
Andy Pan
e7f2e5697a encoding/json: give it a chance to put encodeState back in pool when error occurs
name                       old time/op    new time/op    delta
CodeEncoderError-10           688µs ± 8%     496µs ±15%   -27.92%  (p=0.000 n=10+9)
CodeMarshalError-10           747µs ± 6%     546µs ± 4%   -26.86%  (p=0.000 n=10+10)
MarshalBytesError/32-10       284µs ± 2%     273µs ± 1%    -3.84%  (p=0.000 n=10+10)
MarshalBytesError/256-10      281µs ± 2%     278µs ± 4%      ~     (p=0.053 n=9+10)
MarshalBytesError/4096-10     290µs ± 1%     279µs ± 3%    -3.52%  (p=0.000 n=10+10)

name                       old speed      new speed      delta
CodeEncoderError-10        2.83GB/s ± 8%  3.84GB/s ±20%   +36.03%  (p=0.000 n=10+10)
CodeMarshalError-10        2.60GB/s ± 5%  3.56GB/s ± 4%   +36.61%  (p=0.000 n=10+10)

name                       old alloc/op   new alloc/op   delta
CodeEncoderError-10          4.05MB ± 1%    0.00MB ± 1%  -100.00%  (p=0.000 n=10+9)
CodeMarshalError-10          6.05MB ± 0%    1.99MB ± 1%   -67.13%  (p=0.000 n=10+10)
MarshalBytesError/32-10      66.0kB ± 0%     0.2kB ± 0%   -99.67%  (p=0.000 n=9+8)
MarshalBytesError/256-10     50.1kB ± 0%     0.9kB ± 0%   -98.23%  (p=0.000 n=9+9)
MarshalBytesError/4096-10    87.4kB ± 0%     7.5kB ± 0%   -91.47%  (p=0.000 n=8+10)

name                       old allocs/op  new allocs/op  delta
CodeEncoderError-10            25.0 ± 0%       4.0 ± 0%   -84.00%  (p=0.000 n=9+10)
CodeMarshalError-10            27.0 ± 0%       6.0 ± 0%   -77.78%  (p=0.000 n=10+10)
MarshalBytesError/32-10        18.0 ± 0%       5.0 ± 0%   -72.22%  (p=0.000 n=10+10)
MarshalBytesError/256-10       17.0 ± 0%       6.0 ± 0%   -64.71%  (p=0.000 n=10+10)
MarshalBytesError/4096-10      16.0 ± 0%       6.0 ± 0%   -62.50%  (p=0.000 n=10+10)

Change-Id: I48070bb05f55707251c694e40d2570403bbf61f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/423694
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-23 20:23:19 +00:00
Keith Randall
a6e6b11e3a runtime: initialize pointer bits of noscan spans
Some code paths in the runtime (cgo, heapdump) request heap bits
without first checking that the span is !noscan. Instead of trying
to find and work around all those cases, just set the pointer bits
of noscan spans correctly. It's somewhat safer than ensuring we
caught all the possible cases.

Fixes #54557
Fixes #54558

Change-Id: Ibd476e6cdea77c962e4d15aad26f29df66fd94e8
Reviewed-on: https://go-review.googlesource.com/c/go/+/425194
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2022-08-23 20:12:59 +00:00
Cuong Manh Le
e1114fdf88 runtime: convert ticksType.val to atomic type
Updates #53821

Change-Id: Ia0c58d7e7e11a1b52bbb7c19ebbb131e3eea5314
Reviewed-on: https://go-review.googlesource.com/c/go/+/424926
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
2022-08-23 20:00:03 +00:00
Keith Randall
332a5981d0 cmd/compile: handle partially overlapping assignments
Normally, when moving Go values of type T from one location to another,
we don't need to worry about partial overlaps. The two Ts must either be
in disjoint (nonoverlapping) memory or in exactly the same location.
There are 2 cases where this isn't true:
 1) Using unsafe you can arrange partial overlaps.
 2) Since Go 1.17, you can use a cast from a slice to a ptr-to-array.
    https://go.dev/ref/spec#Conversions_from_slice_to_array_pointer
    This feature can be used to construct partial overlaps of array types.
      var a [3]int
      p := (*[2]int)(a[:])
      q := (*[2]int)(a[1:])
      *p = *q
We don't care about solving 1. Or at least, we haven't historically
and no one has complained.
For 2, we need to ensure that if there might be partial overlap,
then we can't use OpMove; we must use memmove instead.
(memmove handles partial overlap by copying in the correct
direction. OpMove does not.)

Note that we have to be careful here not to introduce a call when
we're marshaling arguments to a call or unmarshaling results from a call.

Fixes #54467

Change-Id: I1ca6aba8041576849c1d85f1fa33ae61b80a373d
Reviewed-on: https://go-review.googlesource.com/c/go/+/425076
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
2022-08-23 19:56:32 +00:00
Matthew Dempsky
503de697cb Revert "cmd/compile: restore test/nested.go test cases"
This reverts CL 424854.

Reason for revert: broke misc/cgo/stdio.TestTestRun on several builders.

Will re-land after CL 421879 is submitted.

Change-Id: I2548c70d33d7c178cc71c1d491cd81c22660348f
Reviewed-on: https://go-review.googlesource.com/c/go/+/425214
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
2022-08-23 19:37:34 +00:00
Paul E. Murphy
7d1cab12c7 runtime: fix ppc64 startup on newer linux kernels
R0 needs to be cleared at startup as it may not always be cleared
by the kernel on newer kernels.

Fixes #54547

Change-Id: Id7055699aaa8d8b193b7e3e784f075ce29ac3f1d
Reviewed-on: https://go-review.googlesource.com/c/go/+/424927
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
2022-08-23 18:59:24 +00:00
Daniel Martí
ef22285f31 all: use go/parser.SkipObjectResolution in more places
None of cgo, "go test", nor srcimporter make use of go/ast's object
resolution via go/ast.Object. As such, we can skip that work during
parse time, which should save some CPU time.

We don't have any benchmark numbers, as none of the three packages have
any usable benchmarks, but we measured gofmt to be about 5% faster
thanks to this tweak in https://go.dev/cl/401454.
These three packages are quite different to gofmt, but one can expect
similar speed-ups in the 1-5% range.

Two notable exceptions, which do make use of go/ast.Object, are cmd/fix
and cmd/doc - we do not modify those here.

See #46485.

Change-Id: Ie3e65600d4790641c4e4d6f1c379be477fa02cee
Reviewed-on: https://go-review.googlesource.com/c/go/+/401455
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-23 18:54:32 +00:00
Axel Wagner
7f632f76db encoding/xml: add (*Encoder).Close
Flush can not check for unclosed elements, as more data might be encoded
after Flush is called. Close implicitly calls Flush and also checks that
all opened elements are closed as well.

Fixes #53346

Change-Id: I889b9f5ae54e5dfabb9e6948d96c5ed7bc1110f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/424777
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
2022-08-23 18:24:30 +00:00
Bryan C. Mills
be9e2440a7 cmd/go/internal/modload: remove ImportMap and PackageDir
These two functions together duplicated much of the functionality of
modload.Lookup. Use that instead in modcmd.vendorPkg, and reduce the
modload surface area.

Updates #42504
Updates #40775
For #26904

Change-Id: Ib8aaac495d090178dd56971aef9e5aa44ffa818b
Reviewed-on: https://go-review.googlesource.com/c/go/+/332571
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
2022-08-23 18:22:17 +00:00
Jakub Ciolek
de561dc766 cmd/compile: mark booleans as registerizable
Boolean values fit in registers, mark them accordingly. Improves codegen a bit.

compilecmp for darwin/amd64:

compress/gzip
compress/gzip.(*Reader).Reset 1017 -> 985  (-3.15%)

net
net.newRequest 1002 -> 970  (-3.19%)

crypto/tls
crypto/tls.(*sessionState).unmarshal 1054 -> 968  (-8.16%)

cmd/compile/internal/syntax
cmd/compile/internal/syntax.Fprint 518 -> 453  (-12.55%)

cmd/vendor/github.com/ianlancetaylor/demangle
cmd/vendor/github.com/ianlancetaylor/demangle.ASTToString 389 -> 325  (-16.45%)

cmd/go/internal/load
cmd/go/internal/load.PackagesAndErrors 3453 -> 3381  (-2.09%)

cmd/compile/internal/ssa
cmd/compile/internal/ssa.registerizable 249 -> 255  (+2.41%)

cmd/compile/internal/ssagen
cmd/compile/internal/ssagen.buildssa 9388 -> 9356  (-0.34%)

file                                            before   after    Δ       %
compress/gzip.s                                 8247     8215     -32     -0.388%
net.s                                           266667   266635   -32     -0.012%
crypto/tls.s                                    290324   290238   -86     -0.030%
cmd/compile/internal/syntax.s                   156422   156357   -65     -0.042%
cmd/vendor/github.com/ianlancetaylor/demangle.s 268313   268249   -64     -0.024%
cmd/go/internal/load.s                          122946   122874   -72     -0.059%
cmd/compile/internal/ssa.s                      3551201  3551207  +6      +0.000%
cmd/compile/internal/ssagen.s                   362299   362267   -32     -0.009%
total                                           19725872 19725495 -377    -0.002%

Change-Id: I4cd40b54d8b2da6d1f946e51f16689315a369dca
Reviewed-on: https://go-review.googlesource.com/c/go/+/408474
Run-TryBot: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2022-08-23 18:16:49 +00:00
Matthew Dempsky
6985ab27df cmd/compile: fix unified IR's pointer-shaping
In CL 424734, I implemented pointer shaping for unified IR. Evidently
though, we didn't have any test cases that check that uses of
pointer-shaped expressions were handled correctly.

In the reported test case, the struct field "children items[*node[T]]"
gets shaped to "children items[go.shape.*uint8]" (underlying type
"[]go.shape.*uint8"); and so the expression "n.children[i]" has type
"go.shape.*uint8" and the ".items" field selection expression fails.

The fix implemented in this CL is that any expression of derived type
now gets an explicit "reshape" operation applied to it, to ensure it
has the appropriate type for its context. E.g., the "n.children[i]"
OINDEX expression above gets "reshaped" from "go.shape.*uint8" to
"*node[go.shape.int]", allowing the field selection to succeed.

This CL also adds a "-d=reshape" compiler debugging flag, because I
anticipate debugging reshaping operations will be something to come up
again in the future.

Fixes #54535.

Change-Id: Id847bd8f51300d2491d679505ee4d2e974ca972a
Reviewed-on: https://go-review.googlesource.com/c/go/+/424936
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: hopehook <hopehook@qq.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-23 18:14:10 +00:00
Matthew Dempsky
0a6e1fa986 cmd/compile: fix "expression has untyped type" ICE in generic code
During walk, we sometimes desugar OEQ nodes into multiple "untyped
bool" expressions, and then use typecheck.Conv to convert back to the
original OEQ node's type.

However, typecheck.Conv had a short-circuit path that if the type is
already identical to the target type according to types.Identical,
then we skipped the conversion. This short-circuit is normally fine;
but with generic code and shape types, it considers "untyped bool" and
"go.shape.bool" to be identical types. And we could end up leaving an
expression of "untyped bool", which then fails an internal consistency
check later.

The simple fix is to change Conv to use types.IdenticalStrict, so that
we ensure "untyped bool" gets converted to "go.shape.bool". And for
good measure, make the same change to ConvNop.

This issue was discovered and reported against unified IR, but the
issue was latent within the non-unified frontend too.

Fixes #54537.

Change-Id: I7559a346b063349b35749e8a2da704be18e51654
Reviewed-on: https://go-review.googlesource.com/c/go/+/424937
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
2022-08-23 18:13:59 +00:00