Commit Graph

44435 Commits

Author SHA1 Message Date
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
Robert Griesemer da7932368b [dev.go2go] go/types: implement a few more predicates for type list sums
Also: Don't convert an untyped nil to a type parameter when
checking if an untyped value (nil) can be coverted to a target
type.

Fixes #39755.

Change-Id: Ib2645759dc659b9c80c2d0a457180eb9616c7cb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/239338
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-22 19:06:44 +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
Robert Griesemer 0a030888da [dev.go2go] go/types: use the underlying type of type list entries
Type lists can contain defined types, make sure we use their
underlying types when computing operational types.

Change-Id: I8b6b11302f6b28977916e495f1486cc7b352e859
Reviewed-on: https://go-review.googlesource.com/c/go/+/239163
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-20 04:46:40 +00:00
Robert Griesemer c0c872e8b0 [dev.go2go] go/types: the underlying type of a type parameter is itself
No need to call Under() when we know that we have a type parameter.

While at it: Turn off debug mode.

Change-Id: Ia0b39d88191c8e5ac580e7e84a512061911c40cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/239162
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-20 03:57:21 +00:00
Robert Griesemer cbdb93d5a7 [dev.go2go] go/types: a type constraint must be an interface
In particular, it cannot be a type parameter
with an operational type that is an interface.

Fixes #39723.

Change-Id: Ia6b65eaecd472dd71b1c9f7631ce1872f06e5a6d
Reviewed-on: https://go-review.googlesource.com/c/go/+/239161
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-20 03:49:15 +00:00
Ian Lance Taylor 815b29d859 [dev.go2go] go/go2go: get package name from package, not import path
No test because the test framework doesn't easily support
package paths containing a dot.

Fixes #39722

Change-Id: If43dc768b28f521d10bd2ef4288aa789aa4bee01
Reviewed-on: https://go-review.googlesource.com/c/go/+/239160
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-20 00:45:10 +00:00
Robert Griesemer 7473c4383e [dev.go2go] go/types: check for duplicate types after interfaces were completed
Fixes #39711.

Change-Id: Id0efb854a42bd88a66be8165fa3444e33d1c8f8d
Reviewed-on: https://go-review.googlesource.com/c/go/+/239158
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-20 00:41:07 +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 cab5f803e8 [dev.go2go] go/go2go: don't drop type arguments in instantiateType
It's not correct to do it here, as we aren't instantiating this
particular type.

Also had a loop check to avoid endless instantiating a recursive type.

Fixes #39688

Change-Id: Ief4c57bb5cea3013501e33ab5bc82a29707af5be
Reviewed-on: https://go-review.googlesource.com/c/go/+/239137
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-20 00:01:12 +00:00
Robert Griesemer 6cf535a27b [dev.go2go] go/types: avoid endless recursion when computing operational types
The operational type for a type parameter T constrained by
interface { type T } is the top type, not itself. The latter
can lead to infinite recursions.

Fix suggested by @tdakkota.

Fixes #39680.

Change-Id: I8a6a6c503f09294b9276965f1d9e05c5d22ec912
Reviewed-on: https://go-review.googlesource.com/c/go/+/238863
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-19 04:37:09 +00:00
Robert Griesemer b302b5f775 [dev.go2go] go/types: don't panic if an embedded type is not an interface
Fixes #39693.

Change-Id: I7f2a4dd95edac3365a9b41b66afcd0015b5b836c
Reviewed-on: https://go-review.googlesource.com/c/go/+/238858
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-19 00:09:12 +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
Robert Griesemer 5e754162cd [dev.go2go] go/types: fix unification issue when looking up generic methods
If enabled in types.Config, the type checker can handle generic
methods (methods that have their own type parameter list).
This CL fixes an issue with method lookup (missing method test)
that caused some assignments to fail.

Note that this does not affect the go2go tool - we don't have any
plans to support such generic methods. Type-checking them is
fairly straight-forward. Translating them into code is not.

Change-Id: I8b8a6b814417277c728732bd5a9421c99440a47a
Reviewed-on: https://go-review.googlesource.com/c/go/+/238627
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-18 05:58:40 +00:00
Robert Griesemer 2c4c09e4ff [dev.go2go] go/types: don't crash when receiver type doesn't declare type parameters
Fixes #39664.

Change-Id: I0cf585f0c704bdaa163a7ebc9e7c82a734fcd5e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/238625
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-18 00:39:33 +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
Ahmed W 3f40f78cab README.go2go: add a note about GO2PATH
Adds a little note about `GO2PATH` and that it is required for the `go2go` tool.

Updates #39617

Change-Id: I9e3cea16a7d7539555180dc065957d6a56f390b9
GitHub-Last-Rev: 2aa6815df7
GitHub-Pull-Request: golang/go#39657
Reviewed-on: https://go-review.googlesource.com/c/go/+/238498
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 22:48:43 +00:00
Ian Lance Taylor 4287a49936 [dev.go2go] cmd/go2go: document that function-local parameterized types don't work
For #39643

Change-Id: Ic3d3e4a4bd46c62705d3ce3473e3e06e1380d834
Reviewed-on: https://go-review.googlesource.com/c/go/+/238620
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 22:05:55 +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
Robert Griesemer 0b89d8b52a [dev.go2go] go/types: use correct predicate when checking binary addition
See also https://team-review.git.corp.google.com/c/golang/go2-dev/+/759562
for the analogous problem for another predicate.

Fixes #39623.

Change-Id: I39efcb07c337691eb202de166e2cb8d6b5d5ee18
Reviewed-on: https://go-review.googlesource.com/c/go/+/238359
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-17 03:59:45 +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
Robert Griesemer c2b328710b [dev.go2go] go/types: prevent comparable interface from being used outside constraints
It was already not possible to implement an interface that was or
embedded the predeclared interface "comparable" in ordinary (non-
constraint) use, but trying to do so would lead to confusing errors
(missing method "==").

Simply disallow the use of such interfaces outside constraints,
as we do for interfaces containing type lists.

Change-Id: I15ccf1b77226a50baf16df46192e90144208f9dd
Reviewed-on: https://go-review.googlesource.com/c/go/+/238300
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-17 02:11:25 +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 56a37ac5a4 [dev.go2go] go/go2go: make defaultImporter a field of Importer
It turns out that defaultImporter has modifiable fields, so making it a
package scope variable can cause confusion in the use by test/run.go.

Change-Id: I33b060f2ffd17639312e7aa15a632268a3c14ab1
Reviewed-on: https://go-review.googlesource.com/c/go/+/238299
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 00:36:21 +00:00
Robert Griesemer 45038b7bca [dev.go2go] README.go2go.md: fix typo
Change-Id: Iee71ea7af488a717986d2e5994f16fdeaf8f3dda
Reviewed-on: https://go-review.googlesource.com/c/go/+/238297
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-16 23:13:12 +00:00
Robert Griesemer ad307489d4 go/types: always use the underlying type of type list entries for operations
Passes all.bash.

Change-Id: Ie31cba04b7147fb1468f90d26450034223745a57
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/771577
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-16 05:49:35 +00:00
Robert Griesemer 84cbe4f953 go/types: allow any type in a type list
Since we have to recompute the underlying type of each type in a
type list after instantiation (if any), there is no need to restrict
the types in the type list anymore.

Per the adjustment in the design draft.

Change-Id: I51ced90788e06ed4a9dbd34566e3baca7f3afe20
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/771574
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-16 03:41:38 +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 feeeea1cda README.go2go: add README for branch
Change-Id: I92d9feb0c382a160afbff2428d92487e2275e09f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/771427
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-15 20:07:34 +00:00
Robert Griesemer 221a28e338 go/types: always compare against underlying types in type lists
The underlying type of each type list entry must be computed
(again) _after_ the interface was instantiated because its
original typelist may have contained type parameters that were
substituted with defined types.

Passes all.bash.

Change-Id: I65a234fe6b9bc7b36121532410a0ecc29061516e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/770445
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-14 06:40:04 +00:00
Robert Griesemer 8d612e39fe go/types: fix a couple of trace output problems (when -v is set)
- fix endless recursion when caused by trace output for self-referential generic types
- print pointer designation of type parameters in type parameter lists

Change-Id: I02d985187ee5e42fdaece2e7420824de8c90a906
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/770152
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:54 -07:00
Robert Griesemer 795f776602 go/types: stronger type inference across defined types
If a defined type is passed as an argument for a paramater
of a composite generic but unnamed type (and vice versa),
use the defined type's underlying type for type inference
rather than fail.

Passes all.bash.

Change-Id: I90b33b549c1d0e7569c1520b0f8e45a67152df43
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/770149
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor e7b04c5e2d go/go2go: add check for looping while rewriting
Change-Id: I2dacc606e9aecf8616eff2e9ab9fc09af69b7767
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/769752
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:54 -07:00
Robert Griesemer bbdb05760f go/types: a type parameter acts like a named type; fix predicate and test
Change-Id: Ibe9f074d516200b9b12c26a270e62defc024eeac
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/769347
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:54 -07: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
Robert Griesemer cf52fda189 go/types: update README
Change-Id: If0031161b0c651d9196ebb7e565dfb8b8c7e664f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/768852
Reviewed-by: Robert Griesemer <gri@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