Commit graph

48780 commits

Author SHA1 Message Date
Rob Findley 82f875d735 [dev.typeparams] go/types: fix generic type indirection
This is a port of CL 333890 to go/types.

Change-Id: I8ee20f405dad98083bb5e91636044d132a95d909
Reviewed-on: https://go-review.googlesource.com/c/go/+/335081
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-07-19 17:09:27 +00:00
Rob Findley 62f6f130fe [dev.typeparams] go/types: interface identity must consider full type set
This is a port of CL 333889 to go/types.

Change-Id: I66cefb81a33f4677efc18c1ca923ded374a87f12
Reviewed-on: https://go-review.googlesource.com/c/go/+/335080
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-07-19 17:09:20 +00:00
Rob Findley baeabf3b36 [dev.typeparams] go/types: cleanups around receiver type checks
This is a port of CL 333770 to go/types, adjusted for the error
reporting API and to not support compiler error messages. An error
message changed (to 'invalid receiver type' from just 'invalid
receiver'), so a test had to be adjusted.

Change-Id: I166e8831d8c9f98ebfb0270fe5221586fc112825
Reviewed-on: https://go-review.googlesource.com/c/go/+/335079
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-07-19 17:09:14 +00:00
Rob Findley b3d91e3a24 [dev.typeparams] go/types: implement delete(m, k) where m is of type parameter type
This is a port of CL 333729 to go/types.

Change-Id: I8682f549a7a15124b1b338f8c73e83a57d138368
Reviewed-on: https://go-review.googlesource.com/c/go/+/335078
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-07-19 17:08:59 +00:00
Rob Findley cf7e66b7d4 [dev.typeparams] go/types: implement close(ch) where ch is of type parameter type
This is a port of CL 333713 to go/types.

Change-Id: I517f52592f65cc76e11a12d9148b20c12d9e3e81
Reviewed-on: https://go-review.googlesource.com/c/go/+/335077
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-07-19 17:08:53 +00:00
Rob Findley 19b4142f24 [dev.typeparams] go/types: implement ch <- x where ch is of type parameter type
This is a port of CL 333712 to go/types, adjusted for the different
error reporting API and to position errors on the arrows.

Fixes #43671

Change-Id: I7d2de249e86d272c89a046f60e632e75848ff865
Reviewed-on: https://go-review.googlesource.com/c/go/+/335076
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-07-19 17:08:45 +00:00
Rob Findley d6d7f8458e [dev.typeparams] go/types: implement <-ch where ch is of type parameter type
This is a port of CL 333709 to go/types, adjusted for the different
error API.

Fixes #43671

Change-Id: Ifd340149bfbcabe401cec74398cb83f2ae812e51
Reviewed-on: https://go-review.googlesource.com/c/go/+/335075
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-07-19 17:08:29 +00:00
Rob Findley 796ac6d5f2 [dev.typeparams] go/types: move methods on *Named into named.go
This is a port of CL 333671 to go/types.

Change-Id: Ic2f66b49f1db68fb93d5095131733e99a37b9cbf
Reviewed-on: https://go-review.googlesource.com/c/go/+/335074
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-07-19 17:07:41 +00:00
Rob Findley 22f39ba208 [dev.typeparams] go/types: use InstantiateLazy to create instance types (cleanup)
This is a port of CL 333669 to go/types, adjusted for the position and
IndexExpr APIs, and excluding the noder changes.

Change-Id: I3ac4bbf271947c3cf80ab04c462a91657316f4fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/335073
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-07-19 17:07:35 +00:00
Rob Findley 4a72be87b3 [dev.typeparams] go/types: move instantiation code to instantiate.go (cleanup)
This is a port of CL 333589 to go/types.

Change-Id: Ib9fb1b09e10c400e62d20b55ff0558f3a92fc0eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/335072
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-07-19 17:07:28 +00:00
Rob Findley 41ff0aac13 [dev.typeparams] go/types: replace types2.Instantiate with Checker.Instantiate
This is a partial port of CL 333569 containing just changes to go/types.
Changes to the importer wil be made in a separate CL.

Change-Id: I9383e260b76402875ca6eb23c4478a6a3e8c1f0d
Reviewed-on: https://go-review.googlesource.com/c/go/+/335071
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-07-19 16:51:16 +00:00
Rob Findley 9e147c55b7 [dev.typeparams] go/types: update TypeParam APIs to match types2
This is a partial port of CL 323029, consisting only of changes to
go/types. Changes to the importer will be made in a separate CL.

Change-Id: I3b300f5e8f4df36c2c87e3f164705cd3c36218ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/335145
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-07-19 15:50:51 +00:00
Rob Findley 22a38ba5ca [dev.typeparams] go/types: remove unnecessary guard from NewInterfaceType
This is a partial port of CL 322609, containing only changes to
go/types. Importer changes will be made in a separate CL.

Change-Id: I50af3c1ed5e949bb28a3462d717c0eb29a5f31ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/335144
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-07-19 15:50:21 +00:00
Rob Findley b96f1b9419 [dev.typeparams] go/types: add some missing APIs for the importer
This is a partial port of CL 319930, containing only changes to
go/types. Importer changes will be made in a separate CL.

The TypeParams APIs are left unexported for now; they will be exported
when they are needed.

Change-Id: I74bd246d4c174cb38f8360d921c733fa03900eab
Reviewed-on: https://go-review.googlesource.com/c/go/+/335143
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-07-19 15:50:07 +00:00
Rob Findley 43ad1ffa99 [dev.typeparams] go/types: recursive substitution must terminate (bug fix)
This is a port of CL 333383 to go/types.

Change-Id: I7ff68116cbe63337dbcc834c473a2a5588274e36
Reviewed-on: https://go-review.googlesource.com/c/go/+/335115
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-07-19 15:49:58 +00:00
Rob Findley c7c13ae432 [dev.typeparams] go/types: use scope numbers to identify local types
This is a port of CL 333192 to go/types.

Change-Id: I12fd6b682d40c4d30b9ac0e87c463843cf5030d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/335114
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-19 15:49:47 +00:00
Rob Findley ccf95f17dd [dev.typeparams] go/types: support local defined types
This is a port of CL 327170 to go/types. Tests were not ported; they can
be added later.

Change-Id: Ic9fd681ac06dd187c1715efaf882b11353bc395a
Reviewed-on: https://go-review.googlesource.com/c/go/+/335113
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-07-19 15:49:09 +00:00
Rob Findley 76b39959f4 [dev.typeparams] go/types: don't permit method calls on ptr to type parameter receivers
This is a port of CL 332609 to go/types.

Change-Id: I3482ea1b97bc7101b987ef312cd6cade80a5843f
Reviewed-on: https://go-review.googlesource.com/c/go/+/335112
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-07-19 15:48:55 +00:00
Dan Scales 9b85985d36 [dev.typeparams] Separate out gcshape types that are instantiated types
Distinguish the gcshape of all top-level instantiated type from normal
concrete types, even if they have the exact same underlying "shape",
because in a function instantiation, any method call on this type arg
will be a generic method call (requiring a dictionary), rather than a
direct method call on the underlying type (no dictionary).

So, we add the instshape prefix to the gcshape name for instantiated
types, and we make it a defined type with that name.

Change-Id: I33056269d24f3451a2632a5ce6a481108f533c9c
Reviewed-on: https://go-review.googlesource.com/c/go/+/335169
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-07-19 05:02:24 +00:00
Rob Findley df778e6fd9 [dev.typeparams] go/types: replace optype() with under() in various cases (cleanup)
This is a port of CL 332555 to go/types.

Change-Id: I9b26bba8b605f5bbbd8f0f81fd6651a4a3ff4b57
Reviewed-on: https://go-review.googlesource.com/c/go/+/335111
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-07-17 01:52:18 +00:00
Rob Findley e9836fe318 [dev.typeparams] go/types: clean up index expr implementation for type parameters
This is a port of CL 332553 to go/types. The "expr" variable is renamed to
"e" in Checker.indexExpr to be consistent with types2.

Change-Id: I7905bebf2e8dab47256361362b16becf7596cf95
Reviewed-on: https://go-review.googlesource.com/c/go/+/335110
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
2021-07-17 01:38:18 +00:00
Rob Findley c4cd76fbbb [dev.typeparams] go/types: disallow "free" type parameter as RHS of a type declaration
This is a port of CL 332411 to go/types. methodset_test.go is similarly
updated.

Change-Id: I332b1837a954acc9d3b7e0e2ad2bec3425f088f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/335109
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
2021-07-17 01:35:49 +00:00
Rob Findley 521828091c [dev.typeparams] go/types: move (remaining) type decls into their own files (cleanup)
This is a port of CL 332093 to go/types. A missing comment is added to
named.go, and some TODOs were added to converge on the TypeParam API.

Change-Id: I781a1d0d3fc6c11bb323123e954c106094d998ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/335040
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-07-16 23:35:10 +00:00
Rob Findley 624d152db7 [dev.typeparams] go/types: move Interface type decl into interface.go (cleanup)
This is a port of CL 332092 to go/types.

Change-Id: I9971c49570424368575108832eac0cd978eb3fe6
Reviewed-on: https://go-review.googlesource.com/c/go/+/335039
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-07-16 23:34:53 +00:00
Rob Findley e12d43866d [dev.typeparams] go/types: move Signature type decl into signature.go (cleanup)
This is a port of CL 332091 to go/types. Notably types.Signature is
missing APIs for RParams. This is left for a later CL, when the API is
finalized.

Change-Id: I70b664d656e8c1e32958a75e1d13eab5f3281bf9
Reviewed-on: https://go-review.googlesource.com/c/go/+/335038
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-07-16 23:34:44 +00:00
Rob Findley b3e7f23a48 [dev.typeparams] go/types: move Struct type decl into struct.go (cleanup)
This is a port of CL 332090 to go/types.

Change-Id: Idc480374f5efe0e7f34f76f37ffd02a3aef59c67
Reviewed-on: https://go-review.googlesource.com/c/go/+/335037
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-16 23:34:35 +00:00
Rob Findley 7c35f5c2fc [dev.typeparams] go/types: rename newTypeSet -> computeTypeSet
This is a port of CL 332089 to go/types.

Change-Id: I39321eaee184c8204bd255b7770a0770ecb25fda
Reviewed-on: https://go-review.googlesource.com/c/go/+/335036
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-07-16 23:34:25 +00:00
Rob Findley de209e693a [dev.typeparams] go/types: make Interface.obj a *TypeName
This is a straightforward port of CL 332011 to go/types.

Change-Id: I682791886c8496c52094f3688e36934afbd7a241
Reviewed-on: https://go-review.googlesource.com/c/go/+/335035
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-07-16 23:34:15 +00:00
Rob Findley 0f4198b5e2 [dev.typeparams] go/types: delay interface check for type bounds
This is a port of CL 331690 to go/types. It diverges from that CL due to
the different representation of Fields in the AST.

Change-Id: I3ae9ac3a0172dc58ac748f28772d87b00db0732a
Reviewed-on: https://go-review.googlesource.com/c/go/+/335034
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-07-16 23:34:00 +00:00
Rob Findley 5f50a6442e [dev.typeparams] go/internal/typeparams: remove the Enabled guard
Type parameters are now always enabled. Users should guard against type
checking generic code by using the types.Config.GoVersion field.

This cleans up some differences with types2.

Change-Id: Ie3e35a549e456a90a10d6a7e158ff58653cc1394
Reviewed-on: https://go-review.googlesource.com/c/go/+/335033
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-07-16 23:08:28 +00:00
Rob Findley 726ffce659 [dev.typeparams] go/types: "comparable" must not be visible before Go 1.18
This is a straightforward port of CL 331517 to go/types.

Change-Id: Id00761fd5dffb4d09e19f086d18ddc20f11528d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/335032
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-07-16 23:07:17 +00:00
Rob Findley 79955155e9 [dev.typeparams] go/types: move newTypeSet function into typeset.go
This is a straightforward port of CL 331515 to go/types.

Change-Id: I05c687e7dd7a64a8a7815c4483ff7fbb06b37627
Reviewed-on: https://go-review.googlesource.com/c/go/+/335031
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-16 23:07:10 +00:00
Rob Findley fe4f13404d [dev.typeparams] go/types: move embedding positions from Checker to Interface
This is a straightforward port of CL 331514 to go/types, with minor
adjustments for the different position API.

Change-Id: I714b3f1cd5a0e8d249912bb589d456885a87e167
Reviewed-on: https://go-review.googlesource.com/c/go/+/335030
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-07-16 23:05:06 +00:00
Rob Findley b98b8b9b5b [dev.typeparams] go/types: remove unused *Checker arguments (cleanup)
This is a straightforward port of CL 331512 to go/types. API usage in
methodset.go was also updated.

Change-Id: I6701265c9d2ae40eb9aa0ea5f00c98ce3516edab
Reviewed-on: https://go-review.googlesource.com/c/go/+/335009
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-07-16 23:04:55 +00:00
Rob Findley fce6290e0a [dev.typeparams] go/types: remove typeparams wrappers and aliases
These wrappers and aliases were necessary when we had different versions
of the API depending on the typeparams build constraint, but now they're
just boilerplate. Remove them.

Notably the documentation for types.Info is restored.

Change-Id: I5363d1d5df47649c2641c03328dfba45b1456278
Reviewed-on: https://go-review.googlesource.com/c/go/+/334895
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-07-16 23:04:45 +00:00
Rob Findley 24f9eb2de3 [dev.typeparams] go/types: introduce type set abstraction for interfaces
This is a port of CL 329309 to go/types, with minor updates for API
differences and to handle methodset.go, which doesn't exist in types2.

A couple pre-existing comments were adjusted to match types2.

Change-Id: I3fd556e1326013a694ff5edb8518ca24c27bd10b
Reviewed-on: https://go-review.googlesource.com/c/go/+/334894
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-07-16 23:04:35 +00:00
Rob Findley b296e54618 [dev.typeparams] go/types: port lazy import resolution from types2
This is a straightforward port of CL 323569 to go/types. It is
line-for-line identical, except where names are unexported to preserve
the current go/types API.

Change-Id: I4c78211bff90f982ca2e90ed224946716118ee31
Reviewed-on: https://go-review.googlesource.com/c/go/+/334893
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-07-16 23:04:27 +00:00
Keith Randall 10c8b7c1d7 [dev.typeparams] cmd/compile: use dictionary to convert arguments of ==, != to interfaces
When comparing a value whose type is a type parameter to an interface,
we need to convert that type parameter to an interface using the dictionary
entries.

Change-Id: I409c9e36e376fe4ef8163407d0fd4e84496d5b65
Reviewed-on: https://go-review.googlesource.com/c/go/+/334150
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-07-16 18:31:15 +00:00
Dan Scales ed9e109dc9 [dev.typeparams] cmd/compile: fix small -G=3 issues for tests disabled in run.go
- set correct position for closure capture variable in (*irgen).use()
   (issue20250.go) Also, evaluate rhs, lhs in that order in assignment
   statements to match noder1 (affects ordering of closure variables).

 - make sure to set Assign flag properly in (*irgen).forStmt() for range
   variables which are map accesses (issue9691.go)

 - make sure CheckSize() is call on the base type for top-level types
   converted by (*irgen).typ() that are pointer types (issue20174.go and
   issue37837.go)

 - deal with parentheses properly in validation function
   (*irgen).validate() (issue17270.go)

 - avoid HasNil call on type TTYPEPARAM - types2 typechecker will have
   already checked validity of the typeparam having nil value (new test
   issue39755.go)

Change-Id: Ie68004d964698aea047e19e7dcd79b297e9d47ca
Reviewed-on: https://go-review.googlesource.com/c/go/+/334733
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-07-16 18:30:16 +00:00
Robert Griesemer 3d8453e00e [dev.typeparams] cmd/compile/internal/types2: more consistent handling of predeclared "any"
Rather than removing "any" from the universe scope, keep it predeclared
but provide a better error message.

While at it, remove some unnecessary type assertions.

Change-Id: I10603274282ea6afc107f703ab194f32bd334dd1
Reviewed-on: https://go-review.googlesource.com/c/go/+/334911
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-07-16 04:41:47 +00:00
Rob Findley 334f2fc045 [dev.typeparams] go/*: switch from ListExpr to MultiIndexExpr
When instantiating a generic type or function with multiple type
arguments, we need to represent an index expression with multiple
indexes in the AST. Previous to this CL this was done with a new
ast.ListExpr node, which allowed packing multiple expressions into a
single ast.Expr. This compositional pattern can be both inefficient and
cumbersome to work with, and introduces a new node type that only exists
to augment the meaning of an existing node type.

By comparison, other specializations of syntax are given distinct nodes
in go/ast, for example variations of switch or for statements, so the
use of ListExpr was also (arguably) inconsistent.

This CL removes ListExpr, and instead adds a MultiIndexExpr node, which
is exactly like IndexExpr but allows for multiple index arguments. This
requires special handling for this new node type, but a new wrapper in
the typeparams helper package largely mitigates this special handling.

Change-Id: I65eb29c025c599bae37501716284dc7eb953b2ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/327149
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-07-16 00:44:40 +00:00
Matthew Dempsky 6b85a218b8 [dev.typeparams] cmd/compile: make TestUnifiedCompare insensitive to default -G level
The test currently fails if the default -G level is changed from 0 to
3, and it only makes sense to run in -G=0 mode anyway. So might as
well hard code it that way.

Change-Id: I026d25d567157df5d3f2ca3c68d31d75d9c74532
Reviewed-on: https://go-review.googlesource.com/c/go/+/334910
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-07-15 22:24:35 +00:00
Robert Griesemer 4ff0e04c2e [dev.typeparams] cmd/compile/internal/types2: embedding stand-alone type parameters is not permitted
For #47127.

Change-Id: Ie979ff56ae7c2dd0e5ce0ff39588f98ae68b5ee9
Reviewed-on: https://go-review.googlesource.com/c/go/+/334151
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-07-14 23:33:52 +00:00
Robert Griesemer 3a047326e8 [dev.typeparams] cmd/compile/internal/types2: fix generic type indirection
Change-Id: If25ceb2aa403b94608760be331faa2aff11c47cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/333890
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-07-14 23:33:51 +00:00
Robert Griesemer dd8bdf4a1f [dev.typeparams] cmd/compile/internal/types2: interface identity must consider full type set
There is no (obvious) way to test this at the moment because we
don't permit such constraint interfaces as ordinary types.

Change-Id: Ieeec023ed82a2c71ed50d111f26916aba4a59099
Reviewed-on: https://go-review.googlesource.com/c/go/+/333889
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-07-14 23:33:49 +00:00
Robert Griesemer 2a8087817c [dev.typeparams] cmd/compile/internal/types2: cleanups around receiver type checks
Generic receiver types may be defined such that an instantiated
receiver ends up being a pointer type. Disallow them as we do
for non-generic receivers.

Change-Id: I6612a52615a2999375c35aa1d69ab42f37d9f55d
Reviewed-on: https://go-review.googlesource.com/c/go/+/333770
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-07-14 23:33:48 +00:00
Robert Griesemer 95f8e64fc0 [dev.typeparams] cmd/compile/internal/types2: implement delete(m, k) where m is of type parameter type
Change-Id: Iaf33c15128af911b6101df9885cb8b5a8495b942
Reviewed-on: https://go-review.googlesource.com/c/go/+/333729
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-07-14 23:33:47 +00:00
Robert Griesemer 5f0ea40c67 [dev.typeparams] cmd/compile/internal/types2: implement close(ch) where ch is of type parameter type
Change-Id: I45189468553e83390fd2640b5708c60a7852fbb5
Reviewed-on: https://go-review.googlesource.com/c/go/+/333713
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-07-14 23:33:46 +00:00
Robert Griesemer 6511922a14 [dev.typeparams] cmd/compile/internal/types2: implement ch <- x where ch is of type parameter type
For #47115.

Change-Id: Ib9c8652c0346029369735ccf7ee9098ab1ae7fd3
Reviewed-on: https://go-review.googlesource.com/c/go/+/333712
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-07-14 23:33:45 +00:00
Robert Griesemer ff33d3dc3a [dev.typeparams] cmd/compile/internal/types2: implement <-ch where ch is of type parameter type
For #43671

Change-Id: I7db4b3886fab44ec0de7c0935e0ab21c26e3335c
Reviewed-on: https://go-review.googlesource.com/c/go/+/333709
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-07-14 23:33:43 +00:00