1
0
mirror of https://github.com/golang/go synced 2024-11-17 01:24:50 -07:00
Commit Graph

50684 Commits

Author SHA1 Message Date
Robert Griesemer
a17a21c190 cmd/compile/internal/types2: deduplicate signatures with the context
This CL is a mostly clean port of CL 362801 from go/types to types2.
It deviates from go/types in some of the testing code because types2
already had made some of the changes.

It also re-introduces some empty lines that got lost in earlier CLs.

Change-Id: I0bebd68f0880fac61631a5d0c323a9f8ce853ac6
Reviewed-on: https://go-review.googlesource.com/c/go/+/364335
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-17 04:31:35 +00:00
Robert Griesemer
fceca2c0f1 cmd/compile/internal/types2: add a test for argument error unwrapping
This CL is a clean port of CL 351338 from go/types to types2.

Change-Id: I7fd0e5a447bf51cb359e71731c2f9b95e3960da6
Reviewed-on: https://go-review.googlesource.com/c/go/+/364536
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-17 04:31:29 +00:00
Robert Griesemer
f384c707ac cmd/compile/internal/types2: tweaks to ArgumentError to be more idiomatic
This CL is a clean port of CL 351335 from go/types to types2.

Updates #47916

Change-Id: Idc377fb71d480a51d5e93a348f3a880346011974
Reviewed-on: https://go-review.googlesource.com/c/go/+/364535
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-17 04:31:22 +00:00
Than McIntosh
3d7cb23e3d cmd/compile: emit definition of 'any' when compiling runtime
Include the predefined type 'any' in the list of other important
predefined types that are emitted when compiling the runtime package
(uintptr, string, etc).

Fixes #49619.

Change-Id: I4a851ba2f302fbc3a425e65daa325c6bf83659da
Reviewed-on: https://go-review.googlesource.com/c/go/+/364377
Trust: Than McIntosh <thanm@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-11-17 01:56:19 +00:00
Josh Bleecher Snyder
a2b8231b91 runtime: remove defer test log spam
This appears to be leftover debugging
from CL 356011.

Change-Id: Ieeda0b7e297e0cb943827b28644135e6cad12e3c
Reviewed-on: https://go-review.googlesource.com/c/go/+/364555
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-11-17 00:02:01 +00:00
Keith Randall
01b6cf09fc runtime: check GOAMD64 compatibility after setting up TLS
We need TLS set up to be able to print an error without crashing.

Fixes #49586
Update #45453

Change-Id: I97f0efcd716a8dca614e82ab73f2d855b7277599
Reviewed-on: https://go-review.googlesource.com/c/go/+/364174
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <martin@golang.org>
Trust: Martin Möhrmann <martin@golang.org>
Trust: Keith Randall <khr@golang.org>
2021-11-16 23:52:13 +00:00
jiahua wang
5e59d6ebd1 sort: improve sort documentation
Fixes #48527

Change-Id: Ib5df0819cbcd5c2e4f03bda841871d237af96b19
Reviewed-on: https://go-review.googlesource.com/c/go/+/351336
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-11-16 23:13:41 +00:00
Michael Pratt
f659183972 os/exec: avoid NewFile on unknown FDs
exec_test.go's init function uses os.NewFile(fd) + f.Stat as a portable
mechanism to determine if an FD is in use.

Unfortunately, the current use is racy: if an unused FD becomes used
between NewFile and f.Close, then we will unintentionally close an FD we
do not use.

We cannot simply drop Close, as the finalizer will close the FD. We
could hold all of the os.Files in a global for the lifetime of the
process, but the need for such a hack is indicative of the larger
problem: we should not create an os.File for an FD that we do not own.

Instead, the new fdtest.Exists provides a helper that performs the
equivalent of fstat(2) on each OS to determine if the FD is valid,
without using os.File.

We also reuse this helper on a variety of other tests that look at open
FDs.

Fixes #49533

Change-Id: I36e2bdb15f271ab01e55c18db6564271995a15af
Reviewed-on: https://go-review.googlesource.com/c/go/+/364035
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-11-16 19:41:37 +00:00
Alessandro Arzilli
6c36c332fe debug/pe,debug/macho: add support for DWARF5 sections
Adds the same logic used in debug/elf to load DWARF5 sections.

Fixes #49590

Change-Id: Iee05b9927a6f521842b330eab8942ade3fc2bd86
Reviewed-on: https://go-review.googlesource.com/c/go/+/363895
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Than McIntosh <thanm@google.com>
2021-11-16 18:36:59 +00:00
Michael Matloob
40effca7a1 cmd: pull in golang.org/x/mod@3a5865c
This change updates the cmd module's requirement on x/mod and vendors in
the changes.

This pulls in the following changes into our vendored copy of x/mod:
golang.org/cl/351319: module: accept trailing slash in MatchPrefixPattern
golang.org/cl/353749: semver: remove unused err field
golang.org/cl/355630: x/mod: update requirement on x/crypto
golang.org/cl/359412: modfile: rename directory directive to use

Changes have been made in cmd/go renaming all uses of directory to use
and fixing references to functions in x/mod/modfile to account for the
changes in the last of thse CLs.

For #45713

Change-Id: I9121d08f6e6b11838bca50e6cbd756baeeae867b
Reviewed-on: https://go-review.googlesource.com/c/go/+/364114
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-11-16 17:32:23 +00:00
Michael Pratt
29ec902efc runtime: get tracking time only when needed
casgstatus currently calls nanotime on every casgstatus when tracking,
even though the time is only used in some cases. For goroutines making
lots of transitions that aren't covered here, this can add a small
overhead. Switch to calling nanotime only when necessary.

Change-Id: I2617869332e8289ef33dd674d786e44dea09aaba
Reviewed-on: https://go-review.googlesource.com/c/go/+/364375
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-11-16 17:13:33 +00:00
Robert Findley
79d0013f53 go/types, types2: improve error messages referencing any
Because any is an a alias, it is naively formatted as interface{} in
error messages. This is a source of verbosity and potential confusion.

We can improve the situation by looking for pointer equality with the
any type. To avoid churn in the importers, do this all at once across
the compiler, go/types, and go/internal/gcimporter. CL 364194 makes the
corresponding change in x/tools/go/internal/gcimporter, allowing the
x/tools trybots to pass.

Fixes #49583

Change-Id: Ib59570937601308483f6273364cc59338f9b8b3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/363974
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-11-16 15:59:43 +00:00
Cuong Manh Le
7f4a946fa2 cmd/compile: prevent irgen crashing for empty local declaration stmt
Updates #47631
Fixes #49611

Change-Id: Ib4a4466038e0d4a9aa9380d7909f29f7d15c6c69
Reviewed-on: https://go-review.googlesource.com/c/go/+/364314
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-11-16 15:38:59 +00:00
Robert Findley
7c50ef6c8c go/types: remove asTypeParam and simplify some code
This is a port of CL 363438 from types2 to go/types.

Change-Id: I87c76d31b398b9ce406f96b0030ee458619b3dbe
Reviewed-on: https://go-review.googlesource.com/c/go/+/364235
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-11-16 15:35:52 +00:00
Robert Findley
f041c7e302 go/types: remove structuralString in favor of inlined code
This is a clean port of CL 363154 from types2 to go/types.

Change-Id: I26c18767041db096390e84ba9200ec69b66778d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/364234
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-11-16 15:16:54 +00:00
Robert Findley
289c930750 go/types: slightly relax notion of structural type
This is a port of CL 363075 from types2 to go/types, adjusted for the
different error reporting API, and to adjust positions of error messages
in tests.

Change-Id: Ic6bfedf1152eff94bad20725b56e6ba804b2e3e8
Reviewed-on: https://go-review.googlesource.com/c/go/+/363991
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-11-16 15:16:49 +00:00
Robert Findley
46e98d489f go/types: refer to structural rather than single underlying type in errors
This is a port of CL 362997 from types2 to go/types. Some error
positions were adjusted in tests.

Change-Id: I6a932aee1a8d9bcbf4cd8c16a95bbb41b5c7e13f
Reviewed-on: https://go-review.googlesource.com/c/go/+/363990
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-11-16 15:16:41 +00:00
Robert Findley
50dac3b410 go/types: move some functions into different files (cleanup)
This is a clean port of CL 362995 from types2 to go/types.

Change-Id: Iefc37b28178795ea944e0bc0ff91982251de2944
Reviewed-on: https://go-review.googlesource.com/c/go/+/363989
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-11-16 14:33:48 +00:00
Robert Findley
67c1556815 go/types: rename structure to structuralType
This is a clean port of CL 362994 from types2 to go/types.

Change-Id: I51b38c35ec3306274ef0355516e2d5557e7d8b46
Reviewed-on: https://go-review.googlesource.com/c/go/+/363988
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-11-16 14:33:39 +00:00
Robert Findley
bddb79f0fa go/types: use type variables consistently in Checker.conversion
This is a clean port of CL 362895 from types2 to go/types.

Change-Id: Icd0631127c51aec80ce9450df2be71bf4b96b2df
Reviewed-on: https://go-review.googlesource.com/c/go/+/363987
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-11-16 14:02:36 +00:00
Robert Findley
9efb6493f4 all: update vendored golang.org/x/tools
Update the vendored x/tools to pick up the fix for #49597, using the
following commands:

  go get -d golang.org/x/tools@4adea5033c5c6f39a900d4b963c4b496448b1655
  go mod tidy
  go mod vendor

Fixes #49597

Change-Id: Ib1bc43aacbdc707b605194012134f048a336e176
Reviewed-on: https://go-review.googlesource.com/c/go/+/363986
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-11-16 13:48:46 +00:00
Alberto Donizetti
6e481c0b36 cmd/go: don't try to print build info of non-Go binaries
On a non-nil err, buildinfo.ReadFile will always return a nil
*Buildinfo. In scanFile, we need to return early if that happens.

Fixes #49181

Change-Id: I354348d206ab084804937c6f922eadb61435e7b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/359154
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-11-16 08:58:05 +00:00
Robert Griesemer
6b3f4d388f cmd/compile/internal/types2: re-use type hashing logic in Context.typeHash
This CL is clean port of CL 362800 from go/types to types2.

Change-Id: I66443b5a82b3a9c2f608a0fe012fbb099db996f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/364155
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-16 07:47:15 +00:00
Robert Griesemer
313cae3861 cmd/compile/internal/types2: refactor the Context type map to accept arbitrary types
This CL is a clean port of CL 362799 from go/types to types2.

Change-Id: Id670aa4b1ca0b568a79bb6e4855747807dcf00f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/364154
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-16 07:47:08 +00:00
Robert Griesemer
a52e4b9c7e cmd/compile/internal/types2: use Identical to verify type identity in the Context map
This is a clean port of CL 362798 from go/types to types2,
with an additional comment adjustment in types2 and go/types.

Change-Id: Ifa3d11f512f794f8ae2b6aca50b625a4a44672de
Reviewed-on: https://go-review.googlesource.com/c/go/+/364135
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-16 06:36:08 +00:00
Keith Randall
febbef593e doc: mention generics in release notes
Also mention local types restriction.

We probably want to say more at some point, this is just a
placeholder to start.

Update #47631

Change-Id: I828e451e1e8504d21cb55c7132e9cb330b160a54
Reviewed-on: https://go-review.googlesource.com/c/go/+/364134
Trust: Keith Randall <khr@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-11-16 06:31:54 +00:00
Ian Lance Taylor
fdd67930a0 sync: in TryLock try to acquire mutex even if state is not 0
For #45435

Change-Id: I728accd9a53c1826243f52aa04dc2a0a1dfdaadf
Reviewed-on: https://go-review.googlesource.com/c/go/+/363672
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2021-11-16 05:58:03 +00:00
jiahua wang
865689571d doc/go1.18: add AppendRune doc
For #47694

Change-Id: I39594c273aeb038702457587ee1c46e4b3920bb6
Reviewed-on: https://go-review.googlesource.com/c/go/+/363359
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Trust: Jeremy Faller <jeremy@golang.org>
2021-11-16 05:36:07 +00:00
Alessandro Arzilli
9e13a8876f debug/dwarf: better error message when reading absent debug_line_str
When a DW_FORM_line_strp is used without a debug_line_str section a
good error message (about the missing section) is generated but
immediately overwritten by the underflow error generated by trying to
read the non-existent section.

Updates #49590

Change-Id: I1c431392123a86c78c95ef1f185ebd6f17f2476a
Reviewed-on: https://go-review.googlesource.com/c/go/+/363894
Run-TryBot: Alessandro Arzilli <alessandro.arzilli@gmail.com>
Trust: David Chase <drchase@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2021-11-15 23:55:09 +00:00
Robert Griesemer
d15610128e cmd/compile/internal/types2: add test for imported constraints pre-1.18
But exclude the test when running unified build for now
(the unified builder's importers are not yet updated to
handle extended interfaces).
Also, fix respective error position.

Fixes #47967.

Change-Id: I4e3d829b5c12001c024b9eefcc27f97b10c1d1e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/363834
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-11-15 23:01:05 +00:00
Robert Griesemer
95e85e3108 cmd/compile/internal/types2: use "implements" rather than "satisfies" in error messages
Type constraint satisfaction is interface implementation.

Adjusted a few error messages.

Change-Id: I4266af78e83131a76b1e3e44c847a21de760ac6e
Reviewed-on: https://go-review.googlesource.com/c/go/+/363839
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-15 21:22:19 +00:00
Robert Griesemer
c8d7c5fe05 cmd/compile/internal/types2: remove unneccesary tests in implements and lookup
Because the underlying type of a type parameter is an interface,
the questions whether *P for a type parameter P has methods or
not is settled: P is also an interface pointers to interfaces
don't have methods.

This allows us to eliminate the now unneccesary test in "implements"
and also allows us to remove a special case for type parameters in
"lookupFieldOrMethod".

Change-Id: I8b218f81584a8e42e75884089a44293365b700df
Reviewed-on: https://go-review.googlesource.com/c/go/+/363838
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-15 21:22:18 +00:00
Robert Griesemer
e08aae2ee4 cmd/compile/internal/types2: implement Checker.implements
Checker.implements implements the complete interface
"implements" predicate. Use it instead of Checker.satisfies.
This is mostly a refactoring of the code but the constraint
types have already been instatiated with the respective type
arguments as needed before calling "implements".
Future CLs will address the various TODOs.

Change-Id: If530cca36643a561282361348f1526157a7182de
Reviewed-on: https://go-review.googlesource.com/c/go/+/363837
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-15 21:22:17 +00:00
Robert Griesemer
fda9261504 cmd/compile/internal/types2: better position for invalid slice indices error
Report the error at the first place (which is to say, latest index)
causing the error.

Change-Id: I31cf0a4d243fc66cfab84b7fec98055f4eb60ddf
Reviewed-on: https://go-review.googlesource.com/c/go/+/363671
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-15 21:22:15 +00:00
Robert Griesemer
42fa03a88c cmd/compile/internal/types2: better position for "3-index slice of string" error
As a result, slightly narrow position tolerance for tests.

Change-Id: I543dc2b7b9a7940b0684067d1961165b2b4812bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/363670
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-15 21:22:14 +00:00
Robert Griesemer
0a54a6826e cmd/compile/internal/types2: move match function to end of file (cleanup)
Change-Id: Ia09f7b1af0e84858fb73ab7e2592c5c3e983dc0e
Reviewed-on: https://go-review.googlesource.com/c/go/+/363669
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-15 21:22:13 +00:00
Robert Griesemer
cfcd71790f cmd/compile/internal/types2: allow slicing for operands with []byte|string type sets
Fixes #49566.

Change-Id: I80ff4ca661f82b0981d51e0997d5988a9b82f508
Reviewed-on: https://go-review.googlesource.com/c/go/+/363662
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-15 21:22:12 +00:00
Robert Griesemer
0a39e4a89d cmd/compile/internal/types2: optimize common case in structuralType
Most of the time we don't have a type parameter. Avoid using a
closure in that case.

While at it, rename argument from typ to t (to match style in
that file), and clarify the doc string.

Change-Id: Ie62821073f60f353526263f8b380bad9f72d842e
Reviewed-on: https://go-review.googlesource.com/c/go/+/363668
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-15 21:22:11 +00:00
Robert Griesemer
184ca3cf99 go/types, types2: copy implicit bit in interface substitution
Change-Id: Idb02449ef1b06d5f47eeb4a4413e56e2cd5d0d96
Reviewed-on: https://go-review.googlesource.com/c/go/+/363836
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-15 21:22:09 +00:00
Keith Randall
560dc9712d cmd/compile: error when using internal type declarations in generic functions
We hope to support this feature one day, but it doesn't work currently.
Issue a nice error message instead of having the compiler crash.

Update #47631

Change-Id: I0359411410acbaf9a5b9dbb988cd933de1bb8438
Reviewed-on: https://go-review.googlesource.com/c/go/+/364054
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-11-15 21:21:51 +00:00
Robert Findley
92655582d0 cmd/compile/internal/types2: add a check for nil reason in assignableTo
A recent change to error message formatting was missing a nil check.

Fixes #49592

Change-Id: Ic1843e0277ba75eec0e8e41fe34b59c323d7ea31
Reviewed-on: https://go-review.googlesource.com/c/go/+/364034
Trust: Robert Findley <rfindley@google.com>
Trust: Dan Scales <danscales@google.com>
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-11-15 19:24:28 +00:00
Robert Findley
b6342a02ad go/types: return an error message from Checker.genericType
The bare error message "%s is not a generic type" is probably never
sufficient, so change the signature of genericType to instead return an
message that may be formatted as additional context in errors.

Along the way, refactor instantiatedType to have access to the entire
index expression.

Fixes #48827

Change-Id: I0c455c1ce46ac3f1ef2990c997da19e5fc6c4eae
Reviewed-on: https://go-review.googlesource.com/c/go/+/363994
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-11-15 18:43:13 +00:00
Robert Findley
0e65410038 go/types: assign error codes to new errors for Go 1.18
During development, we used placeholder _Todo error codes for new
errors related to generics. Add real error codes in these places.

As a result, 9 new error codes are added for ~50 call sites.

Change-Id: Ib57b4cd9f0a2e160971a3aeea18f9fe26fc0f835
Reviewed-on: https://go-review.googlesource.com/c/go/+/363874
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-11-15 18:43:07 +00:00
Dan Scales
1dc9af5cdc cmd/compile: fix position info for implicit nodes due to generics
The main fix is that we should call ir.SetPos() at the beginning of
(*subster).node.edit function, since that is analogous to the
ir.SetPos() at the beginning of typecheck.typecheck(). It ensures that
transform functions can use base.Pos() with appropriate results, just
like their corresponding tc*() functions do.

A small fix is to make sure that the new nodes creates for dictionary
references have the correct position based on the location of the
function call.

Another small fix is to the use of base.Pos when creating a new selector
expression (including implicit XDOTs) for a method expression in
buildClosure().

Also, I converted the final use of base.Pos in stencil.go to src.NoXPos,
since the nodes created by AddImplicitDots will be checked for their
type, but won't actually be used.

I also needed to add an ir.SetPos() at the beginning of transformCall(),
since transformCall() is called in the modify and dict passes, when we
base.Pos is not being set for each node.

This change fixes all the line numbering problems printed out from
Alessandro's program, except for auto-generated functions (which I think
are fine).

Fixes #49523

Change-Id: I9836a497b7beba25ecafdde653a6c2036a3020d3
Reviewed-on: https://go-review.googlesource.com/c/go/+/363835
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-11-15 18:02:28 +00:00
Michael Anthony Knyszek
f986191325 runtime: fix released bytes accumulation in bg scavenger
Currently "released" is not accumulated bytes released. If the last
attempt to scavenge ends up as 0, then the scavenger will go to sleep
too soon. This is an artifact from the old code where scavenge would
only be called into once.

Change-Id: I85aa2261f1504a6fb5bf086daa029eecb0e09cf4
Reviewed-on: https://go-review.googlesource.com/c/go/+/363416
Trust: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-11-15 17:10:25 +00:00
Cherry Mui
ce4a275595 cmd/compile, runtime: mark R1 as clobbered for write barrier call
If the call to gcWriteBarrier is via PLT, the PLT stub will
clobber R1. Mark R1 clobbered.

For #49386.

Change-Id: I72df5bb3b8d10381fec5c567b15749aaf7d2ad70
Reviewed-on: https://go-review.googlesource.com/c/go/+/363698
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2021-11-15 15:42:24 +00:00
Keith Randall
5337e53dfa cmd/compile: ensure we replace package placeholder in type names
We want package names exposed by reflect to be things like
main.F[main.foo], not main.F["".foo].

Fixes #49547

Change-Id: I182411a75d56ce1f64fde847e5b9ee74ce44e00b
Reviewed-on: https://go-review.googlesource.com/c/go/+/363656
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-11-14 17:38:42 +00:00
Keith Randall
dfa62c79de doc: document GOAMD64 environment variable
Update #47694

Change-Id: I9c90bd251616cd4d10434bd3b6e6c30c5c819e24
Reviewed-on: https://go-review.googlesource.com/c/go/+/363661
Trust: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-11-14 16:54:11 +00:00
Robert Griesemer
c2397905e0 cmd/compile/internal/types2: simplify under() and fix a crash
The simplified version of under exposed a bug (by crashing):
When a pointer base is used before the pointer is fully set
up, the base is nil. Set the pointer base to Typ[Invalid]
when creating the pointer, and add an extra safety check
into deref. Reviewed all code that creates pointers.

The same error cannot happen with other types because
accessing parts of another type results in an expression
that is not a type, and thus these kids of cycles cannot
happen.

Change-Id: I8332a281a534c094cfbb3623a636960865813ff6
Reviewed-on: https://go-review.googlesource.com/c/go/+/363665
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-13 03:33:55 +00:00
Michael Matloob
c54605266b cmd/go: remove remaining uses of TODOWorkspaces
Most of them are fixed, but some of them have been rewritten to refer
to specific issues.

For #45713

Change-Id: Id24d9bd47afeac089835f7a26e7025332fb6119c
Reviewed-on: https://go-review.googlesource.com/c/go/+/359794
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-11-13 02:30:25 +00:00