Commit Graph

44128 Commits

Author SHA1 Message Date
Robert Griesemer fbff5cc915 go/types: fix collection of receiver type parameters
... and various related smaller fixes

We can now type-check the slices, chans, and maps
examples from the design doc (with the maps example
prodcing an error because importing chans doesn't
work yet). Progress!

Change-Id: Ifc00359a9a1cdad3bde1659a7de2028ac2544469
2020-06-13 12:02:26 -07:00
Robert Griesemer 3c6943daac go/types: more work on checking contract satisfaction
Change-Id: Ibe54e448603c685d714310ff83d4193150d47ebd
2020-06-13 12:02:26 -07:00
Robert Griesemer b87cfd9558 go/types: more steps towards contract type checking
- moved type parameter collection out of resolver and into decl phase
- collect (meta-) type information (contracts) for type parameters
- first cut at checking contract satisfaction (methods only for now)

Change-Id: I46707969a172423738171aaea9d5282fb4b25a44
2020-06-13 12:02:26 -07:00
Robert Griesemer 590e4ea3f0 go/types: re-enable initial contract type checking
- collect contract methods in respective interfaces
- basic checking on contract type constraints

Contracts are not yet tested against or used to type check
function bodies.

Change-Id: I13b00c44524e599f92f1ba5b4b5d6734e2bf22e1
2020-06-13 12:02:26 -07:00
Robert Griesemer 628e3a2c6f go/printer: first steps towards printing type parameters and contracts
- type parameters can be printed
- empty contracts can be printed
- contract constraints are missing (only started)

Change-Id: I787898203aeb064b0b2ac49a7b858313cee5f45b
2020-06-13 12:02:26 -07:00
Robert Griesemer a65d9b58a9 go/types: fix type inference bugs for untyped arguments
Change-Id: Ic98be8b102521090108d288514ee2cf016a7bb46
2020-06-13 12:02:26 -07:00
Robert Griesemer d03ba9f74c go/types: fix a type instantiation issue, added slices.go2 example
Change-Id: If020572762039adf10973bccd072005084e17e4e
2020-06-13 12:02:26 -07:00
Robert Griesemer c4a20af9f1 go/types: incorporate last-minute changes added for GopherCon
Change-Id: I8e1ff18f073ca47ef1a5d8ea43c8b6a3bc4d27b8
2020-06-13 12:02:26 -07:00
Robert Griesemer d4272d0350 go/types: add examples/contracts.go2, extended examples/functions.go2
Change-Id: Icb1c0dfc6e752598a51d8039b5df77cde9a115ca
2020-06-13 12:02:26 -07:00
Robert Griesemer 0f7748af30 go/types: add examples directory
Also: fix substitution for cyclic types

Change-Id: I2d4eca6846c1ac9a2b4d0278246228e1f61aea08
2020-06-13 12:02:25 -07:00
Robert Griesemer 025f8ad924 go/types: add README describing the state of this prototype
Change-Id: I9c994be7600ed969064cf49e8edcbe431f1b7242
2020-06-13 12:02:25 -07:00
Robert Griesemer e2ccf6356b go/types: initial steps towards customizing method signatures
Needs more work and tests.

Change-Id: Ic54e5798c374254d55b46cb582d7cf87efe125d1
2020-06-13 12:02:25 -07:00
Robert Griesemer 3663c91f3a go/types: unpack parameterized method receivers
Also: Print debug trace when running tests and -v is set.

Change-Id: I741377f82845d4713eebeb26706cb47b55afebd3
2020-06-13 12:02:25 -07:00
Robert Griesemer be88be6e7a go/types: steps towards type-checking of methods with parameterized receivers
Change-Id: I80b4d4c248cb5e29933366322cca1d76c3ed5e23
2020-06-13 12:02:25 -07:00
Robert Griesemer 0ffe62a473 go/types: more fixes around parameterized types
Change-Id: I81e6e70a2833e7dbb17f5155386ed3c7a75dc2ac
2020-06-13 12:02:25 -07:00
Robert Griesemer d5d25288d4 go/types: remove typemap again (incomplete and currently not used)
Change-Id: If7483716b2ea7f66ef9fe5311ce000a3b6212524
2020-06-13 12:02:25 -07:00
Robert Griesemer 38fa8c1e9b go/types: fix instantiated type name computation (for now)
This needs more work eventually.

Change-Id: I33fce18c454113620df9bb1db71a60b38b0a1306
2020-06-13 12:02:25 -07:00
Robert Griesemer de712f2df8 go/types: implemented comparison of parameterized types; minor bug fixes
Also: Added -h flag to test framework; setting -h causes a panic when
an error is reported (for debugging).

Change-Id: Ib45d4ef38769f2ecdd3ce53fa3aed9fd99ef6bc8
2020-06-13 12:02:25 -07:00
Robert Griesemer 06ce58509d go/types: cleaned up parameterized type code a bit; enabled more tests
Change-Id: I579239f30f26e8a483c6f5dc379124d8a9eb4576
2020-06-13 12:02:25 -07:00
Robert Griesemer 2a76603101 go/types: fixed various issues in check.subst
Next known issue:

type List(type E) []E
var _ List(List(List(int))) = [](List(List(int))){}

This won't work because the RHS's composite literal type
is not fully instantiated - it has non-instantiated elements
which are ignored by Checker.instantiatedType. We could just
call Checker.subst w/o any parameters and have it walk the
incoming type and instantiate any element Parameterized types
but that is expensive and also appears to lead to stack over-
flow. Need to investigate.

Change-Id: I80bd09ab5f06e3991f198965424ce3322c7d6402
2020-06-13 12:02:25 -07:00
Robert Griesemer b8b66e1708 go/types: make tests pass again
Disallow parametrized alias types again. They need a bit more work.

Change-Id: I90fd101a4c61f8693ee850c5dbd6849a60b85bdc
2020-06-13 12:02:24 -07:00
Robert Griesemer 52934f1b1e go/types: significant steps towards complete parametrized type instantiation
testdata/typeinst2.go has some complex examples that pass now.
But code elsewhere seems broken. go test has some issues at the
moment. Committing anyway to not lose the snapshot.

Change-Id: Id8f753a7b098405e2580a45ca1707ef6476c198e
2020-06-13 12:02:24 -07:00
Robert Griesemer a76283d6e4 go/types: add primitive instantiated type map for canonicalization
Change-Id: I265105d483b6fdcee95f3770b9d6d774c1633638
2020-06-13 12:02:24 -07:00
Robert Griesemer 8142528bfd go/types: correctly substitute types when instantiating parametrized types
- use the right type when instantiating a type
- substitute defined types when underlying types are changing
- improved printing of parametrized types
- improved printing of instantiated types
- more top-level trace output

Change-Id: Ie8a65c9cc51e80925d3f580f54dcc6c0b5abe4c6
2020-06-13 12:02:24 -07:00
Robert Griesemer fac6c330ac go/types: more steps towards type-checking instantiated types
Change-Id: Iab2dab932faad704fc7141f7afe04eb80597ec57
2020-06-13 12:02:24 -07:00
Robert Griesemer e6f3c8a0b4 go/types: add missing test file
Change-Id: I36af54691bf757f78612549283e3eea1358dca0e
2020-06-13 12:02:24 -07:00
Robert Griesemer fa30b485bc go/types: collect function type parameters during resolve phase
- move init and method parameter checks to resolve phase as well
- more consistent error messages
- more tests

Change-Id: I6cb147b35385541ca5d7d7e3f87159df84cced76
2020-06-13 12:02:24 -07:00
Robert Griesemer db132013f4 go/types: collect type parameters of types and set up corresponding scopes
Change-Id: Ie63ffcdb8e3682b75f9863cea7987561772e6809
2020-06-13 12:02:24 -07:00
Robert Griesemer aa0fabb90e go/types: prepare resolver for types with type parameters
Change-Id: If4395181b5683750098aefd5292a00921b3a5427
2020-06-13 12:02:24 -07:00
Robert Griesemer 7d54168ae9 go/types: add initial TypeMap implementation
Eventually we need this to avoid repeated instantiation
of generic types.

Change-Id: Idd9625dadfe67398d91121e73ef806576437a2f6
2020-06-13 12:02:24 -07:00
Robert Griesemer e35f6184bd go/*: accept comma-separated list of types/methods in contracts
Updated go/ast and go/parser. go/types doesn't process the
new data structure yet and is missing a good type representation
of contracts.

Change-Id: I101f7c9e98008840dd1edb55404bb97db5a66ccd
2020-06-13 12:02:23 -07:00
Robert Griesemer 150704f738 go/types: implemented a few TODOs (minor progress) 2020-06-13 12:02:23 -07:00
Robert Griesemer 5ef7be9e7c go/types: more work on type-checking stand-alone contracts
Does not handle contract embedding yet.
2020-06-13 12:02:23 -07:00
Robert Griesemer 48d479685e go/*: added linalg.go2, renamed a couple of Go 2 tests to end in .go2 2020-06-13 12:02:23 -07:00
Robert Griesemer 5541826527 go/types: initial checking of type constraints, factored out contracts code 2020-06-13 12:02:23 -07:00
Robert Griesemer e21d47f346 go/types: first steps toward type-checking individual contracts 2020-06-13 12:02:23 -07:00
Robert Griesemer 66b509a402 go/*: remove ast.TypeParamList in favor of ast.FieldList 2020-06-13 12:02:23 -07:00
Robert Griesemer e3b54c8023 go/*: fix parsing of T(P){...} comp. literals and add .go2 tests
Additionally, simplify the syntax for contracts specified in a
type parameter list: It is now not possible to provide explicit
type parameters to a contract in a type parameter list - they
are always implicit. For instance

	func f(type P1, P2 C(P1, P2)) ...

must be written as

	func f(type P1, P2 C) ...

If a different order or different types are desired for C,
a new "intermediate" contract must be declared, as in

	contract C'(A, B) {
		C(B, int)  // here we allow type parameters
	}

	func f(type P1, P2 C')

This simplification will remove confusion if we decide to
allow individual contracts in type parameter lists, such as

	func f(type P C, P1, P2 C') ...

In this case, C accepts one type parameter (and applies to P),
and C' accepts two type parameters and applies to P1 and P2.

The simplification avoids questions such as whether this code
should be permitted:

	func f(type P C(P2), P1, P2 C'(P, P1)) ...

(i.e., can pass P2 to C, or P1 to C', etc.)
2020-06-13 12:02:23 -07:00
Robert Griesemer 6069527287 go/*: switch back to () parentheses, fill in various missing pieces
This change switches parsing back to using () parentheses for
type parameters. The parser now also accepts contracts in
parametrized type declarations, and top-level declared
contracts as defined in the design draft:

contract C(T1, T2) { ... }

(Internally, they are mapped to an ast.ContractType as before.)

Added more tests, incl. map.go2 from the design draft, and removed
some unused parser functions.

Passes parser and types tests.

Known issue: Composite literals with instantiated composite literal
types are not recognized properly: T(P){...} fails to parse.
2020-06-13 12:02:23 -07:00
Robert Griesemer 869c7a4e29 go/*: experiments with () and [] parentheses
This change implements parsing of contracts based on the
most recent design (using a combination of methods and
explicit basic types as well as the short-hand notations
0, 0.0, 0i, ==, and !=). At the moment, a contract is
considered a "type" and declared as such:

type C contract(T1, T2) { ...}

This change also implements parsing of type instantiations
and type parameters for type declarations, using both the
() parentheses and [] brackets (if the flag useBrackets is
set in parser.go).

Not all parsed data structures are set up correctly in the
AST yet. The parser and ast tests pass.

Change-Id: I11ce64ad49e404c5a66ce6623edc8313e803e135
2020-06-13 12:02:23 -07:00
Robert Griesemer fd16d941dc go/*: type-checking of function type parameters
This change implements parsing and type-checking
of parametrized functions (without contracts).
Type-checking includes checking of generic function
calls using explicit type parameters as well as
implicit type parameters inferred from the actual
arguments.

Change-Id: I03c9c6912aa1e2ac79d9c5125fd5ac72df4e808a
2020-06-13 12:02:22 -07:00
Ainar Garipov bd486c39ba doc/go1.15: add release notes for database/sql and database/sql/driver
Updates #37419.

Change-Id: Ifb6aa9a671f677e1a3e908f0b75bf0da17a57ad0
Reviewed-on: https://go-review.googlesource.com/c/go/+/237397
Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
2020-06-13 16:03:19 +00:00
Ian Lance Taylor b05b254e9d doc/go1.15: sort debug/pe entry alphabetically
For #37419

Change-Id: If98ecffbfd976cb66a87b1cce4e82b3ddee1639e
Reviewed-on: https://go-review.googlesource.com/c/go/+/237738
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-06-12 23:50:08 +00:00
Keith Randall 8dae5390cb runtime: raise alert threshold on window smhasher test
This alert is triggering occasionally. I've investigated the
collisions that happen, and they all seem to be pairwise, so they are
not a big deal.  "pairwise" = when there are 32 collisions, it is two
keys mapping to the same hash, 32 times, not 33 keys all mapping to
the same hash.

Add some t.Logf calls in case this comes back, which will help isolate
the problem.

Fixes #39352

Change-Id: I1749d7c8efd0afcf9024d8964d15bc0f58a86e4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/237718
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-12 20:46:27 +00:00
Meng Zhuo 7d975ae9c0 A+C: change email address for Meng Zhuo
Change-Id: I60965f6193256959055824749ed08ce86f6ba482
Reviewed-on: https://go-review.googlesource.com/c/go/+/237541
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-12 17:25:26 +00:00
Dmitri Shuralyov cc3b303a6f cmd/compile/internal/ssa: skip TestNexting with old Delve on linux/386
Support for linux/386 was added to Delve in version 1.4.1, but the
version of Delve currently installed on the linux-386-longtest
builder is 1.2.0. That isn't new enough, which causes the test
to fail. Skip it on that builder until it can be made to work.

The only reason it used to pass on the linux-386-longtest builder
before is because that builder was misconfigured to run tests for
linux/amd64. This was resolved in CL 234520.

Also improve internal documentation and the text of skip reasons.

Fixes #39309.

Change-Id: I395cb1f076e59dd3a3feb53e1dcdce5101e9a0f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/237603
Reviewed-by: David Chase <drchase@google.com>
2020-06-12 16:44:36 +00:00
Toshihiro Shiino 509ee70642 doc/go1.15: add code tags
Other command line arguments are written in code tags, so add a code tag for consistency.

For #37419

Change-Id: I1948536c3a1860d93726484be2dc7bcb03dfdc2f
Reviewed-on: https://go-review.googlesource.com/c/go/+/237539
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-06-11 22:18:30 +00:00
Toshihiro Shiino 7495a42598 doc/go1.15: replace tab indentation with spaces
Replace tab indentation with spaces for consistency, as all other indentation is done with spaces.

For #37419

Change-Id: I728a75ae0d00e637f57eb455b6039ffc1a5feed2
Reviewed-on: https://go-review.googlesource.com/c/go/+/237538
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-06-11 22:17:59 +00:00
Ian Lance Taylor a5a9a06d71 cmd/cgo: in -godefs mode, don't change constant to type
Fixes #39534

Change-Id: Icbc1745935dd7098c09e2d35c61cd5bfbaa31c63
Reviewed-on: https://go-review.googlesource.com/c/go/+/237558
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-06-11 21:53:45 +00:00
Baokun Lee f7ba82d68f cmd/go/internal/web: don't follow an infinite number of redirects
We replaced http.DefaultClient with securityPreservingHTTPClient,
but we still need that too many redirects check. This issue introduced
by CL 156838.

We introduce a special path to test rediret requests in the script test
framework. You can specify the number of redirects in the path.

	$GOPROXY/redirect/<count>/...

Redirect request sequence details(count=8):

 request:  $GOPROXY/mod/redirect/8/rsc.io/quote/@v/v1.2.0.mod
redirect:  $GOPROXY/mod/redirect/7/rsc.io/quote/@v/v1.2.0.mod
redirect:  $GOPROXY/mod/redirect/6/rsc.io/quote/@v/v1.2.0.mod
redirect:  $GOPROXY/mod/redirect/5/rsc.io/quote/@v/v1.2.0.mod
redirect:  $GOPROXY/mod/redirect/4/rsc.io/quote/@v/v1.2.0.mod
redirect:  $GOPROXY/mod/redirect/3/rsc.io/quote/@v/v1.2.0.mod
redirect:  $GOPROXY/mod/redirect/2/rsc.io/quote/@v/v1.2.0.mod
redirect:  $GOPROXY/mod/redirect/1/rsc.io/quote/@v/v1.2.0.mod
the last:  $GOPROXY/mod/rsc.io/quote/@v/v1.2.0.mod

Fixes #39482

Change-Id: I149a3702b2b616069baeef787b2e4b73afc93b0e
Reviewed-on: https://go-review.googlesource.com/c/go/+/237177
Run-TryBot: Baokun Lee <nototon@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-06-11 14:40:28 +00:00