Commit Graph

44503 Commits

Author SHA1 Message Date
Robert Griesemer deb678cebf [dev.go2go] go/types: add testcase for crash 9 of #39634
This test passes type-checking without problems but the
generated code causes a cmd/compile error (filed #40486).

Updates #39634.

Change-Id: If3dd28605f6d8792c6bd5bb032624e9a6140b2c0
Reviewed-on: https://go-review.googlesource.com/c/go/+/245742
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 04:50:09 +00:00
Robert Griesemer 15144bdc72 [dev.go2go] go/types: fix isParameterized predicate
When checking if a type is parameterized, we only care about
type parameters bound to the specific type, not "free" type
parameters. The old code simply looked for "any" type parameter.

Change-Id: I6a3fe5ac7e3150c5796d4b7576682ab3d4b8558f
Reviewed-on: https://go-review.googlesource.com/c/go/+/245741
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 04:50:01 +00:00
Robert Griesemer 88496095d2 [dev.go2go] go/types: remove incorrect assert and replace with explanatory comment
Addresses crash 26 of #39634.
Also, added test case for crash 25 which was fixed with
https://golang.org/cl/245739.

Updates #39634.

Change-Id: I19793eb79fce63052ba055cde0b1dafdd9476895
Reviewed-on: https://go-review.googlesource.com/c/go/+/245740
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 04:00:56 +00:00
Robert Griesemer f0e6640956 [dev.go2go] go/types: generic types in selector expressions must be instantiated
Addresses crash 24 of #39634.

Updates #39634.

Change-Id: If44e834834a07719e7f727d12cc24ac4af0997e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/245739
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 00:57:09 +00:00
Robert Griesemer 0db4da527f [dev.go2go] go/types: don't crash in assignment due to prior errors
Addresses crash #12 of 39634.

Updates #39634.

Change-Id: Ie67545d21b6a1e80fcdec1b2eb101b69c25e2952
Reviewed-on: https://go-review.googlesource.com/c/go/+/245738
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 00:27:38 +00:00
Robert Griesemer d118bf7ce9 [dev.go2go] go/types: don't crash in lookup of incomplete interface
Also, update some comments.

Updates #39634.

Change-Id: I85c63e4b941e2bc04e8b5a59497fc47e5d578b8b
Reviewed-on: https://go-review.googlesource.com/c/go/+/245737
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 00:10:38 +00:00
Robert Griesemer df58427917 [dev.go2go] go/types: remove need to enumerate test files, clean up test handling
- Reorganize testdata directory to either contain single-file packages
or (one level of) sub-directories containing multi-file packages.

- Add TestTestdata that runs all the tests in testdata.

- Change TestCheck to only test files explicitly provided via -files.

Providing -v when running these tests now enumerates the packages.
For TestCheck it also prints the type-checking trace.

Change-Id: I66536881789234af030a0a2c9fc096822f593782
Reviewed-on: https://go-review.googlesource.com/c/go/+/244629
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 22:57:29 +00:00
Robert Griesemer 131fbfb416 [dev.go2go] go/types: remove need to enumerate examples and fixedbugs test files
Just traverse the respective directories.

Change-Id: I21432e23550d8331e61d3392e8488c81183ab6f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/244628
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 20:13:27 +00:00
Robert Griesemer edac449852 [dev.go2go] go/types: clean up test support code and remove global variables
Change-Id: I152d2f4ca95f8217502d796ac49a8c96e5aba60b
Reviewed-on: https://go-review.googlesource.com/c/go/+/244627
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 19:40:13 +00:00
Robert Griesemer d0e6f20899 [dev.go2go] go/parser: make "type" optional in generic type declarations
Experiment: Make "type" keyword optional in generic type declarations when
it is clear that we can't have an array type declaration. This is the case
when we have one the following:

- more than one type parameter
- a type parameter with a constraint
- a trailing comma in the type parameter list

Change-Id: If6c473ba93b993a7c15ff2f7e7302709cc985f9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/244623
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 18:10:25 +00:00
Robert Griesemer fad691cf11 [dev.go2go] go/types: don't crash with unsafe.Alignof/Sizeof on a type parameter value
Report an error instead for now until we have a better idea.
(It's unclear what these operations should do as they are
defined to return a compile-time constant which we can't
know in general.)

Fixes #40301.

Change-Id: I22a991311de117bc00d52b67b4ce862ea09d855a
Reviewed-on: https://go-review.googlesource.com/c/go/+/244622
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 00:25:37 +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
Robert Griesemer 0030e13efb [dev.go2go] go/types: add a couple more interesting type inference examples
Change-Id: I28b31e013ae28a71adefb07cce0f47b505b57676
Reviewed-on: https://go-review.googlesource.com/c/go/+/244620
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-23 21:52:06 +00:00
Robert Griesemer de8501c203 [dev.go2go] go/parser: change value of UseBrackets constant (fix API check)
Passes all.bash again.

Change-Id: Ie558957b380cef937761faea69458980407bc8db
Reviewed-on: https://go-review.googlesource.com/c/go/+/244619
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-23 21:19:31 +00:00
Robert Griesemer c7314f27b3 [dev.go2go] go/*: remove the need for ast.InstantiatedType
Instead, add the field "Brackets" to ast.CallExpr to identify
the bracket used for the (type) parameters. Adjust dependencies.

Change-Id: I6a73b0517ac518d8055e7fadbfb8662dfff585c1
Reviewed-on: https://go-review.googlesource.com/c/go/+/244618
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-23 21:19:13 +00:00
Robert Griesemer bed4b05106 [dev.go2go] go/types: implement constraint type inference for functions
1) Implement full bidirectional unification for general use.
2) Implement constraint type inference using bidirectional unification.
3) Add flag Config.InferFromConstraints to enable constraint type
   inference (disabled by default).

If we don't have all type arguments (provided or inferred) for a
function call, constraint type inference attempts to infer them
from type parameter constraints that are "structural", i.e., whose
interfaces contain exactly one (non-interface) type in their type
lists. For instance, given

	[type P interface{}, Q interface{type []P}]

the constraint for Q requires that the (underlying) structure of
the type argument for Q must match the underlying type of the type
argument provided for P. If only a type argument for P is given, say
say int, we can infer a type argument for Q, which would be []int.

Change-Id: I8508412ad96a0969d2033e99510c56db0f78177e
Reviewed-on: https://go-review.googlesource.com/c/go/+/244061
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-23 06:04:12 +00:00
Robert Griesemer 1576a3d981 [dev.go2go] go/parser: recognize f[a, b] as a (potential) function expression (parser bug)
Change-Id: I6b631a0d7efedfedd6c67640c8cbbff81f9e3af8
Reviewed-on: https://go-review.googlesource.com/c/go/+/244457
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-22 23:57:39 +00:00
Rebecca Stambler f41e3f6173 [dev.go2go] go/ast: add *ast.InstantiatedType case to go/ast.Walk
This is necessary for continued support for the prototype in gopls.

Fixes golang/go#40316

Change-Id: Iafab2e78cfdfd7415d2e2419b8ed1abe6e6216c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/243717
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2020-07-20 22:53:49 +00:00
Ian Lance Taylor 893c5ec17b [dev.go2go] cmd/go2go: rewrite tests to use square bracket syntax
We can roll back this CL if we go back to parentheses.

Change-Id: Ide85330f4c362dad6ae964c6cc1fd0fc6c8a6a60
Reviewed-on: https://go-review.googlesource.com/c/go/+/243162
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-16 21:30:46 +00:00
Ian Lance Taylor 486b592393 [dev.go2go] cmd/go2go: add -brackets option
Change-Id: I5c3d36df3d84ad85d2fb70152f5692223cf6cfb6
Reviewed-on: https://go-review.googlesource.com/c/go/+/243161
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-16 21:28:54 +00:00
Ian Lance Taylor 78c55f923e [dev.go2go] go/go2go: permit caller to require square brackets
Change-Id: Idcb18ea31edee61931aa253f5f4d95923f6bcf6c
Reviewed-on: https://go-review.googlesource.com/c/go/+/243160
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-16 21:24:39 +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 6f583c9a5a [dev.go2go] go/go2go: support square bracket generics syntax
Change-Id: If683ad350aaddebcb3ebb691e1235c24c5dc2fe9
Reviewed-on: https://go-review.googlesource.com/c/go/+/243157
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-16 20:16:37 +00:00
Robert Griesemer e8f7e323f3 [dev.go2go] go/parser: UseBrackets mode forces parser to use [] for generics
Not setting the UseBracket mode still permits the parser to switch
to using brackets depending on the first generic type or function
declaration.

Change-Id: I2ee1235cfe58108ce1f5fd4a7fa1ce81f9e0ec0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/242904
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-16 20:02:53 +00:00
Robert Griesemer a1922594db [dev.go2go] go/parser, go/types: allow both type and func decls to select [] for type params
The first generic type or function declaration encountered in a file chosing
square brackets switches the parser to use square brackets for the remainder of
the file.

Removed the need for extra type declarations in tests solely to switch to [].

Change-Id: Ia8d0c16e69b7e9b0e5397fed7405c5c4afc66451
Reviewed-on: https://go-review.googlesource.com/c/go/+/242899
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-16 00:33:55 +00:00
Robert Griesemer ee1823718a [dev.go2go] go/parser: optional "type" keyword for generic functions using [] (experiment)
Change-Id: Ib7ebcd97f970e3be09626ee3d58d110e531aecd8
Reviewed-on: https://go-review.googlesource.com/c/go/+/242897
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-15 23:08:25 +00:00
Robert Griesemer 42aea19e55 [dev.go2go] go/printer: initial support for []-enclosed type parameters
Also: Don't strip parentheses around unnamed generic parameter
types when () are used for type instantiations (was bug).

Change-Id: I74edde2be2a01d740d2275e5d8768a5c25fa3302
Reviewed-on: https://go-review.googlesource.com/c/go/+/242717
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-15 05:33:40 +00:00
Robert Griesemer 7e7a795836 [dev.go2go] go/types: adjustments to accept [] or () for type parameters
For each testfile xxx.go2, added a corresponding file xxxB.go2
that is using [] instead of () for type parameters. Removed
extra ()'s that are not needed to disambiguate.

See also https://groups.google.com/g/golang-nuts/c/7t-Q2vt60J8

Change-Id: I3d64035b1ca2a22ae50c740ebf4ab8a8f6cab787
Reviewed-on: https://go-review.googlesource.com/c/go/+/242521
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-15 00:53:18 +00:00
Robert Griesemer 5bf3aa1e25 [dev.go2go] go/parser, go/ast: accept [] or () for type parameters
- The first type declaration using [] for type parameters
  switches the parser to using [] for type parameters and
  type instantiations. Otherwise it uses ().

- Type parameters are now always accepted with any function
  or method declaration. It is up to the consumer of the AST
  to reject them as necessary.

- Type parameters are now never accepted in the receiver
  or result parameter list.

- testdata/xxxB.go2 tests correspond to the testdata/xxx.go2
  tests but use [] instead of ().

- See also https://groups.google.com/g/golang-nuts/c/7t-Q2vt60J8

Change-Id: I21b14f9463f7f49deba83b64450a0723b4b1d171
Reviewed-on: https://go-review.googlesource.com/c/go/+/242520
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-15 00:52:51 +00:00
Robert Griesemer 9fe9a324c4 [dev.go2go] go/*: remove vestiges of contracts - they are not coming back
Change-Id: If929860b51b86206d874b49ac00aaa8df09726e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/241657
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-09 00:23:26 +00:00
Ian Lance Taylor 9d9619adc8 [dev.go2go] go/go2go: pass full path when importing Go 1 package
No test case because there is still no test harness for a complex
package heirarchy.

Fixes #40063

Change-Id: Iebe627dd7b2a3e967d437bee61c9d15c7a159fc6
Reviewed-on: https://go-review.googlesource.com/c/go/+/241217
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-07 03:47:15 +00:00
Robert Griesemer 4545287c1b [dev.go2go] go/types: don't panic if receiver type arguments cannot be inferred
This can happen due to earlier errors. This change avoids the panic
but reports a follow-up error. Not ideal, but good enough for now.

Fixes #40056.

Change-Id: I500d4fc2b058cdc70f28883ff8d004df4b43fe4e
Reviewed-on: https://go-review.googlesource.com/c/go/+/241130
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-07 03:13:21 +00:00
Robert Griesemer 17564d8957 [dev.go2go] go/types: do not permit generic types in type switch type lists
Fixes #40057.

Change-Id: Ia1a99378614fda1d0cb3d6b9cf53bbf790fc2953
Reviewed-on: https://go-review.googlesource.com/c/go/+/241126
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-07 00:22:28 +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
Robert Griesemer c583a5d512 [dev.go2go] go/types: add test for crash 15 from issue 39634
This test case doesn't crash anymore.

Updates #39634.

Change-Id: I29b13762265ef1c16c0298d141fdb6cf2c01f4ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/241123
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-06 22:08:08 +00:00
Robert Griesemer a599706090 [dev.go2go] go/types: don't crash instantiating defined types that are not fully set up
Addresses crash #16 of #39634.

Updates #39634.

Change-Id: I33063d6e2176586f097d2d1391f490f1775a2202
Reviewed-on: https://go-review.googlesource.com/c/go/+/241122
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-06 22:00:41 +00:00
Robert Griesemer 005397e36d [dev.go2go] go/types: don't crash instantiating arrays/slices that are not fully set up
Addresses crash #18 of #39634.

Updates #39634.

Change-Id: I4b1a3d81ce9dc2b59ae9af3146d26f79d8c05973
Reviewed-on: https://go-review.googlesource.com/c/go/+/240904
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-06 21:54:48 +00:00
Pavlo Bashynskyi 0e1fc80d04 [dev.go2go] cmd/go2go: correct URL in README
Change-Id: I947c0181512b7d5dd4219cec92262bd1f443b957
GitHub-Last-Rev: 44ec636b89
GitHub-Pull-Request: golang/go#40054
Reviewed-on: https://go-review.googlesource.com/c/go/+/241039
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-05 19:48:30 +00:00
Robert Griesemer 34f76220c3 [dev.go2go] go/types: make sure arrays, slices always have an element type
Addresses crash #19 of #39634.

Updates #39634.

Change-Id: I42208511a3fc27432891243dcf4799e80432c2c1
Reviewed-on: https://go-review.googlesource.com/c/go/+/240903
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-04 04:55:49 +00:00
Robert Griesemer 6e86f51c54 [dev.go2go] go/types: don't rely on completed interfaces in isParameterized predicate
Also, take type lists into account when computing predicate.
Addresses crash #27 of #39634.

Updates #39634.

Change-Id: Id6e1d0d86ac1cb9d79828a3b5fdfbeba0e6aace0
Reviewed-on: https://go-review.googlesource.com/c/go/+/240902
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-03 22:37:04 +00:00
Robert Griesemer 167909e5f5 [dev.go2go] go/types: don't modify Named.underlying when checking validity
Addresses crash #20 of #39634.
Added test, also for some of the other cases that don't crash
anymore.

Updates #39634.

Change-Id: I999e376985a443ac435f64a7c249f891e7b7a6d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/240901
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-03 22:20:59 +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
Robert Griesemer 85ed317eb2 [dev.go2go] go/types: fix computation of type hash
Fixes #39982.

Change-Id: I4e7b52c34bf8df63f2063dc2504a8125ca7585a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/240737
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-02 00:33:43 +00:00
Robert Griesemer 182889ccf5 [dev.go2go] go/types: better error message when converting to a constraint interface
Fixes #39699.

Change-Id: Ib2a756a275c0f96201800d947a72db49d3319a3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/240720
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-01 22:50:35 +00:00
Robert Griesemer 05f750de93 [dev.go2go] go/types: HasTypeList, IsComparable, IsConstraint predicates for interfaces
HasTypeList existed before but now is also written such that it doesn't
expect an interface to be complete.

Change-Id: I43e8d652c6be755473b201a64bf41d363214881c
Reviewed-on: https://go-review.googlesource.com/c/go/+/240719
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-01 22:50:26 +00:00
Robert Griesemer d014fca6d4 [dev.go2go] go/types: fix assertion failure, better error message for inference failure
Fixes #39976.

Change-Id: Idc304a615193847337438e7024e43140472e7bae
Reviewed-on: https://go-review.googlesource.com/c/go/+/240718
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-01 20:30:10 +00:00
Robert Griesemer 6cf6bf162c [dev.go2go] go/types: report inferred type when a type argument doesn't match
Fixes #39725.

Change-Id: I48248283ae0eb635d489d8661512f32b98700c1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/240523
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-01 00:31: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
Robert Griesemer 08b9fd164c [dev.go2go] go/types: better error message when confusing a type parameter with an interface
Fixes #39948.

Change-Id: I868d2264a674a92c39fbe31d89bc002dd74c26fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/240520
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-30 19:00:27 +00:00