Commit Graph

65 Commits

Author SHA1 Message Date
Rob Findley c83a4376c9 [dev.go2go] go/*: merge parser and types changes from dev.typeparams
Merge just the conflicting changes from dev.typeparams (ast, parser,
types, etc.), excluding io/fs changes.

The rest of the dev.typeparams merge will be done in a later CL, once
the compiler changes have stabilized.

Change-Id: Ic24c5902e4cacc85338ab23b100e5a245a5148bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/286774
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
2021-01-27 17:23:18 +00:00
Ian Lance Taylor e6b857770a [dev.go2go] go/go2go: handle inferred arguments for index expressions
Fixes golang/go#41216

Change-Id: Iff109f0a7f047742c5f90d64db201712c04f3259
Reviewed-on: https://go-review.googlesource.com/c/go/+/253818
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-09-09 21:19:10 +00:00
Robert Griesemer c4914f19b5 [dev.go2go] go/types: improve error when a type argument doesn't satisfy constraint
If the cause is a method with incorrect signature, report the
expected and presented signature.

Updates #41125.

Change-Id: Ibd0fa23547b77df924ec5421cc8e657d41c5a5a6
Reviewed-on: https://go-review.googlesource.com/c/go/+/251717
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-31 00:10:51 +00:00
Robert Griesemer dd1af75a70 [dev.go2go] go/types: disable implicit instantiation of single type parameter constraints
Per the latest update to the design draft.

Change-Id: I026b52082e739f6806cd37a0f3e88a546a6f2e90
Reviewed-on: https://go-review.googlesource.com/c/go/+/251139
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-27 23:37:55 +00:00
Robert Griesemer 21bc157bc5 [dev.go2go] go/parser: disallow empty type parameter lists and instantiations
When using unified parameter list syntax, an empty type parameter
list in a type declaration is impossible (it means a slice type).
For symmetry, and because it doesn't make sense to support it,
disallow empty type parameter lists in function declarations.
Accept (parse) them but report a syntax error.

Analogously, disallow empty index/slice/instantiation expressions.
Accept (parse) them but report a syntax error.

Adjust go/types and tests as necessary.

Change-Id: Ifc783245a54d276eb22232a7a74be4d47a7d33fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/250718
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-27 19:10:21 +00:00
Robert Griesemer 27c9d6ef7c [dev.go2go] cmd/go2go: switch to unified parameter syntax
Type and ordinary parameter lists use the same syntax except
for the square brackets or parentheses, respectively.

Change-Id: I6fb93e93bbfc649a2c1ef195d130e0dcee212c79
Reviewed-on: https://go-review.googlesource.com/c/go/+/250717
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-26 16:50:50 +00:00
Robert Griesemer 12c2128b9e [dev.go2go] go/go2go, go/types: enable constraint type inference
Constraint type inference was not enabled for go/go2go and gotype.

Fixes #40859.

Change-Id: Idcab4d0a2eae6f42f938604fb05aabe4ad94c934
Reviewed-on: https://go-review.googlesource.com/c/go/+/249737
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-21 00:12:31 +00:00
Ian Lance Taylor bc00f5ba9f [dev.go2go] test: drop type keyword, always provide constraint
This is a rewrite to drop the type keyword for parameterized functions
and types, and to instead always provide a constraint.

We can revert if we don't like this approach.

Change-Id: If4669fb4e2015067e9f955ff8567ed421be639ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/248880
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-17 17:54:48 +00:00
Ian Lance Taylor 64148d34c7 [dev.go2go] go/go2go: don't import renamed package twice
We keep an import spec if it uses a local alias. Avoid importing it
again, unless it is required by something else.

Fixes #40318

Change-Id: If90de3bf30412645c9144083372e6b07df3c6a0b
Reviewed-on: https://go-review.googlesource.com/c/go/+/244621
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-23 23:17:54 +00:00
Ian Lance Taylor ca218546b8 [dev.go2go] test: rewrite generic tests to square bracket syntax
We can roll back this CL if we go back to parentheses.

Change-Id: Ideb7dbe8e3c4499d76518a5c9b6f7931a7c103a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/243158
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-16 20:18:10 +00:00
Ian Lance Taylor cfb6cac804 [dev.go2go] go/go2go: handle embedded pointers to instantiated types
Change-Id: I47d23dd4a44c644e9ec2f1abbc3cd8cec4a35d04
Reviewed-on: https://go-review.googlesource.com/c/go/+/241125
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-06 23:38:47 +00:00
Ian Lance Taylor b97f992a7e [dev.go2go] go/go2go: F(type)() is not a parameterized function
Fixes #40015

Change-Id: I4e70398e693a53268d3400e829a179c76ff70e75
Reviewed-on: https://go-review.googlesource.com/c/go/+/241124
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-06 23:18:11 +00:00
Ian Lance Taylor 4dde96e380 [dev.go2go] go/go2go: resolve pointers in sameType
Fixes #39982

Change-Id: Ieb33381716662b44464104e0073a52ab5c19b7c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/240899
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-03 19:26:32 +00:00
Ian Lance Taylor 938e96e732 [dev.go2go] go/go2go: instantiate embedded field when needed
If an embedded field is an instantiated type, we need to instantiate
it when instantiating the whole type, in case the type arguments
themselves need instantiation.

Fixes #39953

Change-Id: I80b57456aa4f8e8b2eff82359066c37a9c2a40f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/240522
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-30 23:46:04 +00:00
Ian Lance Taylor 10ea225e28 [dev.go2go] go/go2go: translate types to AST
We were relying on calling typeString and treating that as an AST ident,
with special handling for instantiated types, but that fails if there is
an instantiated type within a type literal.

Fixes #39881

Change-Id: I793fe359868d8d73e830aa8dc67cf52de99355a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/240197
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-26 22:32:53 +00:00
Ian Lance Taylor 93014c51d1 [dev.go2go] go/go2go: avoid crashing on predeclared error type
It has no package, so we need to check for Pkg() == nil.

Fixes #39878

Change-Id: I14a47c5098f97ce42dfa8cc875819f244a2b0201
Reviewed-on: https://go-review.googlesource.com/c/go/+/240013
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-26 18:43:49 +00:00
Ian Lance Taylor 4dfbf5ab9c [dev.go2go] go/go2go: add package qualifier when needed
Fixes #39842

Change-Id: I5046f1bdd7dbc6d1e17cf3835826933aaadf1581
Reviewed-on: https://go-review.googlesource.com/c/go/+/239711
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-25 02:57:14 +00:00
Ian Lance Taylor f04e0ee126 [dev.go2go] go/go2go: include package in instantation of ident
If an instantiated function from a different package uses a plain
identifier to instantiate a generic type or function, include the
package name in the generated identifier.

Fixes #39834

Change-Id: I4c786bac8972475e180cb41178520439343a36ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/239706
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 22:15:29 +00:00
Ian Lance Taylor af16dac1b0 [dev.go2go] go/go2go: don't import both "./a" and "a"
For #39797

Change-Id: I4063a0138062ce8dc1f35cc7fef7c6773c939362
Reviewed-on: https://go-review.googlesource.com/c/go/+/239703
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 21:33:55 +00:00
Ian Lance Taylor fa201df81e [dev.go2go] go/go2go: update name of embedded pointer to instantiation
Fixes #39774

Change-Id: Icb2948ae19e06a3766e7edb01ef40de50e7aca7e
Reviewed-on: https://go-review.googlesource.com/c/go/+/239702
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 21:01:03 +00:00
Ian Lance Taylor e6e8041d02 [dev.go2go] go/go2go: resolve type alias of parameterized type
Fixes #39792

Change-Id: I9eab19a4f516be5a71e71f04b91c4e46b189fba9
Reviewed-on: https://go-review.googlesource.com/c/go/+/239598
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-23 23:35:25 +00:00
Ian Lance Taylor dfb538cec8 [dev.go2go] go/go2go: don't permit underscore as type argument
The go/types package doesn't give us an easy way to get the type,
so just reject it.

Fixes #39743

Change-Id: I5404c10baede0fd2cf67980b06fbebd214a50dff
Reviewed-on: https://go-review.googlesource.com/c/go/+/239382
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 23:30:28 +00:00
Ian Lance Taylor 404a12f056 [dev.go2go] go/go2go: use package name, not package path
types.TypeString defaults to using the package path for references to names.
Provide our own types.Qualifier that uses just the package name,
since that is what the translated code has to use.

Fixes #39744

Change-Id: Icde289b2ed0fdd9b0a9aae6aae4557a8951d25a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/239381
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 23:05:26 +00:00
Ian Lance Taylor a367b7d270 [dev.go2go] go/go2go: check for instantiation with locally defined type
Fixes #39738

Change-Id: I1a3536484a982ec713019572ff7b3c0c36af9784
Reviewed-on: https://go-review.googlesource.com/c/go/+/239380
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 22:19:20 +00:00
Ian Lance Taylor 9b13ca00f8 [dev.go2go] go/go2go: ignore struct tags
Ignore struct tags when generating an instantiated names, and when
comparing types for identity.

Fixes #39737

Change-Id: I53e67fa1d09214dafc4088a59eb00e1a6f18ef3d
Reviewed-on: https://go-review.googlesource.com/c/go/+/239379
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 22:07:26 +00:00
Ian Lance Taylor e643c9792f [dev.go2go] go/go2go: avoid multiple identical instantiations
Move tracking of instantiations from translator to Importer,
so that we can track all instantiations within a package
to avoid duplicates.

Fixes #39749

Change-Id: If6cd5bcdc6e19c2d6481e62a6187ddf7f4fac72a
Reviewed-on: https://go-review.googlesource.com/c/go/+/239337
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 18:38:41 +00:00
Ian Lance Taylor 6500ed4790 [dev.go2go] go/go2go: instantiate local type specs
Fixes #39741

Change-Id: I75e3b98afa5184b87d4a7bbf360761e5cc6c6217
Reviewed-on: https://go-review.googlesource.com/c/go/+/239297
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 17:38:38 +00:00
Ian Lance Taylor ccaf3f5560 [dev.go2go] go/go2go: don't crash on an unnamed receiver
Fixes #39707

Change-Id: I20e5fe2990ceda5429f1a22edf48494d2c6496a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/239159
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-20 00:36:20 +00:00
Ian Lance Taylor 657803033f [dev.go2go] go/go2go: handle fields promoted through embedded type parameter
Fixes #39678

Change-Id: Ib74d15795ab85ad0b1e58096302a9a88810242c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/238857
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18 23:28:46 +00:00
Ian Lance Taylor 20dbf4d49d [dev.go2go] go/go2go: add imports for packages referenced by inferred types
Fixes #39625

Change-Id: Iebae2afbb42092e14c91c52d2046bc287d423844
Reviewed-on: https://go-review.googlesource.com/c/go/+/238817
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18 22:00:57 +00:00
Ian Lance Taylor 4af4810e15 [dev.go2go] go/go2go: add type arguments to type instantiation
Previously we instantiated the underlying type, so we didn't need this.
We stopped doing that to get the same type in the generated code,
but now we need to get the right type arguments, rather than just
leaving the type parameters there.

Fixes #39692

Change-Id: I56ba8ff017c37219e7cb9bb6e07a4beb8c50e9dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/238797
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18 21:36:57 +00:00
Ian Lance Taylor 7a16d6c119 [dev.go2go] go/go2go: don't crash on functions/methods with no body
Fixes #39672

Change-Id: Ia9fa4e7d5090200d7c2b4f654ac7ee42d7d79732
Reviewed-on: https://go-review.googlesource.com/c/go/+/238761
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18 20:51:39 +00:00
Ian Lance Taylor 57cec2f259 [dev.go2go] go/go2go: accept slash in an instantiated type name
It shows up when instantiating with types with a package path
containing a slash, as in net/url.Error.

Fixes #39642

Change-Id: Icf40e7bcdf1de7c84f58ebde35ebffadbb071d72
Reviewed-on: https://go-review.googlesource.com/c/go/+/238623
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 23:45:00 +00:00
Ian Lance Taylor e531e11b9a [dev.go2go] go/go2go: return quickly from typeWithoutArgs if no args
Avoids crashing when we see a universe scope type in an instantiated type.

Change-Id: Iec3ebee291973180a63cd4cddef7e2f131a30053
Reviewed-on: https://go-review.googlesource.com/c/go/+/238622
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 23:34:10 +00:00
Ian Lance Taylor 9840dbbef8 [dev.go2go] go/go2go: instantiate embedded type parameters
Turn an embedded type parameter into a regular field with the type
parameter as the name and the type argument as the type.

Fixes #39671

Change-Id: I0050499b90feb5085cac4452d53fa0dc6f614c48
Reviewed-on: https://go-review.googlesource.com/c/go/+/238621
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 23:21:31 +00:00
Ian Lance Taylor 143b944192 [dev.go2go] go/go2go: error, not panic, for local parameterized type
Fixes #39643

Change-Id: I45aaaf8818d4d383d1514891b5cc9bc68926ad97
Reviewed-on: https://go-review.googlesource.com/c/go/+/238619
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 22:03:14 +00:00
Ian Lance Taylor e0d5d9f770 [dev.go2go] go/go2go: make uses of typeInstantiations consistent
Fixes #39653

Change-Id: I98fd1bd4f0deccb5b4c2ed0d67d508c7f0117839
Reviewed-on: https://go-review.googlesource.com/c/go/+/238618
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 21:53:37 +00:00
Ian Lance Taylor 3a25e98917 [dev.go2go] go/go2go: parenthesize type strings
Fixes #39662

Change-Id: Id176ec00474d66a24e95f2db092f3b4245a93cfb
Reviewed-on: https://go-review.googlesource.com/c/go/+/238557
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 19:42:47 +00:00
Ian Lance Taylor 5f01333bf1 [dev.go2go] go/go2go: check for embedded interface with type list
Add an accessor to go/types: HasTypeList for an interface type.

Fixes #39626

Change-Id: I880eabbe6660739cd7febc1df89eaa7f9262c8c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/238360
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 04:20:54 +00:00
Ian Lance Taylor 1bcef8724f [dev.go2go] go/go2go: catch more embedded comparable cases
Check for comparable embedded via a different embedded interface.
Check for comparable embedded in a defined interface type.

Change-Id: I8c9c576ad31443dcb77b4be71e29ab2284339cb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/238357
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 03:29:48 +00:00
Ian Lance Taylor 4ba19b0188 [dev.go2go] go/go2go: if an interface embeds comparable, treat it as parameterized
Change-Id: If61c88ae115bc14ae306653e78e3241380ab936a
Reviewed-on: https://go-review.googlesource.com/c/go/+/238301
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 00:44:16 +00:00
Ian Lance Taylor 197db4cd00 go/go2go: use types.RelativeTo rather than doing it by hand
Change-Id: I0891f034ef71311df007bb9aa527132d5b45c672
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/771559
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-15 20:51:13 +00:00
Ian Lance Taylor bc77b007e5 go/go2go: compare arguments of instantiated types
types.Identical will report that two instantiated types are different
even if they are instantiated with the same type arguments.
Change our comparison so that we treat them as the same.

This lets us drop fully resolving all types, which is good because
that wasn't correct anyhow.

Change-Id: Ibcf2dc08896ecacb11ca302627e5d0c6f0722da7
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/769080
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor 94ebaa9b4f go/go2go: support instantiating functions with directed channels
Change-Id: I5c7cf605862bc4d34e0eb2b72870c68014d2f58a
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/768851
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor 09a02162ee test: add a couple of pointer method test cases
Change-Id: If91c8a61fcda93eeb5affe51ef8f537736a28bce
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/768839
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor 730419578e go/go2go: handle references to embedded instantiated types
Change-Id: I4f54a7820483e6b79169d319301943063a26ac53
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/767868
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor 3df5cb5c52 go/go2go: improve handling of self-referential types
Also, resolve types when looking up instantiations.

Change-Id: I8b2e976d9c0d313fe3c1dd9dafce41dcb59b33bf
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/767864
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor 73c4e1f380 test: add AbsDifference test case from design draft
Change-Id: I184ca0949200064947a3c974f8aa9c3738d93e33
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/765523
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor 35eefe6b79 test/gen: add some FromStrings test cases
These are from the latest version of the design draft.

There are still a couple of FromStrings test cases that don't yet work.

Change-Id: I057875820d8250012c06faeabda4637f0585b6f8
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/763941
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor db04e7cb2e go/go2go, cmd/go2go, test: rewrite example code to not use contracts
Don't emit interfaces that are type bounds in the generated .go file.

Change-Id: I9b0fd2f6041e9464147ad6d82d349fe894ea762d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/735474
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00