1
0
mirror of https://github.com/golang/go synced 2024-11-23 02:20:03 -07:00
Commit Graph

48511 Commits

Author SHA1 Message Date
Michael Anthony Knyszek
fb84d213a8 [dev.typeparams] reflect: support big endian architectures in callMethod
Currently, callMethod has some ABI translation code that is not agnostic
of endianness. This change rectifies that by adding a method to
internal/abi.RegArgs for safely returning an offset into a register slot
that's endianness-dependent.

No tests for this because it's just best-effort. There's no actual way
to test this because we don't support a register ABI on any big endian
architectures yet.

Change-Id: Ic68d9ee1bfdea0fc2992d467d749e2b083e92de3
Reviewed-on: https://go-review.googlesource.com/c/go/+/328348
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-06-17 21:30:24 +00:00
Michael Anthony Knyszek
9f50d9a0b4 [dev.typeparams] internal/reflectlite: remove unused ptrSize
Change-Id: Ia0da5e5d1e8d20327690cb53c9df067401f3428c
Reviewed-on: https://go-review.googlesource.com/c/go/+/328812
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-17 21:29:40 +00:00
Michael Anthony Knyszek
890a8407a9 [dev.typeparams] internal/reflectlite: use goarch.PtrSize instead of the duplicated ptrSize [generated]
[git-generate]
cd src/internal/reflectlite
gofmt -w -r "ptrSize -> goarch.PtrSize" .
goimports -w *.go

Change-Id: I6a55f2aa035ed863785856ddd4fcc519dec15ac9
Reviewed-on: https://go-review.googlesource.com/c/go/+/328347
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-17 21:29:35 +00:00
Michael Anthony Knyszek
bfd9b63f12 [dev.typeparams] reflect: delete unused ptrSize and PtrSize
Change-Id: I522263eb5112b78639340b83d92e80a13f738bd4
Reviewed-on: https://go-review.googlesource.com/c/go/+/328811
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-17 21:29:28 +00:00
Michael Anthony Knyszek
95c104ee61 [dev.typeparams] reflect: use goarch.PtrSize instead of the duplicated ptrSize [generated]
[git-generate]
cd src/reflect
gofmt -w -r "PtrSize -> goarch.PtrSize" .
gofmt -w -r "ptrSize -> goarch.PtrSize" .
goimports -w *.go

Change-Id: Ib534bb0ecde10d93f45365ab4f8efd620d6d2ef3
Reviewed-on: https://go-review.googlesource.com/c/go/+/328346
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-17 21:29:22 +00:00
Michael Anthony Knyszek
2e600fb8b3 [dev.typeparams] runtime/internal/sys: remove unused Goarch* and Goos* constants
Change-Id: Ibc8381662242c6754f34edce9c0ad81681f55940
Reviewed-on: https://go-review.googlesource.com/c/go/+/329192
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-17 21:29:15 +00:00
Michael Anthony Knyszek
46e1e74a86 [dev.typeparams] runtime: replace Goarch* constants with internal/goarch versions [generated]
[git-generate]
cd src/runtime
gofmt -w -r "sys.Goarch386         -> goarch.Is386" .
gofmt -w -r "sys.GoarchAmd64       -> goarch.IsAmd64" .
gofmt -w -r "sys.GoarchAmd64p32    -> goarch.IsAmd64p32" .
gofmt -w -r "sys.GoarchArm         -> goarch.IsArm" .
gofmt -w -r "sys.GoarchArmbe       -> goarch.IsArmbe" .
gofmt -w -r "sys.GoarchArm64       -> goarch.IsArm64" .
gofmt -w -r "sys.GoarchArm64be     -> goarch.IsArm64be" .
gofmt -w -r "sys.GoarchPpc64       -> goarch.IsPpc64" .
gofmt -w -r "sys.GoarchPpc64le     -> goarch.IsPpc64le" .
gofmt -w -r "sys.GoarchMips        -> goarch.IsMips" .
gofmt -w -r "sys.GoarchMipsle      -> goarch.IsMipsle" .
gofmt -w -r "sys.GoarchMips64      -> goarch.IsMips64" .
gofmt -w -r "sys.GoarchMips64le    -> goarch.IsMips64le" .
gofmt -w -r "sys.GoarchMips64p32   -> goarch.IsMips64p32" .
gofmt -w -r "sys.GoarchMips64p32le -> goarch.IsMips64p32le" .
gofmt -w -r "sys.GoarchPpc         -> goarch.IsPpc" .
gofmt -w -r "sys.GoarchRiscv       -> goarch.IsRiscv" .
gofmt -w -r "sys.GoarchRiscv64     -> goarch.IsRiscv64" .
gofmt -w -r "sys.GoarchS390        -> goarch.IsS390" .
gofmt -w -r "sys.GoarchS390x       -> goarch.IsS390x" .
gofmt -w -r "sys.GoarchSparc       -> goarch.IsSparc" .
gofmt -w -r "sys.GoarchSparc64     -> goarch.IsSparc64" .
gofmt -w -r "sys.GoarchWasm        -> goarch.IsWasm" .
goimports -w *.go

Change-Id: I9d88e1284efabaeb0ee3733cba6286247d078c85
Reviewed-on: https://go-review.googlesource.com/c/go/+/328345
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-17 21:29:09 +00:00
Michael Anthony Knyszek
7b0e9cae66 [dev.typeparams] runtime: replace Goos* constants with internal/goos versions [generated]
[git-generate]
cd src/runtime
gofmt -w -r "sys.GoosAix       -> goos.IsAix" .
gofmt -w -r "sys.GoosAndroid   -> goos.IsAndroid" .
gofmt -w -r "sys.GoosDarwin    -> goos.IsDarwin" .
gofmt -w -r "sys.GoosDragonfly -> goos.IsDragonfly" .
gofmt -w -r "sys.GoosFreebsd   -> goos.IsFreebsd" .
gofmt -w -r "sys.GoosHurd      -> goos.IsHurd" .
gofmt -w -r "sys.GoosIllumos   -> goos.IsIllumos" .
gofmt -w -r "sys.GoosIos       -> goos.IsIos" .
gofmt -w -r "sys.GoosJs        -> goos.IsJs" .
gofmt -w -r "sys.GoosLinux     -> goos.IsLinux" .
gofmt -w -r "sys.GoosNacl      -> goos.IsNacl" .
gofmt -w -r "sys.GoosNetbsd    -> goos.IsNetbsd" .
gofmt -w -r "sys.GoosOpenbsd   -> goos.IsOpenbsd" .
gofmt -w -r "sys.GoosPlan9     -> goos.IsPlan9" .
gofmt -w -r "sys.GoosSolaris   -> goos.IsSolaris" .
gofmt -w -r "sys.GoosWindows   -> goos.IsWindows" .
gofmt -w -r "sys.GoosZos       -> goos.IsZos" .
goimports -w *.go

Change-Id: I42bed2907317ed409812e5a3e2897c88a5d36f24
Reviewed-on: https://go-review.googlesource.com/c/go/+/328344
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-17 21:29:02 +00:00
Michael Anthony Knyszek
81a6a4354b [dev.typeparams] internal/goarch,internal/goos: rename Goos and Goarch constants
Lots of constants in these packages start with Goarch and Goos, which is
redundant. Instead, add the "Is" prefix to make the constant clearer,
and to differentiate from the arch family constants.

Change-Id: Id92c1d3e911296a72949f8c9d649f142e7dc9d17
Reviewed-on: https://go-review.googlesource.com/c/go/+/328343
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-17 21:28:55 +00:00
Michael Anthony Knyszek
33d1b82d16 [dev.typeparams] runtime/internal/sys: replace ArchFamily and constants with goarch
Refactoring with rf

    rf 'ex . {
      import "internal/goarch"
      import "runtime/internal/sys"
      sys.ArchFamily -> goarch.ArchFamily
      sys.AMD64 -> goarch.AMD64
      sys.ARM -> goarch.ARM
      sys.ARM64 -> goarch.ARM64
      sys.I386 -> goarch.I386
      sys.MIPS -> goarch.MIPS
      sys.MIPS64 -> goarch.MIPS64
      sys.PPC64 -> goarch.PPC64
      sys.RISCV64 -> goarch.RISCV64
      sys.S390X -> goarch.S390X
      sys.WASM -> goarch.WASM
    }'

Change-Id: I0cc29ed3fdcf9ff39aa901d8bc92270996f0821c
Reviewed-on: https://go-review.googlesource.com/c/go/+/328341
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-17 20:56:29 +00:00
Michael Anthony Knyszek
85b12a8563 [dev.typeparams] runtime,runtime/internal/sys: remove unused BigEndian
Change-Id: I1209904326b1563e12d9c7d19a12a10c72d1dbcb
Reviewed-on: https://go-review.googlesource.com/c/go/+/329191
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-17 20:42:41 +00:00
Michael Anthony Knyszek
9a93072a07 [dev.typeparams] runtime/internal/sys: replace BigEndian with goarch.BigEndian [generated]
[git-generate]
cd src/runtime/internal/atomic
gofmt -w -r "sys.BigEndian -> goarch.BigEndian" .
goimports -w *.go
cd ../..
gofmt -w -r "sys.BigEndian -> goarch.BigEndian" .
goimports -w *.go

Change-Id: Iad35d2b367d8defb081a77ca837e7a7c805c2b7b
Reviewed-on: https://go-review.googlesource.com/c/go/+/329190
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-17 20:42:35 +00:00
Michael Anthony Knyszek
9c58e399a4 [dev.typeparams] runtime: fix import sort order [generated]
[git-generate]
cd src/runtime
goimports -w *.go

Change-Id: I1387af0f2fd1a213dc2f4c122e83a8db0fcb15f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/329189
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-17 20:42:23 +00:00
Michael Anthony Knyszek
671954e72e [dev.typeparams] runtime/internal/sys: replace GOOS with goos.GOOS
Refactoring done by rf tool:

    rf 'ex . {
	import "internal/goos"
	import "runtime/internal/sys"
	sys.GOOS -> goos.GOOS
    }'

Change-Id: I4b4aadff8640731ce4cb9bdad9954c267eb484c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/328339
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-17 20:42:08 +00:00
Michael Anthony Knyszek
5c028751bd [dev.typeparams] runtime/internal/sys: replace uses of GOARCH with goarch.GOARCH
Refactoring performed by the rf tool:

    rf 'ex . {
	import "internal/goarch"
	import "runtime/internal/sys"
	sys.GOARCH -> goarch.GOARCH
    }'

Change-Id: I4b0246bf4e734f08313c6fff7b547db362057714
Reviewed-on: https://go-review.googlesource.com/c/go/+/328338
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-17 20:42:01 +00:00
Michael Anthony Knyszek
6d89c90fb1 [dev.typeparams] runtime/internal/sys: remove unused PtrSize
Change-Id: I01e079b95f71b01edaf049d49a0993a7ed39c7bf
Reviewed-on: https://go-review.googlesource.com/c/go/+/328810
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-17 18:54:59 +00:00
Michael Anthony Knyszek
6d85891b29 [dev.typeparams] runtime: replace uses of runtime/internal/sys.PtrSize with internal/goarch.PtrSize [generated]
[git-generate]
cd src/runtime/internal/math
gofmt -w -r "sys.PtrSize -> goarch.PtrSize" .
goimports -w *.go
cd ../..
gofmt -w -r "sys.PtrSize -> goarch.PtrSize" .
goimports -w *.go

Change-Id: I43491cdd54d2e06d4d04152b3d213851b7d6d423
Reviewed-on: https://go-review.googlesource.com/c/go/+/328337
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-17 18:54:48 +00:00
Michael Anthony Knyszek
122f5e16d6 [dev.typeparams] internal/goarch,internal/goos: explode runtime/internal/sys into pieces
This change extracts the GOOS and GOARCH specific constants from
runtime/internal/sys into packages that are available to the entire
standard library.

This change does not yet update the runtime and associated packages to
use them, and instead adds constants to runtime/internal/sys to forward
the constants defined by these new packages.

Change-Id: I14d574b8d7bfe599ad25da29dc1b39716e35a734
Reviewed-on: https://go-review.googlesource.com/c/go/+/328336
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-17 18:54:38 +00:00
Matthew Dempsky
804ecc2581 [dev.typeparams] all: add GOEXPERIMENT=unified knob
Setting `-gcflags=all=-d=unified` works for normal builds/tests, but
seems to have trouble with the test/run.go regress tests. So add a
GOEXPERIMENT knob to allow another way to turn on unified IR
construction, which plays better with all.bash.

While here, update two existing test expectations that currently fail
during GOEXPERIMENT=unified ./all.bash:

1. misc/cgo/errors/testdata/err2.go is testing column positions, and
types2 gets one case slightly better, and another case slightly
worse. For now, the test case is updated to accept both.

2. fixedbugs/issue42284.go is added to the list of known failures,
because it fails for unified IR. (It's an escape analysis test, and
escape analysis is working as expected; but unified is formatting an
imported constant value differently than the test's regexp expects.)

Updates #46786.

Change-Id: I40a4a70fa1b85ac87fcc85a43687f5d81e011ec0
Reviewed-on: https://go-review.googlesource.com/c/go/+/328215
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-06-17 09:09:02 +00:00
Cuong Manh Le
b14fd720a8 [dev.typeparams] cmd/compile: make types2 report better error for invalid untyped operation
This ports the fix in CL 328050 for typecheck to types2.

The fix is not identical, due to code structure differences between
typecheck and types2, but the idea is the same. We only do the untyped
conversion when both operands can be mixed.

Updates #46749

Change-Id: Ib2c63ba0d5dd8bf02318b1bfdfe51dcaeeeb7f82
Reviewed-on: https://go-review.googlesource.com/c/go/+/328053
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-06-17 02:30:22 +00:00
Rob Findley
8115ae198d [dev.typeparams] go/types: disallow ~T where T is a defined type or an interface
This is a straightforward port of CL 324570 to go/types.

Change-Id: I1395775a1d21a903a57e0cefc4e240cfa2bb8e97
Reviewed-on: https://go-review.googlesource.com/c/go/+/326684
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-06-17 02:15:03 +00:00
Rob Findley
6237e441bc [dev.typeparams] go/types: disallow type list handling
This is a port of CL 324571 to go/types, though type list handling is
guarded by a const rather than a config option.

Change-Id: I91c940fead048980603e0bb56fcc896dbef4f94c
Reviewed-on: https://go-review.googlesource.com/c/go/+/326683
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-06-17 02:14:52 +00:00
Rob Findley
6e50f4f111 [dev.typeparams] go/types: convert testdata/check tests to type set syntax
This is a port of CL 324569 to go/types, with some error positions
adjusted: go/types puts errors related to terms on the '~', not type
name.

Change-Id: I92e8443ce27a5ecae0e3e0dac4811eaf3eee07ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/326682
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-06-17 02:14:13 +00:00
Rob Findley
b6fc4d01a8 [dev.typeparams] go/types: convert testdata/fixedbugs tests to type set sytax
This is a port of CL 324530 to go/types. One error position in
issue39634.go2 was adjusted by a character, to account for go/types'
positioning.

Change-Id: Ie06974ea9ee81d3ae66ef58dba522936ab4ce2d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/326681
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-06-17 02:10:00 +00:00
Rob Findley
795f4475e5 [dev.typeparams] go/types: convert testdata/examples tests to type set sytax
This is a straightforward port of CL 324529 to go/types.

Change-Id: I788b1ac3d4e40060038a134c525c81624add8e81
Reviewed-on: https://go-review.googlesource.com/c/go/+/326680
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-06-17 02:09:33 +00:00
Rob Findley
8e14a9cf04 [dev.typeparams] go/types: eliminate need for unpack and asUnion functions
This is a straightforward port of CL 323355 to go/types, adjusted for
the different error reporting API in go/types.

Change-Id: I0f9d7ca0e0959e1e214ecd61eb85cc311e6409a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/326679
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-06-17 02:08:57 +00:00
Rob Findley
aecfd5c29e [dev.typeparams] go/types: clean up type set/union intersection
This is a straightforward port of CL 323354 to go/types.

Change-Id: I53512540cc35df6e88b2b66e144e1be7ccc9a6f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/326678
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-06-17 02:08:29 +00:00
Rob Findley
c7a460526e [dev.typeparams] go/types: replace Sum type with Union type
This is a straightforward port of CL 323274 to go/types.

Change-Id: Ica769d90fd482703f260f105199d2f2229498e95
Reviewed-on: https://go-review.googlesource.com/c/go/+/326677
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-06-17 02:08:15 +00:00
Rob Findley
e7451f6616 [dev.typeparams] go/types: accept embedded interface elements
This is a port of CL 321689 to go/types. It differs from that CL in the
uses of the position, AST and error APIs, and in not factoring out an
unimplemented() helper (this helper didn't already exist in go/types, so
it seemed cleaner to defer adding it).

Change-Id: I577a57297caf35eb7a23f63f3f52037a7bb528ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/326069
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-06-17 02:08:05 +00:00
Rob Findley
54f854fb41 [dev.typeparams] go/parser: accept embedded type literals
This is an approximate port of CL 321109 to go/parser, though go/parser
does not have the same internal APIs as cmd/compile/internal/syntax, so
this CL required some refactoring.

Change-Id: I146ef530c969d61bab99f98f4de94b862e103ddc
Reviewed-on: https://go-review.googlesource.com/c/go/+/325703
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-06-17 02:06:15 +00:00
Rob Findley
ab4b3c4b15 [dev.typeparams] go/parser: accept "~" and "|" interface elements
This is a port of CL 307371 to go/parser, adding support for the new
embedded type expressions. As in that CL, type lists continue to be
accepted.

This CL also revealed a pre-existing bug related to embedded instances:
the parser was failing to parse embedded instances with multiple type
arguments, due to not consuming the initial ','. This is fixed, and
along the way TestErrors is modified to use subtests.

Several missing tests cases were added to exprstring_test.go. These must
have been missed in an earlier CL.

Change-Id: I452769536998cddb1618bebdba675fc09d48a12f
Reviewed-on: https://go-review.googlesource.com/c/go/+/325690
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-06-17 02:06:03 +00:00
Rob Findley
7c5d7a4caf [dev.typeparams] go/token, go/scanner: add the "~" operator
This is an approximate port of CL 307370 to go/token and go/scanner.

Change-Id: I5b789408f825f7e39f569322cb67802117b9d734
Reviewed-on: https://go-review.googlesource.com/c/go/+/324992
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-06-17 02:05:54 +00:00
Rob Findley
ad59efb027 [dev.typeparams] go/ast: remove the typeparams build constraint
This CL removes the typeparams build constraint guarding changes to the
go/ast and go/types APIs. Notably it does not remove all indirection
added to hide the type parameter API: the go/internal/typeparams
package is not yet deleted, nor have go/parser or go/types been updated
to access type parameter data directly. This will be done in a follow-up
CL; the intent of this CL is to make it easier to support the new type
set syntax, and to experiment with different AST APIs.

Change-Id: I13ea0285752991b87b3aead1d1371e1f3f817b1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/325689
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-06-17 02:05:42 +00:00
Matthew Dempsky
1ba2074440 [dev.typeparams] cmd/compile/internal/types2: support local defined types
This CL changes types2's instance hashing logic to include position
information for function-scope defined types as disambiguation. This
isn't ideal, but it worked for getting nested.go passing.

Updates #46592.

Change-Id: Id83ba0001f44af69b81260306cc8b05e44fc4f09
Reviewed-on: https://go-review.googlesource.com/c/go/+/327170
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-06-16 21:38:50 +00:00
Matthew Dempsky
dd95a4e3db [dev.typeparams] cmd/compile: simplify SSA devirtualization
This CL implements a few improvements to SSA devirtualization to make
it simpler and more general:

1. Change reflectdata.ITabAddr to now immediately generate the wrapper
functions and write out the itab symbol data. Previously, these were
each handled by separate phases later on.

2. Removes the hack in typecheck where we marked itabs that we
expected to need later. Instead, the calls to ITabAddr in walk now
handle generating the wrappers.

3. Changes the SSA interface call devirtualization algorithm to just
use the itab symbol data (namely, its relocations) to figure out what
pointer is available in memory at the given offset. This decouples it
somewhat from reflectdata.

Change-Id: I8fe06922af8f8a1e7c93f5aff2b60ff59b8e7114
Reviewed-on: https://go-review.googlesource.com/c/go/+/327871
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-06-16 20:57:38 +00:00
Matthew Dempsky
132ea56d29 [dev.typeparams] cmd/compile: fix crawling of embeddable types
In reflectdata, we have a hack to only apply inlining for (*T).M
wrappers generated around T.M. This was a hack because I didn't
understand at the time why other cases were failing.

But I understand now: during export, we generally skip exporting the
inline bodies for unexported methods (unless they're reachable through
some other exported method). But it doesn't take into account that
embedding a type requires generating wrappers for promoted methods,
including imported, unexported methods.

For example:

	package a
	type T struct{}
	func (T) m() {} // previously omitted by exported

	package b
	import "./a"
	type U struct { a.T } // needs U.m -> T.m wrapper

This CL adds extra logic to the crawler to recognize that T is an
exported type directly reachable by the user, so *all* of its methods
need to be re-exported.

This finally allows simplifying reflectdata.methodWrapper to always
call inline.InlineCalls.

Change-Id: I25031d41fd6b6cd69d31c6a864b5329cdb5780e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/327872
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-06-16 17:32:49 +00:00
Cuong Manh Le
8f95eaddd3 [dev.typeparams] cmd/compile: fix missing sync implicit types
CL 328051 introduced new syncImplicitTypes, but forgot to add a sync
after syncAddBody in linker.relocFuncExt, cause the compiler crashes
when reading in package data.

Adding missing w.sync(syncImplicitTypes) call fixes this.

While at it, also run go generate to update code generated for
syncImplicitTypes, which is also missed in CL 328051.

Change-Id: Ic65092f69f8d8e63de15989c7f15b6e5633d8f9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/328054
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-16 16:30:37 +00:00
Cherry Mui
a4121d7dd6 [dev.typeparams] Revert "[dev.typeparams] runtime: make deferproc take a func() argument"
Temprary revert CL 325918.

Delve relies on the _defer.fn.fn field to get defer frames.
CL 325918 changes the type of _defer.fn to func(), which no
longer has an fn field.

Change-Id: If6c71b15a27bac579593f5273c9a49715e6e35b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/327775
Trust: Cherry Mui <cherryyz@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-06-16 15:27:43 +00:00
Cuong Manh Le
4d6f9d60cf [dev.typeparams] all: merge master (785a8f6) into dev.typeparams
- test/run.go

  CL 328050 added fixedbugs/issue46749.go to -G=3 excluded files list

Merge List:

+ 2021-06-16 785a8f677f cmd/compile: better error message for invalid untyped operation
+ 2021-06-16 a752bc0746 syscall: fix TestGroupCleanupUserNamespace test failure on Fedora
+ 2021-06-15 d77f4c0c5c net/http: improve some server docs
+ 2021-06-15 219fe9d547 cmd/go: ignore UTF8 BOM when reading source code
+ 2021-06-15 723f199edd cmd/link: set correct flags in .dynamic for PIE buildmode
+ 2021-06-15 4d2d89ff42 cmd/go, go/build: update docs to use //go:build syntax
+ 2021-06-15 033d885315 doc/go1.17: document go run pkg@version
+ 2021-06-15 ea8612ef42 syscall: disable c-shared test when no cgo, for windows/arm
+ 2021-06-15 abc56fd1a0 internal/bytealg: remove duplicate go:build line
+ 2021-06-15 4061d3463b syscall: rewrite handle inheritance test to use C rather than Powershell
+ 2021-06-15 cf4e3e3d3b reflect: explain why convertible or comparable types may still panic
+ 2021-06-14 7841cb14d9 doc/go1.17: assorted fixes
+ 2021-06-14 8a5a6f46dc debug/elf: don't apply DWARF relocations for ET_EXEC binaries
+ 2021-06-14 9d13f8d43e runtime: update the variable name in comment
+ 2021-06-14 0fd20ed5b6 reflect: use same conversion panic in reflect and runtime
+ 2021-06-14 6bbb0a9d4a cmd/internal/sys: mark windows/arm64 as c-shared-capable
+ 2021-06-14 d4f34f8c63 doc/go1.17: reword "results" in stack trace printing

Change-Id: I60d1f67c4d48cd4093c350fc89bd60c454d23944
2021-06-16 14:59:13 +07:00
Cuong Manh Le
ee0420d3b5 [dev.typeparams] cmd/compile: factor out implicit/explicit handling
The logic for handling them must keep in sync between reader/writer, so
factoring them out from addBody make it's easier to refer later.

Change-Id: I26447065867d79f4f47cc678a398b9e7bf5d2403
Reviewed-on: https://go-review.googlesource.com/c/go/+/328051
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: Matthew Dempsky <mdempsky@google.com>
2021-06-16 06:10:32 +00:00
Cuong Manh Le
785a8f677f cmd/compile: better error message for invalid untyped operation
For typed vs un-typed operation, the compiler do the conversion
un-conditionally, so if the operation is invalid, the error report is
pointed to the conversion, instead of the invalid operation itself.

To fix this, only do the conversion when the operations are valid
for both types.

Fixes #46749

Change-Id: Ib71c7bcd3ed5454e6df55b6a8db4e0f189259ba7
Reviewed-on: https://go-review.googlesource.com/c/go/+/328050
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: Matthew Dempsky <mdempsky@google.com>
2021-06-16 06:05:23 +00:00
Rahul Bajaj
a752bc0746 syscall: fix TestGroupCleanupUserNamespace test failure on Fedora
Fixes #46752

Change-Id: I2eaa9d15fac4e859e18191fcf1372e5be94899df
GitHub-Last-Rev: 8a2672d8dc
GitHub-Pull-Request: golang/go#46753
Reviewed-on: https://go-review.googlesource.com/c/go/+/328109
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2021-06-16 04:45:46 +00:00
Matthew Dempsky
cf1ae5fc36 [dev.typeparams] cmd/compile: add -d=unified flag to enable unified IR
This CL adds a new -d=unified debug flag, which controls whether
unified IR mode is used.

Change-Id: Iaa5f3cc0a24b9881aeec5317cd6b462b4a7b6fc9
Reviewed-on: https://go-review.googlesource.com/c/go/+/327054
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-06-15 22:29:54 +00:00
Filippo Valsorda
d77f4c0c5c net/http: improve some server docs
Change-Id: I04662a08e07c49f629f9067a89bf453e697d44dd
Reviewed-on: https://go-review.googlesource.com/c/go/+/327813
Trust: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2021-06-15 20:59:42 +00:00
Matthew Dempsky
79cd1687e6 [dev.typeparams] cmd/compile: unified IR construction
This CL adds a new unified IR construction mode to the frontend.  It's
purely additive, and all files include "UNREVIEWED" at the top, like
how types2 was initially imported. The next CL adds a -d=unified flag
to actually enable unified IR mode.

See below for more details, but some highlights:

1. It adds ~6kloc (excluding enum listings and stringer output), but I
estimate it will allow removing ~14kloc (see CL 324670, including its
commit message);

2. When enabled by default, it passes more tests than -G=3 does (see
CL 325213 and CL 324673);

3. Without requiring any new code, it supports inlining of more code
than the current inliner (see CL 324574; contrast CL 283112 and CL
266203, which added support for inlining function literals and type
switches, respectively);

4. Aside from dictionaries (which I intend to add still), its support
for generics is more complete (e.g., it fully supports local types,
including local generic types within generic functions and
instantiating generic types with local types; see
test/typeparam/nested.go);

5. It supports lazy loading of types and objects for types2 type
checking;

6. It supports re-exporting of types, objects, and inline bodies
without needing to parse them into IR;

7. The new export data format has extensive support for debugging with
"sync" markers, so mistakes during development are easier to catch;

8. When compiling with -d=inlfuncswithclosures=0, it enables "quirks
mode" where it generates output that passes toolstash -cmp.

--

The new unified IR pipeline combines noding, stenciling, inlining, and
import/export into a single, shared code path. Previously, IR trees
went through multiple phases of copying during compilation:

1. "Noding": the syntax AST is copied into the initial IR form. To
support generics, there's now also "irgen", which implements the same
idea, but takes advantage of types2 type-checking results to more
directly construct IR.

2. "Stenciling": generic IR forms are copied into instantiated IR
forms, substituting type parameters as appropriate.

3. "Inlining": the inliner made backup copies of inlinable functions,
and then copied them again when inlining into a call site, with some
modifications (e.g., updating position information, rewriting variable
references, changing "return" statements into "goto").

4. "Importing/exporting": the exporter wrote out the IR as saved by
the inliner, and then the importer read it back as to be used by the
inliner again. Normal functions are imported/exported "desugared",
while generic functions are imported/exported in source form.

These passes are all conceptually the same thing: make a copy of a
function body, maybe with some minor changes/substitutions. However,
they're all completely separate implementations that frequently run
into the same issues because IR has many nuanced corner cases.

For example, inlining currently doesn't support local defined types,
"range" loops, or labeled "for"/"switch" statements, because these
require special handling around Sym references. We've recently
extended the inliner to support new features like inlining type
switches and function literals, and they've had issues. The exporter
only knows how to export from IR form, so when re-exporting inlinable
functions (e.g., methods on imported types that are exposed via
exported APIs), these functions may need to be imported as IR for the
sole purpose of being immediately exported back out again.

By unifying all of these modes of copying into a single code path that
cleanly separates concerns, we eliminate many of these possible
issues. Some recent examples:

1. Issues #45743 and #46472 were issues where type switches were
mishandled by inlining and stenciling, respectively; but neither of
these affected unified IR, because it constructs type switches using
the exact same code as for normal functions.

2. CL 325409 fixes an issue in stenciling with implicit conversion of
values of type-parameter type to variables of interface type, but this
issue did not affect unified IR.

Change-Id: I5a05991fe16d68bb0f712503e034cb9f2d19e296
Reviewed-on: https://go-review.googlesource.com/c/go/+/324573
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-06-15 20:35:54 +00:00
unbyte
219fe9d547 cmd/go: ignore UTF8 BOM when reading source code
Fix the problem that UTF8 BOM can cause the parsing of import path and directives to fail.

Fixes #46198
Fixes #46290
Fixes #35726

Change-Id: I2d9995ee82b094bcfa5583f0cb4e8547cb973077
GitHub-Last-Rev: 98abf91377
GitHub-Pull-Request: golang/go#46643
Reviewed-on: https://go-review.googlesource.com/c/go/+/325990
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-15 18:42:11 +00:00
Than McIntosh
723f199edd cmd/link: set correct flags in .dynamic for PIE buildmode
For internal linking, when generating a PIE binary, set the proper
.dynamic section flags to mark the binary as position-independent.

Fixes #46747.

Change-Id: I2b899148c6d06f92c9d12257a9761278b4236dfc
Reviewed-on: https://go-review.googlesource.com/c/go/+/328089
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Trust: Than McIntosh <thanm@google.com>
2021-06-15 18:09:44 +00:00
Damien Neil
4d2d89ff42 cmd/go, go/build: update docs to use //go:build syntax
Fixes #46124.

Change-Id: I6b8179032102a14befc37719f64ddace98397c97
Reviewed-on: https://go-review.googlesource.com/c/go/+/326931
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2021-06-15 18:05:29 +00:00
Michael Matloob
033d885315 doc/go1.17: document go run pkg@version
Fixes #46687

Change-Id: I6c311f15d3871a9824306b901fa0b81818ed2df8
Reviewed-on: https://go-review.googlesource.com/c/go/+/326870
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-06-15 17:05:31 +00:00
Jason A. Donenfeld
ea8612ef42 syscall: disable c-shared test when no cgo, for windows/arm
The windows/arm port does not yet support cgo, so disable a test that
requires it. This fixes a regression from CL 327969, which added support
for arm64, but errantly dropped the t.Skip for both arm and arm64,
rather than just for arm64. With this commit, we make the test specific
to cgo, rather than the architecture.

Change-Id: Ibe1166c1965e007c7af899b07ded65f2a2633ddd
Reviewed-on: https://go-review.googlesource.com/c/go/+/327970
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-06-15 16:53:28 +00:00