Commit Graph

37567 Commits

Author SHA1 Message Date
Robert Griesemer fd583fcbae go/types: update README
Change-Id: Ifc694498d0661c02907a1f39f2ea9f1535d8dbdf
2020-06-13 12:24:48 -07:00
Ian Lance Taylor 1d379da30b go/go2go: don't expect type arguments after instantiated name
Change-Id: I639adb020890e29b96458db5dffdea31bd1f8ffe
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/712186
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:48 -07:00
Robert Griesemer faf2cc0cb8 go/types: improve printing of type parameter lists
- leave type bounds away if empty (interface); don't write "any"
- boundle type parameters with the same type type bound
- simpler code for error message cleanup

Change-Id: I8c1b662479de185b2ebae47ed1d16482253dfe03
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/710076
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:48 -07:00
Robert Griesemer f936401d53 go/types: use local and global type cache consistently (cleanup)
- store a *Named type in both caches
- update local cache also when we have a global cache hit

Change-Id: If4ab24a0c24d21f425a76dc51e4ec2ed495b26e4
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/710128
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:48 -07:00
Robert Griesemer 81022d54ae go/types: remove instantiated type name hacks
Instead of creating a new instantiated type name "name<T1, T2...>"
keep the regular name for the corresponding type object since
these newly created types are never declared. This eliminates
the need to clean up the names (remove the <>'s) before they can
be used.

When printing a named type, simply decide what to print depending
on whether it is instantiated or not.

When looking up an instantiated type, simply create the instantiated
type name string for use in the (local and global) type caches.

Change-Id: I4b20d09ec64d8deefccdd338ffb2f78fdfd2101e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/710062
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:48 -07:00
Robert Griesemer f25fd9bf57 go/types: remove an empty line (test for code review)
Change-Id: I5595aa5ea2ae808c60dde1566d35bad8ad7761c5
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/709260
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:48 -07:00
Ian Lance Taylor be37919cd7 go/types: better error message for incomparable type
If a type does not satisfy comparable, don't report "missing method ==".

Change-Id: Idae2477e134f73db9ba5fb94302eec84fefe98ef
2020-06-13 12:24:48 -07:00
Ian Lance Taylor d3ecc7c57c cmd/go2go: mention some tool restrictions in the doc
Change-Id: I8568fffa6570610d909b0f23fa9bdd3ab6097a78
2020-06-13 12:24:48 -07:00
Robert Griesemer ab835222b0 go/types: updated README (after rebasing on top of master)
Change-Id: I3d63346aa00b6de8a7ba725081affb155cc828f1
2020-06-13 12:24:48 -07:00
Robert Griesemer ac135a4bcf go/types: better error messages for type inference
Change-Id: I8a5b07eca76b084901cce6f1bae4f8d107d10701
2020-06-13 12:24:48 -07:00
Robert Griesemer 1ad26bf1a7 go/types: fix some internal comments
Change-Id: I50f9127219321c3f173b28bf42b03e01384d920a
2020-06-13 12:24:48 -07:00
Ian Lance Taylor fad64b3083 cmd/go2go: add pointer variant to graph package
Change-Id: Ib5cf28be42943ea816c64740f5698a5716d3dec1
2020-06-13 12:24:48 -07:00
Robert Griesemer 07382406ea go/types: fix satisfaction check of argument type against type bound
Per the draft design:

In a generic function body all method calls will be pointer method calls.
If necessary, the function body will insert temporary variables, not seen
by the user, in order to get an addressable variable to use to call the method.

When checking if a concrete type argument satisfies its type bound, assume
that concrete type is the type of an addressable value.

Change-Id: I9d40138755c38330448c010994b95a82f38e60e0
2020-06-13 12:24:48 -07:00
Robert Griesemer 6768c4f513 go/types: first cut at better error messages
- added Error.Full and Error.FullError which provide the full error
  message, possibly containing internal details
- Error.Msg and Error.Error provide a user-friendly error message

Change-Id: Id3044165331af71be31ef423cd2c9b8fe28accbd
2020-06-13 12:24:48 -07:00
Robert Griesemer 62683a7752 go/types: fix lookup of methods of pointers to type parameters
Since the type bound of a type parameter is an interface, no method
is found if the receiver is a pointer to a type parameter (pointers
to interfaces have no methods).

Ignore the indirection in this case.

Change-Id: Ie2af78b4cfb2f70b5d4f1d2afc631716a10ff7d9
2020-06-13 12:24:48 -07:00
Robert Griesemer f81ad49939 go/types: report an error when seeing pointer designation in contracts
Pointer designations were not recognized nor supported.
Now we recognize them and report an error until type-checking
can handle them.

Change-Id: I0deed536aa03c06c3e9ec60a5c2e186e916b970f
2020-06-13 12:24:48 -07:00
Robert Griesemer e03920500c go/printer: print pointer designation of type parameters in contracts
Also: Align start or methods and type lists.
Change-Id: Icae3be0ebcbc633d2ed88ff6f620dc078a7c698e
2020-06-13 12:24:48 -07:00
Robert Griesemer 49c8636998 go/parser: accept pointer designation for type parameters in contracts
Change-Id: Ib119b7cd22de7117db82b987a3cd4573cbb6f6c8
2020-06-13 12:24:48 -07:00
Ian Lance Taylor 29365a1738 cmd/go2go: rename graphs_test.go2 to graph_test.go2
Change-Id: I25cfedbf6c115db5545c0c12b96588a581e41a53
2020-06-13 12:24:47 -07:00
Ian Lance Taylor 87059675da go/go2go: support instantiating with an inferred local type
Add a graph example.

Change-Id: Iec533487f2757b9fdc883e4a57715ad993e11254
2020-06-13 12:24:47 -07:00
Ian Lance Taylor 5f4c825cf8 go/go2go: support imports that only defines funcs
That case was breaking when looking for a symbol to import to avoid an
unused package error.

Change-Id: I51ccacf36a95a16eac89071d5fa141608b759014
2020-06-13 12:24:47 -07:00
Robert Griesemer a31f6ae875 go/*: change representation of type lists in interface types, adjusted dependent code
Until now, types of type lists in interface types were collected in
a single expression list "Types". This made it not possible to gofmt
such interfaces while preserving the original layout of type lists.

This change represents types of type lists as part of an ast.FieldList.
The ast.InterfaceType.Methods field list now represents embedded interfaces,
methods, or type list types through ast.Fields. This preserves all position
information and thus permits accurate gofmt-ing.

The new representation is as follows: For an ast.Field f, if
- len(f.Names) == 0        : f.Type is an embedded interface
- f.Names[0].Name == "type": f.Type is a type of a type list
- otherwise                : f represents a method

Since "type" is a keyword, a Go field name cannot be "type".
Fields of types of type lists that share the same "type" keyword
in the source share the same f.Names[0] identifier (named "type"),
and the position of that identifier is the position of the "type"
keyword in the source.

Related changes:
- Adjusted go/parser to build the new representation.
- Adjusted go/printer and implemented formatting of type lists.
  (This is still not quite correct if there are comments, but
  that is fine-tuning).
- Adjusted go/types to work with the new representation.
- Implemented SplitFieldList and MergeFieldList in go2go
  translator to easily switch between old and new representation.
- Updated documentation.

Change-Id: I016e2ce5949bfe294509d703156c41d42cf7084e
2020-06-13 12:24:47 -07:00
Robert Griesemer e5e519e893 go/printer: cleanups around contract printing
- added more tests
- documented invariants and status quo

Change-Id: I74d75eee3936e659476fc5b428e8d11d5c5e4098
2020-06-13 12:24:47 -07:00
Ian Lance Taylor 01ab391f82 go/go2go: support instantiating with an instantiated type
Add metrics test case to test GO2PATH.

Change-Id: I48c8a418d743ccd80cdcf36fc043ca0e2dd932f4
2020-06-13 12:24:47 -07:00
Ian Lance Taylor 42884d7524 go/types: support setting the TArgs of a types.Named
Change-Id: I468b77165079ab30844e54b4988717be452cb648
2020-06-13 12:24:47 -07:00
Ian Lance Taylor 10efd1cfc6 go/printer, go/ast: gofmt improvements for generic code
Change-Id: I62f7c0f52ac9d51eacd2392083e1aa7799022559
2020-06-13 12:24:47 -07:00
Robert Griesemer e39082c80f go/types: remove vestiges of type unification in Checker.identical0
Type unification now happens through the new unifier code.
We can revert the functionality of Checker.identical back
to its original purpose of type comparison. This change
should make identity comparison faster again.

Change-Id: I844515b5f20a890152a0a5436f04c553b3b722e5
2020-06-13 12:24:47 -07:00
Robert Griesemer 5da07bf767 go/types: implemented (bidirectional) unifier and use it for type inference
- Implemented bidirectional unifier as a stand-alone mechanism
  separate from Checker.identical0.
- Use it instead of Checker.identical0 where we need unification.
- Missing: Bidirection functionality not fully implemented because
  we don't use it yet, but the basic outline is present.

Change-Id: I1666c9e4c9094eda749084bb69c700f1b5e879bb
2020-06-13 12:24:47 -07:00
Ian Lance Taylor 42e310c4a6 cmd/go2go: add Append and Copy to slices test
Change-Id: Ie6826d8c66ae33a377dac9e66ff8363439a2be6c
2020-06-13 12:24:47 -07:00
Ian Lance Taylor 4a8a353a22 go/go2go, cmd/go2go: add orderedmap example
Add transitive imports so that imports used by instantiated functions
and types work correctly.

Change-Id: Ie8fe0aaece7ca1bdbf201242870113d741ad3f37
2020-06-13 12:24:47 -07:00
Robert Griesemer 46b40480b6 go/types: updated documentation
Change-Id: Id84fd18dc0e1928c96bb50a1759ced1e56605d51
2020-06-13 12:24:47 -07:00
Robert Griesemer 74bad35110 go/types: updated README
Change-Id: Ib68114593c5c26f05e06e7326c1567d3f253c5a5
2020-06-13 12:24:47 -07:00
Ian Lance Taylor 01b5212797 cmd/go2go: point to testdata/go2path in package docs
Change-Id: I94857bb943503d1107b814e5111ccd6512c4a477
2020-06-13 12:24:47 -07:00
Ian Lance Taylor 0b55a72ba3 cmd/go2go: remove explicit type arguments in chans_test
They are no longer needed as the type checker now ignores channel
direction for type inference.

Change-Id: I06f2ffaf60a140747f1fc5c47135045e9004d551
2020-06-13 12:24:47 -07:00
Robert Griesemer e490a1bfb5 go/types: ignore channel directions for type inference
Change-Id: Ic7c61dfea7b43bb102bff077bf17d86b26fffba9
2020-06-13 12:24:47 -07:00
Ian Lance Taylor db2cf1336d go/go2go: instantiate all kinds of types
Change-Id: Iaf17de0e5556171e18d4b0c4ae7e3dd1e9f7c777
2020-06-13 12:24:47 -07:00
Ian Lance Taylor 22a2e4f0c2 cmd/go2go, go/go2go: add chans test case
To make this work, add support for instantiating pointer types.

Change-Id: Ifcecf863ad4194014a242d0a0d01ca3dc0288811
2020-06-13 12:24:46 -07:00
Ian Lance Taylor 8d18d04312 go/go2go: report all type checking errors
Previously we reported just the first one.

Change-Id: Id8fbb50f8c6f8ab56ce76dacda4c388b76ce6c80
2020-06-13 12:24:46 -07:00
Ian Lance Taylor c165308eb6 go/go2go: fill in missing ast.Expr and Stmt nodes
Change-Id: I151a923c72fb61c8f31dc6d3688bcd338ab472f7
2020-06-13 12:24:46 -07:00
Ian Lance Taylor c65d33fa3d go/go2go: handle ast.Ellipsis in instantiate and rewrite
Change-Id: I03d316677c2a1cf31fe28d55df1ef21515a0a2ba
2020-06-13 12:24:46 -07:00
Ian Lance Taylor 87d1d10fbe go/go2go: register packages by full import path, not package name
Change-Id: Ie40021111c97c6b30a733912e3106e8a87a0634a
2020-06-13 12:24:46 -07:00
Robert Griesemer 399d59ee46 go/types: make type inference work for self-recursive function calls
Cases such as

	func f(type T)(x T) {
		f(x)
	}

can now be type-checked. For more examples see examples/functions.go2
in the go/types directory.

Change-Id: Id661c84f086cc8ee45ec372ac4af543e68bebe8a
2020-06-13 12:24:46 -07:00
Ian Lance Taylor 67e62d261e cmd/go2go: add sets package to testdata/go2path
Change-Id: Id47ae62192c1c8507689f8a5b1bb347baa5db4ea
2020-06-13 12:24:46 -07:00
Ian Lance Taylor 9482f72042 cmd/go2go: add Map/Reduce/Filter/Max/Min to test cases
Change-Id: I586d4c548d4a982fe15d75128ea4f82be9db2416
2020-06-13 12:24:46 -07:00
Robert Griesemer 54d6b25ee0 go/types: updated README
Change-Id: Ib4a86240ca82722d522f8b1ce67c96695c7c4b13
2020-06-13 12:24:46 -07:00
Ian Lance Taylor 2902418378 cmd/go2go: use embedded comparable in maps test
Change-Id: I9f3a8a377597330daa43d1757ddd8a18560cf5d4
2020-06-13 12:24:46 -07:00
Robert Griesemer a30aa6c43e go/types: fix contract embedding
Contract embedding is reduced to interface embedding. When embedding
interfaces:
1) use the correct interface to embed; and
2) don't leave type bounds residue on the incoming type arguments
   of the embedded interface/contract as those are also the type
   parameters of the embedding (outer) interface/contract.

Also:
- For now, print "any" instead of "interface{}" (empty interface)
  when printing type parameter lists to reduce clutter. Eventually
  we should not print anything for empty interface bounds, but we
  first must also group type parameters with the same type bounds.
- Print the type parameter subscript in type parameter lists to
  make it clearer which type parameter we are referring to.

Change-Id: Ic83516096387d0f512c4c76a8a8fe849d51e033a
2020-06-13 12:24:46 -07:00
Ian Lance Taylor 2044d8b94b cmd/go2go: use predeclared comparable in maps test
(But embedding comparable doesn't work yet.)

Change-Id: I977ca97597de47c79edb56b385c970392afb87f0
2020-06-13 12:24:46 -07:00
Robert Griesemer 10b59aa539 go/types: implement predeclared contract "comparable"
The comparable contract defines a magic method "==" which
enables comparisons with == and != . Comparable types
automagically implement this method.

TODO: If a type is not comparable but a comparable type is
expected, the error message can be confusing (missing ==
method).

Change-Id: Ie0d89b87c36d83549f7d869c18dd9786151adbae
2020-06-13 12:24:46 -07:00
Ian Lance Taylor e6f000d2f9 go/go2go: add maps test case
Change-Id: Iad570b218a7a3c2075f846cc86c58ec7e6b0e50c
2020-06-13 12:24:46 -07:00
Robert Griesemer 2bc31ee9f4 go/types: de-parameterize instantiated contracts when embedding them
More precisely, de-parameterize the corresponding interfaces when
embedding them in the corresponding type bounds (interfaces) for
the embedding contract. This prevents the embedded (and already
instantiated) interfaces from being instantiated again when the
outer interface is instantiated and avoids breaking an assertion.

See also the test case in testdata/issues.go2 for more details.

Change-Id: I70c9354849eda0c8a36905d0b80f4d3031542f30
2020-06-13 12:24:46 -07:00
Robert Griesemer 3935b33b31 go/types: avoid follow-on panic after assertion failure in subst
Also: Updated NOTES.

Change-Id: Iabc45e46aa76bacf5c6984dab6f4bcab74392562
2020-06-13 12:24:46 -07:00
Ian Lance Taylor 5a5b14a4b3 go/go2go: support type inference
We can now translate code that use type inference when calling generic
functions. A couple of test cases were adjusted to use it.

Change-Id: I53c2f3dd8f9fcdb44b4a8f592acee1a19ff46f22
2020-06-13 12:24:46 -07:00
Ian Lance Taylor 4172f069ae go/go2go: aggregate types.Info together for all packages
Change-Id: I4c73c417a1e7946422fd2e1035a2ce4406ca1cf3
2020-06-13 12:24:45 -07:00
Robert Griesemer 07a7684507 go/types: record inferred type arguments for parameterized calls
In api.go, introduce a new type `Inferred` which collects type arguments
and signature in one place and which can be extended if need be.

Change-Id: I014dd52641843e85ad408fdaa07eda121cf1c41c
2020-06-13 12:24:45 -07:00
Ian Lance Taylor 2eed31c177 go/go2go, cmd/go2go: build a GOPATH of translated packages
Also start a testsuite for cmd/go2go.

Change-Id: Ib693c79b3a7427ac2f6be3264469274157a39851
2020-06-13 12:24:45 -07:00
Ian Lance Taylor 1bf660ee7c go/go2go: initial support for contracts
Includes a small patch to go/types to correctly check whether type
parameters are comparable.

Change-Id: Icd3443e0cd968eabdbd55f90520b0c6ad485edf8
2020-06-13 12:24:45 -07:00
Robert Griesemer 3370013383 go/types: add support for imported contracts (denoted by qualified identifiers)
Original code by iant@. Slightly streamlined and fixed a bug in the
process (if there is a type error in the contract, we only must "use"
the type arguments if they exist in the first place).

Change-Id: Id404d2cd4fd081b9a8053e194bf643593093e397
2020-06-13 12:24:45 -07:00
Robert Griesemer 73bb221120 go/types: add types.Info.Inferred map recording inferred function signatures
Change-Id: Idc57c1662fe63edbe8f494961cb4dcda6db61e79
2020-06-13 12:24:45 -07:00
Robert Griesemer 1211c65e41 go/types: provide accessor to type arguments for instantiated types
Plus a couple of minor unrelated comment updates.

Change-Id: I38554c9ae9143172ea65da6c270fba10772c194b
2020-06-13 12:24:45 -07:00
Ian Lance Taylor 74ba054b38 go/go2go: start to handle inferred types
Also support for statements and inc/dec statements.

Change-Id: I9af474065d3b433f582422b739fc49ef266d2751
2020-06-13 12:24:45 -07:00
Robert Griesemer e27cae74ec go/types: assertions/type switches on generic types are strict
Assertions/type switches that are guaranteed to fail on generic
types are not permitted (in contrast to regular type assertions
and type switches).

Change-Id: Iaa5b96f094585cb206fdadaa501445f96f26c166
2020-06-13 12:24:45 -07:00
Robert Griesemer 86b6990e9e go/types: implement type assertions and switches over generic types
Change-Id: I5e8debe3fee832e7829bcf2d451bde9bdc50a600
2020-06-13 12:24:45 -07:00
Ian Lance Taylor fe586a7418 go/go2go, cmd/go2go: support importing Go2 packages
This support works for the top level test directory, but needs more
testing of "go tool go2go".

Change-Id: I01c4ce4a428535777b0fff1e6f8f39eee9005e04
2020-06-13 12:24:45 -07:00
Robert Griesemer 8578f6bfe6 go/types: address TODO (follow-up on previous commit)
Instead of rewriting the underlying AST for a receiver type in place,
explicitly pass the rewritten AST to Checker.collectParams.
Also, better comments in various places.

Change-Id: If64e80b2c6b4b57477a4a0bf87caaa2f4ea1bf21
2020-06-13 12:24:45 -07:00
Robert Griesemer f7bc9d382f go/types: support blank identifiers for unused receiver type parameters
Change-Id: I5d7d359d7453f7ed949a7cab7b85419f8f4ee2a9
2020-06-13 12:24:45 -07:00
Robert Griesemer 08e2d11638 go/types: update NOTES
Missed with prior commit.

Change-Id: If111c8c6df6663199a23f8a1d2c147114f34ba6f
2020-06-13 12:24:45 -07:00
Robert Griesemer 86c2daf9e9 go/parser, go/types: permit parentheses around embedded contracts
For symmetry with embedding in structs and interfaces.
Fixed an incorrect error message print in the process.

Change-Id: I295685438a22971edc610e6c51cfefd286eaffba
2020-06-13 12:24:45 -07:00
Ian Lance Taylor 5cc90acd4b go/build: add go/go2go to pkgDeps
Change-Id: I43c131a910c372d849095160e6feb958da906e19
2020-06-13 12:24:45 -07:00
Robert Griesemer 6c083a7972 go/types: use correct package when creating a new instantiated type
Fix provided by iant@.

Change-Id: Iec89f007cfe9b9b50351122a03550e64238f9c44
2020-06-13 12:24:45 -07:00
Robert Griesemer 3d8c442870 go/parser, go/types: accept parameterized embedded struct fields
To be able to distinguish between a named field with a parenthesized
type `foo (T)` and an embedded parameterized type `foo(T)` in structs
we permit the use of parentheses in embedded types. For instance, the
latter example will need to be written as `(foo(T))`.

The parser now accepts any parenthesized embedded type liberally
and assumes that type-checking makes sure only permissible types
are accepted. As a result, parsing of field declarations is now
massively simpler. Also, removed an unused function.

The type-checker now complains about invalid embedded types (as
opposed to an invalid AST); it also now accepts embedded parameterized
types.

Change-Id: Ib8c6cbea9a0b739f66ba266fb5f8b71f91b7b64e
2020-06-13 12:24:45 -07:00
Robert Griesemer 38c2ef660d go/types: implement substMap and use it for substitutions
Instead of passing around a type parameter list and type arguments,
create a substitution map from them and use that map instead.

Change-Id: Ia4a041d95bfaa98888c9c06812d33b3d2a79227d
2020-06-13 12:24:44 -07:00
Robert Griesemer 72d320ec6e go/types: don't compute parameter list twice for regular generic functions (optimization)
Avoid a substitution operation for non-variadic generic functions.

Change-Id: Id40c0078a05be3aa53cd5b8551fa9fe6107bcda8
2020-06-13 12:24:44 -07:00
Robert Griesemer 99c8ae0d28 go/types: cleanup instantiation of function signatures
Make sure that a generic signature is not generic anymore
after instantiation. Update various related comments.

Change-Id: I2ac81037e570dc3a96c138b85529f3d86030776a
2020-06-13 12:24:44 -07:00
Robert Griesemer 3ab56f5ff2 go/types: minor adjustment to an error message and comments
Change-Id: Ie9505d508507c9ed764ec725df1027c92bae0702
2020-06-13 12:24:44 -07:00
Robert Griesemer e70e49973e go/types: move method collection out of type declaration processing
Simplifies Checker.typeDecl. Also, methods can only be added to
top-level types; no need to try to collect them for local types.

Change-Id: I05b926df7ffa70c32c1dd5faed3c68617be8f270
2020-06-13 12:24:44 -07:00
Ian Lance Taylor 12a7da1eb0 go/go2go: add support for methods of parameterized types
Change-Id: I308eb692612cb8d6e7321c4972e90b102466b4c2
2020-06-13 12:24:44 -07:00
Robert Griesemer 1bcfb0add1 go/types: fix receiver type parameter inference
Make sure receiver type and actual receiver argument
match in "pointer-ness" before attempting to infer
any receiver type parameters.

Change-Id: Ie28004ce42ecef46e348424140b8d0c65e37cdaa
2020-06-13 12:24:44 -07:00
Robert Griesemer 5a2e660efa go/types: improved type strings for instantiated generic types
Better output for now, but the printing code is a hack and needs
a rethink and cleanup.

Change-Id: Ieb1f13a21645b48f9494ceda50f58017b31bbd82
2020-06-13 12:24:44 -07:00
Ian Lance Taylor b1322d38b6 go/go2go: support parameterized types
Added an accessor function to go/types:

// TParams returns the type parameters of the named type t, or nil.
func (t *Named) TParams() []*TypeName { return t.tparams }

Change-Id: Ife2322c73dd6eaecaed42655a57a37541661d1ed
2020-06-13 12:24:44 -07:00
Ian Lance Taylor f0d1b476a9 cmd/go2go: support "go2go translate a.go2 b.go2"
For the translate subcommand, support .go2 files as well as package names.
Creates a.go b.go.

Change-Id: Ica09ca447e7312dcec5fabbc68b365bc45d55ad5
2020-06-13 12:24:44 -07:00
Ian Lance Taylor 2687ed5586 go/go2go: simplify error handling in rewrite methods
Just store the error in the translator struct, rather than always
checking for an error and returning it up the stack.

Change-Id: I38ea2a282f61457eea123f852d9daf9337bcf9b8
2020-06-13 12:24:44 -07:00
Ian Lance Taylor 9ceb91ef5f go/go2go: cache type instantiations
Change-Id: Ie239e6ac7cfabf472970cd2aeddf337bcc242043
2020-06-13 12:24:44 -07:00
Ian Lance Taylor a480c1b795 go/go2go, go/types: support recursive instantiation
Permit a generic function to call a generic function.

Change-Id: Ic41b87eb4effd0d5eb9a6a209c98354b306d5449
2020-06-13 12:24:44 -07:00
Ian Lance Taylor 8238ad0ab5 test, go/go2go: support .go2 files in test directory
Add an initial test.

Change-Id: If1bd6922eebf6881d3ac5d93731078fb9ca7b032
2020-06-13 12:24:44 -07:00
Ian Lance Taylor a588cbcd8e go/go2go, go/types: preliminary support for rewriting and instantiation
Good enough to run this program:

package main

import "fmt"

func Print(type T)(s []T) {
	for _, v := range s {
		fmt.Println(v)
	}
}

func PrintInts(s []int) {
	Print(int)(s)
}

func main() {
	PrintInts([]int{1, 2})
}

Change-Id: I5ac205138085a63e7075b01ca2779b7eb71f9682
2020-06-13 12:24:44 -07:00
Ian Lance Taylor 10c3db1727 go/go2go: add line comments to rewritten files
Change-Id: I6fe3de668381d89131825ba00cc202f49c7971cf
2020-06-13 12:24:44 -07:00
Ian Lance Taylor f95754ecff cmd/go2go, go/go2go: new framework for translating generics to Go
Adds a new command go2go, invocable after installation as "go tool go2go".
The go2go command supports build, test, run, and translate subcommands.
These will translate .go2 files to .go files.
No actual translation is done yet; the files are simply rewritten.
So this is a framework that works if the .go2 files are pure Go 1 code.

Change-Id: I8183fd276c4c87577c428794fb87e8dde1fa398d
2020-06-13 12:24:44 -07:00
Robert Griesemer 7ad6dd2e38 go/types: add testdata/todos.go2 for documenting unimplemented features
Also: Updated NOTES file.

Change-Id: I9f760693a486433d5a496d155627cad330630e90
2020-06-13 12:24:43 -07:00
Robert Griesemer 352c86eca2 go/types: better error messages for range clauses over generic values
Change-Id: I7b4ad2734aea5ab508b35ab526f0953b4f99c3f3
2020-06-13 12:02:35 -07:00
Robert Griesemer 2b265905e9 go/types: better comments for range stmt code
Change-Id: Id7ccf3f47b5ba9d8edd023675122d5f975b89905
2020-06-13 12:02:35 -07:00
Robert Griesemer 172f10b1e2 go/types: first cut at supporting range over generic variables
TODO
- some channel errors are not reported for generic variables
- error messages should be better

Change-Id: Ie388d6811b605645ea092481eee3a850c7ceb77b
2020-06-13 12:02:34 -07:00
Robert Griesemer c8947e760e go/types: update README
Change-Id: I73eec3fa1ce247ae91e6acacfdd238a8314a3969
2020-06-13 12:02:34 -07:00
Robert Griesemer 4150c6a490 go/types: fix various issues with contract instantiation
Contract instantiation (= contracts with explicit type
arguments) should work now but has some implementation
restrictions:

- The type arguments provided to a contract must be
  type parameters from the type parameter list using
  the contract or the type parameter list of the en-
  closing contract (in case of contract embedding).

- Each type argument may be used at most once per
  contract expression.

Change-Id: Ia9f9d81e95d84f11ff3821b9f17b74eadab201f8
2020-06-13 12:02:34 -07:00
Robert Griesemer 203449cf09 go/internal/gccgoimporter: fix test
The typestring for embedded fields in structs was changed
by 8d30bd752d4 (type checking of function type parameters)
but this test was not updated.

Change-Id: I0d9438e3000939de09aa298c33ad1e9604a59fe8
2020-06-13 12:02:34 -07:00
Robert Griesemer 2ebcbd9efd go/printer: add missing test files
Change-Id: If5522bcf0f75a86b7aa36ed853a1349ad4a2a1f4
2020-06-13 12:02:34 -07:00
Robert Griesemer ee164bc407 go/test: steps toward instantiated contracts (partially working)
See testdata/tmp.go for a test that shouldn't succeed.

Change-Id: Iefa738e0b6df6c3abe74670f8bc1d62a3e8c4e46
2020-06-13 12:02:34 -07:00
Robert Griesemer 5d80216f87 go/types: ensure a TypeParam always has a non-nil type bound
Plus minor cleanups.

Change-Id: I2508a576ad56d55fb188aa78c861afd0d032cf80
2020-06-13 12:02:34 -07:00
Robert Griesemer 3272b2b60b go/types: factor out contract expression handling
Change-Id: I499cce2abd6cf0647ea6c0aa5f93bbd513020518
2020-06-13 12:02:33 -07:00
Robert Griesemer 312a8ea57c go/types: initial code to handle instantiated contract expressions
New code not yet used. Snapshot.

Change-Id: Id3f9172d5ebd198d34b66707eaf429b791374ea1
2020-06-13 12:02:33 -07:00
Robert Griesemer 3c2505cae9 go/types: use Interface.is for generic variable indexing/len/cap (cleanup)
Interface.is already takes care of iterating through all types of
a generic type bound; use it instead of writing custom loops each
time.

Change-Id: Ie0f91b27e5a7b65ea85a8c3847a954db1e9f24fe
2020-06-13 12:02:33 -07:00
Robert Griesemer 1a2a175a8e go/types: implement indexing of generic types
Change-Id: I88a488d9d279b1029dd8086ea1befaa7b5733df6
2020-06-13 12:02:33 -07:00
Robert Griesemer d2fce6bc64 go/types: implement len/cap for arguments of type paramater type
Change-Id: Ieeaa41573e5ec10df46ab25ec0a3563e3ae5b32b
2020-06-13 12:02:33 -07:00
Robert Griesemer c49fde5b11 go/types: various comment improvments (cleanup)
Change-Id: I0763f7ef202f9dec11abd4f204ab950b86e0272c
2020-06-13 12:02:33 -07:00
Robert Griesemer 45dd45561e go/parser: better error recovery for (invalid) local contracts
Change-Id: I76b0d2af3767978ca138d899a083a6e399fea0fe
2020-06-13 12:02:33 -07:00
Robert Griesemer b5ecc31064 go/parser, go/types: minor cleanups around type parameters
Change-Id: Ic2faf89a29193d1d50bb5bdccce0fda2301785ed
2020-06-13 12:02:33 -07:00
Robert Griesemer 2c0e53f518 go/parser, go/types: allow parenthesized embedded interfaces
This enables the distinction between a method M(int) and an
embedded instantiated (parameterized) interface (M(int)).

Change-Id: I150d1b1cd53a2b14ddc0ad6336d84078fcb41ad6
2020-06-13 12:02:33 -07:00
Robert Griesemer 9c75653a79 go/types: generalize/cleanup missingMethod to handle generic methods
This simplifies the use of missingMethod again but moving the lazy
instantiation of methods into missingMethod. Method comparison now
also takes method type paramaters into account.

This change enables the first examples of parameterized methods
to type-check.

Change-Id: I4c629fb7b1f8959184c6ce5196365893d11b197d
2020-06-13 12:02:33 -07:00
Robert Griesemer 3fd481043b go/types: must have at least one type when checking type list properties
Fixes bug with generic min being accepted even though the contract
or interface bound doesn't enumerate any types (or is missing).

Change-Id: Icdfc62fbd2b73ece397d5b5f1ebe27e52ed9b32f
2020-06-13 12:02:33 -07:00
Robert Griesemer 32c4c5a5f8 go/*: move TParams field into ast.FuncType and adjust dependencies
This step further consolidates all parameter types (except for the
receiver) in an ast.FuncType which now matches more closely the
representation of a types.Signature. As a result, fewer parameters
need to passed around because we can just use an *ast.FuncType or
a *types.Signature instead.

As an immediate (and implicit) consequence, parameterized interface
methods now type-check. (But we cannot yet "implement" them with a
matching concrete type.)

Change-Id: I2ea24694ade9838488625ffec48d5e98070d1006
2020-06-13 12:02:32 -07:00
Robert Griesemer e3a0a7429a go/types: first steps towards parameterized methods
This is a generalization of type parameters to methods.
Being able to type-check them (even if we don't have an
idea how to actually implement such methods) is likely
going to inform the structure the type-checker: If the
code is organized correctly, the generalization should
mostly just work (and consist of the elimination of
extra checks).

So far, this first step only exposed some minor scoping
issues (where does the scope of type parameters start).

Change-Id: I8658ea8d1876a0ce9c62c0e9a7e943301e9cc19d
2020-06-13 12:02:32 -07:00
Robert Griesemer 464fb5c1e7 go/parser: allow method type parameters
Controlled via methodTypeParamsOk (internal flag).

Change-Id: I821a303f897f5a99ac42f667a3f592cbd1e98d0c
2020-06-13 12:02:32 -07:00
Robert Griesemer a9c105c1d7 go/parser: use named consts rather than bools to control paramater parsing (cleanup)
Change-Id: I5d0638f4a9ad396c0203fc88ea93fcc38945f1b4
2020-06-13 12:02:32 -07:00
Robert Griesemer bc236133bf go/types: implement interface embedding of interfaces with types
This follows the approach used for methods, but there is no error
reporting yet if a type is (explicitly) declared multiple times in
an interface.

Change-Id: I52428174ae278577a7c538b0817c6fb7af1c369e
2020-06-13 12:02:32 -07:00
Robert Griesemer d4338964b3 go/types: implement contract embedding
Also:
- updated README
- rebased on master

Change-Id: Ieafcdd94460e02964350abc98651d0348d6521f9
2020-06-13 12:02:32 -07:00
Robert Griesemer b6a8a0a86f go/types: first steps towards contract embedding
Incomplete but all the major steps are outlined now.

Change-Id: I05c0357072d8b2c9f85154d3dd14984d2134de62
2020-06-13 12:02:32 -07:00
Robert Griesemer af12458327 go/types: always create a bound for each contract parameter
Also:
- simplify Contract struct
- rename some variables for more consistency

Change-Id: Icd10b47ac97d11870c6d4590c154b7efe158c134
2020-06-13 12:02:32 -07:00
Robert Griesemer 24cbbe5229 go/types: use function body scope for type and ordinary parameters
Change-Id: Iab3cf89125d9e13e1dff86710b313770a520a54a
2020-06-13 12:02:32 -07:00
Robert Griesemer 97251af9c4 go/types: move tparams field out of Func, clean up Signature
Type parameters are now collected as part of signature type
checking, as they are part of the type not the object. This
opens the door to more uniform handling of type parameters,
also for concrete methods and interface methods (future use).

Cleaned up confusion between Signature.mtparams and tparams:
tparams are explicitly declared function type parameters.
mtparams is gone and replaced with rparams which are the
receiver type parameters used in the function.

Various related cleanups.

Change-Id: Id8422b57cc8fbc18ffdca12a69d890aef83c3f80
2020-06-13 12:02:32 -07:00
Robert Griesemer 6e52291881 go/types: factor out type parameter list declaration
Including minor related cleanups.

Change-Id: I9d6f6ce6d2460fed10aa0818baa3f53b6f723b39
2020-06-13 12:02:32 -07:00
Robert Griesemer 2741fd2ea1 go/types: rewrite Checker.collectTypeParams (fix TODO)
Change-Id: Ie504606340d6ce52c1d5241ba13ec02043ba5400
2020-06-13 12:02:32 -07:00
Robert Griesemer 3d4810b5ba go/parser: remove vestiges for [type T] style type parameters
We're not going back to that notation.

Change-Id: Ic3d9b2c931525df60c00ed0ba0e43c20be5f7b43
2020-06-13 12:02:31 -07:00
Robert Griesemer 9090a73d10 go/types: updated NOTES and README files
Change-Id: Iea657febf7bf86f28116d9ac0fdf3c921d436b90
2020-06-13 12:02:31 -07:00
Robert Griesemer 53a8d66b5b go/types: temporary fix for subtle signature instantiation bug
A signature that's instantiated but doesn't have any incoming
or result (value) parameters doesn't get a copy automatically.
This leads to bugs because the instantiated signature doesn't
lose its type parameters when it should.

Make a copy outside for now, this fixes some (but not all cases)
and added test cases.

Also, factored out printing of type parameters in type printing.

Change-Id: I0ec3a4226c7473cddfb16704a2218992dd411593
2020-06-13 12:02:31 -07:00
Robert Griesemer d45f7ef80d go/types: move tparams field out of TypeName and into Named
Type parameters are a property of the type, not the type name.

Change-Id: I479eafea80f9bfbd638e688ac0747cfa52df5da1
2020-06-13 12:02:31 -07:00
Robert Griesemer 1a93d0a2ca go/types: treat contract decl as declaration, not type
This change completes the prior change by adjusting the go/types
implementation accordingly. As a consequence, contracts may now
not occur in type context anymore and errors are reported if they
do.

With this change, all tests pass again.

Change-Id: Id984b3d24b7cb6ff2fceb74fd3c33fd0af91fdce
2020-06-13 12:02:31 -07:00
Robert Griesemer 3a40a4f856 go/ast, go/parser, go/printer: treat contract decl as declaration, not type (cleanup)
Progress snapshot.

This change makes a contract declaration a proper declaration (as it is
envisioned in the design draft). Specifically, contracts cannot be used
in type position anymore, and a contract declaration is not treated as
a type declaration with the type being a contract.

The change has not been pushed through go/types yet; this change will
temporarily brake go/types.

Change-Id: Ia4034caebab07dac449a02cdd362d6ce5d61c4a3
2020-06-13 12:02:31 -07:00
Robert Griesemer bf01ee1864 go/types: update README
Change-Id: I9508ad449a82295ec2eb1a31c6932fcf8b42fee3
2020-06-13 12:02:31 -07:00
Robert Griesemer ac0c4f1846 go/types: fix bug with generic function instantiation
Once a generic function is instantiated, it's not generic anymore.

Also: Added various additional test cases.

Change-Id: Ic2304b6c252cfdf41e526825dda64b8a77023d47
2020-06-13 12:02:31 -07:00
Robert Griesemer edb963e7e9 go/types: fixed testdata/linalg.go2 example
The new lazy method substitution code seems to work. The bug was
in the test, not in the implementation!

Change-Id: I39794743a01e9725d57f49ccd7c3751376cd01d6
2020-06-13 12:02:31 -07:00
Robert Griesemer a28b69c5d0 go/types: various attempts at lazy substitution of methods for lookups (snapshot)
When instantiating a type, we should also instantiate its methods (at least their
signatures) so that they have the correct type when being looked up. Unfortunately,
methods may not yet be type-checked; and worse, when we type-check them, typing
their receiver means instantiating that type again which would require updating
(= instantiating) the methods...

Instead, we keep the original list of methods (*Funcs) with each (named) type
and only update the method signatures when looking them up. The problem with this
approach is that we need to know with which values to substitute the method (i.e.,
receiver) type parameters, and this is currently not working.

Change-Id: Ie1835919dc8bfb8161a6a9e3d784c3bbbeb958c4
2020-06-13 12:02:31 -07:00
Robert Griesemer cef8f5c6a4 go/types: move includeTypes function to a method of Interface (cleanup)
Change-Id: Ic3a4beaa279b6d6349136f5a9ff0447227cabb5a
2020-06-13 12:02:31 -07:00
Robert Griesemer 74d0d556d9 go/types: use named receiver type for contract methods
Change-Id: Ib82a8c41490d75ee80cd96fbf862412fdc5657c2
2020-06-13 12:02:30 -07:00
Robert Griesemer 609756301c go/types: updated NOTES
Change-Id: I65cbbb3aaeb1c364932b7e9ee8bdc7635ac41160
2020-06-13 12:02:30 -07:00
Robert Griesemer 960e15c183 go/types: print implementation type in tracing output of types
Change-Id: I9d48540413addaac4b2a6e2b821e9ef63e97c983
2020-06-13 12:02:30 -07:00
Robert Griesemer 118728b8c2 go/types: steps towards customization of methods in bounds checks (snapshot)
This CL introduces an update mechanism to customize method signatures
with the correct type parameters before comparing them for equality.
The mechanism is not correctly used, yet.

Change-Id: Ib88af88e151578a3fb3a648ed70d3f462a936c9b
2020-06-13 12:02:30 -07:00
Robert Griesemer e1203396e7 go/types: updated README
This README can now be used as commit message.

Change-Id: I26d1e430d643868bd7e3d71ec585b8518ad47366
2020-06-13 12:02:30 -07:00
Robert Griesemer 29f795f511 go/types: implement conversions to generic types
Change-Id: Ifa878fddea3548a27579b3196921c6816f2d9363
2020-06-13 12:02:30 -07:00
Robert Griesemer 75897ab270 go/types: instantiate contracts when used as type bounds
Change-Id: I1b9ecf6007b485ca53096134fa875a9bf6fcfa73
2020-06-13 12:02:30 -07:00
Robert Griesemer 67b83f1382 go/types: represent type parameter bounds always as interfaces
When type-checking contracts, construct a parameterized named
interface for each of the contract parameters. Use those iterfaces
as type bounds for the type parameters.

This simplifies and cleans up the implementation.

Change-Id: I688e38542fa7fa83dd436439dd9ebe35af2f0458
2020-06-13 12:02:30 -07:00
Robert Griesemer ed8d54fb3a go/types: added testdata/linalg.go2 to test suite, disabled some code
Context-specific customization of parameterized interface methods of
type parameter bounds is missing; as a result some of linalg.go2 fails.

Change-Id: I3e749ee040d2b3ae8f73ae26680984bc1b4b79ef
2020-06-13 12:02:30 -07:00
Robert Griesemer 2aeeba6836 go/types: set receiver type bounds for methods
Enable a few more tests that now work correctly.

Change-Id: I7efe91660c2896d4d8279b86831aa7de2ae7c0ad
2020-06-13 12:02:30 -07:00
Robert Griesemer d49c915592 go/types: a type arg type list must be a subset of the type param type list
The original implementation (commit 65377ae6e0) checked the wrong way around.
Added more tests.

Change-Id: I59e1fd6d7e646f2e8e0ff68a0bbcf9ff9def0eff
2020-06-13 12:02:30 -07:00
Robert Griesemer a30fb05aa2 go/types: substitute type parameters when checking type param. bounds
Change-Id: Ib97d1b3928629bc073b32fde48709369213a4bbb
2020-06-13 12:02:30 -07:00
Robert Griesemer d941f3db1d go/types: remove satisfyContract - now implemented via instantiate
Change-Id: I1561d57709a996112b39aa8a15826387ea062e29
2020-06-13 12:02:29 -07:00
Robert Griesemer 6e1fbb8a53 go/types: factored writeTypeList, various minor cleanups, added test case
Change-Id: I971633c93099ab69466dc152e23aa9cf3ded50e0
2020-06-13 12:02:29 -07:00
Robert Griesemer 5504084423 go/types: implement type bound checking for type parameter type args
If the type argument is itself a type parameter, we must use that
type parameter's bound to check against the bound of the type
parameter matching the type argument.

Change-Id: If5128115a9fc10af8163c37b1f75645447ead766
2020-06-13 12:02:29 -07:00
Robert Griesemer 0de29c0b76 go/types: more cleanups around type instantiation
- type instantiations checks parameter count
- better positions for error messages
- removed some (now) dead code

Change-Id: Icf70642bbfd4e45a7762b002ea94704dc3d56475
2020-06-13 12:02:29 -07:00
Robert Griesemer 13893bbf9e go/types: type instantiation to verify type bounds
Change-Id: Ia4670a0d6bbabf4a1ac71410c7bfccc99ba61c9d
2020-06-13 12:02:29 -07:00
Robert Griesemer 3458c46de1 go/types: factor out/consolidate instantiate calls
Change-Id: I4973e0ebcd07d543b049f1fcdd8040f2ae214142
2020-06-13 12:02:29 -07:00
Robert Griesemer be92a40c3f go/types: minor improvements in tracing output, removed some TODOs
Also: added failing test cases to NOTES

Change-Id: Ie7b823b4cc46c64068749676d7a1464082e60264
2020-06-13 12:02:29 -07:00
Robert Griesemer 57c8d7fe0a go/types: do not permit parenthesized uninstantiated generic types
Document the design decision.

Change-Id: Ied5d77bc576653b49edcde4cdb3f6b95623a9045
2020-06-13 12:02:29 -07:00
Robert Griesemer fefe08cbea go/types: check that generic types are instantiated before use
This (temporarily) disables the use of recursively defined
generic types w/o repeating the type arguments, but such
type definitions need some more (type-checking) love anyway
before all conditions are checked.

Change-Id: I173f5ce2296b1c484ac95a3a887812c0b1f88245
2020-06-13 12:02:29 -07:00
Robert Griesemer eacaaec439 go/types: add NOTES text file
To be used for better record keeping (design notes, observations,
bugs, TODOs, etc.).

Change-Id: Iaecf091dcd46f53ee55b97236bd0febd7c1d2b3d
2020-06-13 12:02:29 -07:00
Robert Griesemer edc9611855 go/types: various minor fixes around interface type bounds
- print type bounds when printing function signatures
- store (named) tyep bound rather than underlying type
- first example using parameterized interface type bound working

Change-Id: Ic7110039d1e09838c8f33040e887e6a4f038d75d
2020-06-13 12:02:29 -07:00
Robert Griesemer 704beb3881 go/parser, go/types: parse/type-check interface (literal) type constraints
Accept (parse and type-check) parameterized interfaces with literal
type constraints, as in contracts. For instance, instead of

	contract C(T) {
		T add(T) T
		T int, string
	}

one can write

	type C(type T) interface {
		add(T) T
		type int, string
	}

Their use as type bounds still needs some work, though.

Change-Id: I9d59681dc0ba38054ee5627be141fc6e8a78381b
2020-06-13 12:02:28 -07:00
Robert Griesemer 6db0b6d33a go/parser, go/types: various minor fixes around printing and tracing
- set correct token position for ast.ContractType
- print "best effort" interface position in "complete interface" traces
- don't print trace output for types that are already set up
- print contract "signtature" when printing Contract type

Also: rebased on top of today's master branch

Change-Id: I6a528ce51a4152c25ad5d83ad52e01df8e89d283
2020-06-13 12:02:28 -07:00
Robert Griesemer 234ccd01f3 go/types: print contract type strings
Change-Id: Id698420124d526eb481659856705798bc5648b91
2020-06-13 12:02:28 -07:00
Robert Griesemer 4fa7fd828d go/types: fix type inference and method calls with parameterized receivers
This change expands type inference to parameterized named types
and clarifies handling of type parameters during type inference
(specifically, an inferred type may be a type parameter itself).

The change also implements method selectors with parameterized
receiver types by using type inference to deduce the receiver
type parameters.

Add more tests and enable many disabled tests that now work
correctly.

Change-Id: I8e10f9166fec9a8454f14b8fb089230c70422a1b
2020-06-13 12:02:28 -07:00
Robert Griesemer 1a0bc57392 go/types: removed instantiate call, renamed instantiate2 => instantiate
Also: added a currently failing test case to testdata/tmp.go2

Change-Id: I605bffb457e3b3979b42a642010215630c0544c6
2020-06-13 12:02:28 -07:00
Robert Griesemer 45eb8a74f0 go/types: added another example to examples/types.go2
Also: disabled aggressive rewriting of methods upon type instantiation

(Need to first figure out what we really need to do.)

Change-Id: I6fba78d60963534ebfe130164058ac1fbed7e5a3
2020-06-13 12:02:28 -07:00
Robert Griesemer 47ddbd09af go/types: added example to examples/types.go2
Change-Id: Ib2e5d28c48bc818e1c1a54ae4888bbab916b758a
2020-06-13 12:02:28 -07:00
Robert Griesemer 3e2c9743cb go/types: write TypeParam id's using subscript digits (fun)
Change-Id: I0df6e534774b2616f67c29a1525ddb40dbed9b05
2020-06-13 12:02:28 -07:00
Robert Griesemer 8c7ab48154 go/types: remove Parameterized type and related code
The need for the Parameterized type was eliminated by
the prior commit.

Change-Id: I8a2a2ae19ec5fef9292885fc7d23f8950d917e2f
2020-06-13 12:02:27 -07:00
Robert Griesemer 703974d608 go/types: rewrote instantiation of named types
A parameterized named type is in one of two states: not yet
instantiated, or instantiated. It may be instantiated with
any type, including (outer) type parameters. An instantiated
parameterized type may needs its type parameters substituted
if it is part of an enclosing type (or function) that is
instantiated.

A Named type has an extra field targs which is set to the
type arguments if the type is instantiated.

As a result, we don't need a representation for (partially)
instantiated parameterized types anymore: the Parameterized type
is now unused (but still present in the code).

Added a unique id field to TypeParam types so they can be
printed with a unique name. This permits the creation of a
unique type name for instantiated types which then can be used
for hashing that type name.

Also, made interfaces as type bounds work in more cases.

A handful of places (in testdata/map.go2, map2.go2) are broken
(commented out) and need investigation.

Change-Id: I137d352b419b2520eadde1b07f823375e0273dab
2020-06-13 12:02:27 -07:00
Robert Griesemer 46442bd4a9 go/parser: complain if type parameters are not permitted
Always accept them but complain if they are not permitted.
The analogous parser check was lost in a recent change.

Also: Fix index computation in collectTypeParams.

Change-Id: I7cb89944984df6dadd7f603b56f0c3941d60f7c5
2020-06-13 12:02:27 -07:00
Robert Griesemer c47bad9a28 go/types: interfaces as type bounds starting to work
With various loose ends.

Change-Id: Idbcb4affc585f5bb14caa2045943a64a78d05d09
2020-06-13 12:02:27 -07:00
Robert Griesemer 51d599efa2 go/parser, go/types: steps towards accepting interfaces as type bounds
Also, rebased branch on top of master.

Change-Id: I758b19ae577a4554687b2206c016277c1ca21a45
2020-06-13 12:02:27 -07:00
Robert Griesemer 34f753b9d1 go/types: add testdata/linalg.go2 (not yet type-checked)
Also, added missing copyright notices in a few places.

Change-Id: Iaa39c10a1821a189cef604d2442e6f7ed7ac68a8
2020-06-13 12:02:27 -07:00
Robert Griesemer 660f7c38d1 go/types: first cut at supporting real/imag/complex with type parameters
Change-Id: Ic0dba1a5e758942a03d114df10cb5536cf432985
2020-06-13 12:02:27 -07:00
Robert Griesemer e4a39e916f go/types: update README
Change-Id: I81e8304da885f36a2f6a41f6809063e74e87b0ea
2020-06-13 12:02:27 -07:00
Robert Griesemer 1bddb66b7c go/types: more operators supported by contracts
Change-Id: I03493508813d13dd1a16cd675de68170da14b29f
2020-06-13 12:02:27 -07:00
Robert Griesemer cfbeecaabb go/types: first cut at type-checking type parameters with operators
- implemented for comparisons for now
- can type-check generic min
- also: rebased on top of Go tip

Change-Id: Id35582a59c4cddcb2b4ae9c7d7154ef8e41580ab
2020-06-13 12:02:27 -07:00
Robert Griesemer dc4f9fb373 go/types: first steps towards collecting/recognizing type constraints
Change-Id: Ic0d70db24ad9fb76a5bb128df654c131f173247e
2020-06-13 12:02:27 -07:00
Robert Griesemer 7b6471a756 go/types: use new Checker.completeInterface when constructing Contracts
Change-Id: I1b54ddb7ac69541fcab1f17e0fe1574288a5b9b9
2020-06-13 12:02:27 -07:00
Robert Griesemer 0ac0b8518c go/types: add testdata/map2.go2, update README
Change-Id: I5a859fe3298998810ba56f3b445fae8e1d177995
2020-06-13 12:02:27 -07:00
Robert Griesemer 5891f8c720 go/types: add cycle detection to IsParameterized
Also: Recognize method expressions with parameterized receivers
and report an error for now (not implemented yet).

Change-Id: I96405b2b739d8e9fff6e9840347d3e78bfe8b6ec
2020-06-13 12:02:27 -07:00
Robert Griesemer 1f06612063 go/types: fix a bug with type instantiation
Change-Id: I977bb5525a40d0e17c27bbc01d7c77426e1bad00
2020-06-13 12:02:26 -07:00
Robert Griesemer e73de77f33 go/types: some prep work for making `import "chans"` (testdata/map.go2) work
To make the import work, the import needs to be changed into
`import "./chan"`, the file testdata/chans.go2 needs to be
copies into a new directory testdata/chan and the file must
be renamed to chans.go.

But this exposes some problem with instantiating parameterized
types with other type parameters. Delaying this for now.

Change-Id: I1cd784fb89c2374131f3b1105493492eb0189abc
2020-06-13 12:02:26 -07:00
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
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
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
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
Matthew Dempsky 6aadfcdfad go/types: rename UsesCgo to go115UsesCgo
This API and functionality was added late in the Go 1.15 release
cycle, and use within gopls has revealed some shortcomings. It's
possible (but not decided) that we'll want a different API long-term,
so for now this CL renames UsesCgo to a non-exported name to avoid
long-term commitment under the Go 1 compat guarantee.

Updates #16623.
Updates #39072.

Change-Id: I04bc0c161a84adebe43e926df5df406bc794c3db
Reviewed-on: https://go-review.googlesource.com/c/go/+/237417
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-10 21:39:03 +00:00
Gawen Arab ec177e4c83 cmd/internal/objabi: enable frame-pointer for iOS arm64
This improves stack unwinding of Go code running on iOS arm64.

Change-Id: I0494f750c15dcb895f9d4a072352f050d731df17
GitHub-Last-Rev: 435a2a1690
GitHub-Pull-Request: golang/go#37403
Reviewed-on: https://go-review.googlesource.com/c/go/+/220588
Run-TryBot: Elias Naur <mail@eliasnaur.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-06-10 20:58:11 +00:00
Rodolfo Carvalho e92be18fd8 runtime: fix typo in FuncForPC doc
Change-Id: I04037e13b131e79ebc5af84896bfeda49ddc0eaa
GitHub-Last-Rev: b0d0de9308
GitHub-Pull-Request: golang/go#39500
Reviewed-on: https://go-review.googlesource.com/c/go/+/237220
Reviewed-by: Keith Randall <khr@golang.org>
2020-06-10 14:56:01 +00:00
Michael Munday ac743dea8e cmd/compile: always tighten and de-duplicate tuple selectors
The scheduler assumes two special invariants that apply to tuple
selectors (Select0 and Select1 ops):

  1. There is only one tuple selector of each type per generator.
  2. Tuple selectors and generators reside in the same block.

Prior to this CL the assumption was that these invariants would
only be broken by the CSE pass. The CSE pass therefore contained
code to move and de-duplicate selectors to fix these invariants.

However it is also possible to write relatively basic optimization
rules that cause these invariants to be broken. For example:

  (A (Select0 (B))) -> (Select1 (B))

This rule could result in the newly added selector (Select1) being
in a different block to the tuple generator (see issue #38356). It
could also result in duplicate selectors if this rule matches
multiple times for the same tuple generator (see issue #39472).

The CSE pass will 'fix' these invariants. However it will only do
so when optimizations are enabled (since disabling optimizations
disables the CSE pass).

This CL moves the CSE tuple selector fixup code into its own pass
and makes it mandatory even when optimizations are disabled. This
allows tuple selectors to be treated like normal ops for most of
the compilation pipeline until after the new pass has run, at which
point we need to be careful to maintain the invariant again.

Fixes #39472.

Change-Id: Ia3f79e09d9c65ac95f897ce37e967ee1258a080b
Reviewed-on: https://go-review.googlesource.com/c/go/+/237118
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-06-10 14:55:29 +00:00
Bryan C. Mills 2a4e71c752 run.bat: do not unset GOROOT_FINAL before running tests
This removes the same logic from run.bat that was removed from
cmd/dist in CL 236819.

The duplicated logic was removed from run.bash and run.rc in CL 6531,
but that part of run.bat was apparently missed (and not noticed
because its effect was redundant).

Also fix a path-separator bug in cmd/addr2line.TestAddr2Line that was
exposed as a result.

Fixes #39478
Updates #39385

Change-Id: I00054966cf92ef92a03681bf23de7f45f46fbb5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/237359
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-10 03:27:28 +00:00
Roland Shoemaker 7b872b6d95 crypto/tls: restore OCSP and SCTs during session resumption
Restore previously sent SCTs and stapled OCSP response during session
resumption for both TLS 1.2 and 1.3. This behavior is somewhat
complicated for TLS 1.2 as SCTs are sent during the server hello,
so they override what is saved in ClientSessionState. It is likely
that if the server is sending a different set of SCTs there is probably
a reason for doing so, such as a log being retired, or SCT validation
requirements changing, so it makes sense to defer to the server in
that case.

Fixes #39075

Change-Id: I3c0fa2f69c6bf0247a447c48a1b4c733a882a233
Reviewed-on: https://go-review.googlesource.com/c/go/+/234237
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-06-09 23:24:08 +00:00
Brad Fitzpatrick 619072be41 runtime: fix typo in comment (object -> objects)
Change-Id: I2af1f9dcd1a9609681e58ab07e73e6d7a5f8a12b
Reviewed-on: https://go-review.googlesource.com/c/go/+/237160
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-09 21:24:52 +00:00
Vee Zhang 281f0ed7bf internal/poll: correct function name in comment
Change-Id: I3b28a45e942a6d6032855758fcc41e4edd64aa32
GitHub-Last-Rev: 9c994bbee7
GitHub-Pull-Request: golang/go#39467
Reviewed-on: https://go-review.googlesource.com/c/go/+/237059
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-09 20:45:39 +00:00
eric fang e5e386938f cmd/asm: fix the encoding error of VCNT instruction for arm64
When the arrangement specifier is "B16", the 30-bit should be 1 rather than 0.
This CL fixes this error.

Fixes #39445

Change-Id: Ib44881cdb8b3aab855cb30f2c52a085cd73a6a2c
Reviewed-on: https://go-review.googlesource.com/c/go/+/236638
Run-TryBot: eric fang <eric.fang@arm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-06-09 15:58:36 +00:00
Xiangdong Ji e031318ca6 cmd/compile: ARM comparisons with 0 incorrect on overflow
Some ARM rewriting rules convert 'comparing to zero' conditions of if
statements to a simplified version utilizing CMN and CMP instructions to
branch over condition flags, in order to save one Add or Sub caculation.

Such optimizations lead to wrong branching in case an overflow/underflow
occurs when executing CMN or CMP.

Fix the issue by introducing new block opcodes that don't honor the
overflow/underflow flag:

  Block-Op         Meaning                   ARM condition codes
  1. LTnoov        less than                 MI
  2. GEnoov        greater than or equal     PL
  3. LEnoov        less than or equal        MI || EQ
  4. GTnoov        greater than              NEQ & PL

The patch also adds a few test cases to cover scenarios that are specific
to ARM and fine-tunes the code generation tests for 'x-const'.

For more details please refer to the previous fix on 64-bit ARM:
  https://go-review.googlesource.com/c/go/+/233097

Go1 perf, 'old' is the non-optimized version, that is removing all concerned
rewriting rules.

name                     old time/op    new time/op     delta
BinaryTree17-8              7.73s ± 0%      7.81s ± 0%  +0.97%  (p=0.000 n=7+8)
Fannkuch11-8                7.06s ± 0%      7.00s ± 0%  -0.83%  (p=0.000 n=8+8)
FmtFprintfEmpty-8           181ns ± 1%      183ns ± 1%  +1.31%  (p=0.001 n=8+8)
FmtFprintfString-8          319ns ± 1%      325ns ± 2%  +1.71%  (p=0.009 n=7+8)
FmtFprintfInt-8             358ns ± 1%      359ns ± 1%    ~     (p=0.293 n=7+7)
FmtFprintfIntInt-8          459ns ± 3%      456ns ± 1%    ~     (p=0.869 n=8+8)
FmtFprintfPrefixedInt-8     535ns ± 4%      538ns ± 4%    ~     (p=0.572 n=8+8)
FmtFprintfFloat-8          1.01µs ± 2%     1.01µs ± 2%    ~     (p=0.625 n=8+8)
FmtManyArgs-8              1.93µs ± 2%     1.93µs ± 1%    ~     (p=0.979 n=8+7)
GobDecode-8                16.1ms ± 1%     16.5ms ± 1%  +2.32%  (p=0.000 n=8+8)
GobEncode-8                15.9ms ± 0%     15.8ms ± 1%  -1.00%  (p=0.000 n=8+7)
Gzip-8                      690ms ± 1%      670ms ± 0%  -2.90%  (p=0.000 n=8+8)
Gunzip-8                    109ms ± 1%      109ms ± 1%    ~     (p=0.694 n=7+8)
HTTPClientServer-8          149µs ± 3%      146µs ± 2%  -1.70%  (p=0.028 n=8+8)
JSONEncode-8               50.5ms ± 1%     49.2ms ± 0%  -2.60%  (p=0.001 n=7+7)
JSONDecode-8                135ms ± 2%      137ms ± 1%    ~     (p=0.054 n=8+7)
Mandelbrot200-8             951ms ± 0%      952ms ± 0%    ~     (p=0.852 n=6+8)
GoParse-8                  9.47ms ± 1%     9.66ms ± 1%  +2.01%  (p=0.000 n=8+8)
RegexpMatchEasy0_32-8       288ns ± 2%      277ns ± 2%  -3.61%  (p=0.000 n=8+8)
RegexpMatchEasy0_1K-8      1.66µs ± 1%     1.69µs ± 2%  +2.21%  (p=0.001 n=7+7)
RegexpMatchEasy1_32-8       334ns ± 1%      305ns ± 2%  -8.86%  (p=0.000 n=8+8)
RegexpMatchEasy1_1K-8      2.14µs ± 2%     2.15µs ± 0%    ~     (p=0.099 n=8+8)
RegexpMatchMedium_32-8     13.3ns ± 1%     13.3ns ± 0%    ~     (p=1.000 n=7+7)
RegexpMatchMedium_1K-8     81.1µs ± 3%     80.7µs ± 1%    ~     (p=0.955 n=7+8)
RegexpMatchHard_32-8       4.26µs ± 0%     4.26µs ± 0%    ~     (p=0.933 n=7+8)
RegexpMatchHard_1K-8        124µs ± 0%      124µs ± 0%  +0.31%  (p=0.000 n=8+8)
Revcomp-8                  14.7ms ± 2%     14.5ms ± 1%  -1.66%  (p=0.003 n=8+8)
Template-8                  197ms ± 2%      200ms ± 3%  +1.62%  (p=0.021 n=8+8)
TimeParse-8                1.33µs ± 1%     1.30µs ± 1%  -1.86%  (p=0.002 n=8+8)
TimeFormat-8               3.04µs ± 1%     3.02µs ± 0%  -0.60%  (p=0.000 n=8+8)

name                     old speed      new speed       delta
GobDecode-8              47.6MB/s ± 1%   46.5MB/s ± 1%  -2.28%  (p=0.000 n=8+8)
GobEncode-8              48.1MB/s ± 0%   48.6MB/s ± 1%  +1.02%  (p=0.000 n=8+7)
Gzip-8                   28.1MB/s ± 1%   29.0MB/s ± 0%  +2.97%  (p=0.000 n=8+8)
Gunzip-8                  178MB/s ± 1%    179MB/s ± 2%    ~     (p=0.694 n=7+8)
JSONEncode-8             38.4MB/s ± 1%   39.4MB/s ± 0%  +2.67%  (p=0.001 n=7+7)
JSONDecode-8             14.3MB/s ± 2%   14.2MB/s ± 1%  -0.81%  (p=0.043 n=8+7)
GoParse-8                6.12MB/s ± 1%   5.99MB/s ± 1%  -2.00%  (p=0.000 n=8+8)
RegexpMatchEasy0_32-8     111MB/s ± 2%    115MB/s ± 2%  +3.77%  (p=0.000 n=8+8)
RegexpMatchEasy0_1K-8     618MB/s ± 1%    604MB/s ± 2%  -2.16%  (p=0.001 n=7+7)
RegexpMatchEasy1_32-8    95.7MB/s ± 1%  105.1MB/s ± 2%  +9.76%  (p=0.000 n=8+8)
RegexpMatchEasy1_1K-8     479MB/s ± 2%    477MB/s ± 0%    ~     (p=0.105 n=8+8)
RegexpMatchMedium_32-8   75.2MB/s ± 1%   75.2MB/s ± 0%    ~     (p=0.247 n=7+7)
RegexpMatchMedium_1K-8   12.6MB/s ± 3%   12.7MB/s ± 1%    ~     (p=0.538 n=7+8)
RegexpMatchHard_32-8     7.52MB/s ± 0%   7.52MB/s ± 0%    ~     (p=0.968 n=7+8)
RegexpMatchHard_1K-8     8.26MB/s ± 0%   8.24MB/s ± 0%  -0.30%  (p=0.001 n=8+8)
Revcomp-8                 173MB/s ± 2%    176MB/s ± 1%  +1.68%  (p=0.003 n=8+8)
Template-8               9.85MB/s ± 2%   9.69MB/s ± 3%  -1.59%  (p=0.021 n=8+8)

Fixes   #39303
Updates #38740

Change-Id: I0a5f87bfda679f66414c0041ace2ca2e28363f36
Reviewed-on: https://go-review.googlesource.com/c/go/+/236637
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-06-09 15:50:33 +00:00
Bryan C. Mills cacac8bdc5 cmd/dist: do not unset GOROOT_FINAL prior to running tests
Also do not unset it by default in the tests for cmd/go.

GOROOT_FINAL affects the GOROOT value embedded in binaries,
such as 'cmd/cgo'. If its value changes and a build command
is performed that depends on one of those binaries, the binary
would be spuriously rebuilt.

Instead, only unset it in the specific tests that make assumptions
about the GOROOT paths embedded in specific compiled binaries.
That may cause those tests to do a little extra rebuilding when
GOROOT_FINAL is set, but that little bit of extra rebuilding
seems preferable to spuriously-stale binaries.

Fixes #39385

Change-Id: I7c87b1519bb5bcff64babf1505fd1033ffa4f4fb
Reviewed-on: https://go-review.googlesource.com/c/go/+/236819
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-06-09 02:49:06 +00:00
Ian Lance Taylor e64675a79f os: always check for EINTR in calls to open
For #11180
For #20400
For #39237

Change-Id: I8de97517c8f92c08f0c8a51f651a17e31617979b
Reviewed-on: https://go-review.googlesource.com/c/go/+/236997
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-06-08 22:06:39 +00:00
Russ Cox 2cd2ff6f56 all: avoid awkward wording from CL 236857
CL 236857 removed all uses of whitelist/blacklist, which is great.
But it substituted awkward phrasing using allowlist/blocklist,
especially as verbs or participles. This CL uses more standard English,
like "allow the function" or "blocked functions" instead of
"allowlist the function" or "blocklisted functions".

Change-Id: I9106a2fdbd62751c4cbda3a77181358a8a6d0f13
Reviewed-on: https://go-review.googlesource.com/c/go/+/236917
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-08 21:36:04 +00:00
Bryan C. Mills 8891b82332 cmd/go: remove a bogus assertion in mod_convert_dep
The removed line assumed that the script's WORK directory is not a
child of any directory containing version-control metadata.
While that assumption does hold in most cases, it does not hold when,
for example, $TMPDIR is $HOME/tmp and $HOME/.git/config exists.

A similar situation may or may not arise when using
golang.org/x/build/cmd/release. Either way, the assertion is incorrect
and was interfering with local testing for #39385.

Updates #39385
Fixes #39431

Change-Id: I67813d7ce455aa9b56a6eace6eddebf48d0f7fa6
Reviewed-on: https://go-review.googlesource.com/c/go/+/236818
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-06-08 19:02:07 +00:00
Austin Clements 886caba73c runtime: always mark span when marking an object
The page sweeper depends on spans being marked if any object in the
span is marked, but currently only greyobject does this.
gcmarknewobject and wbBufFlush1 also mark objects, but neither set
span marks. As a result, if there are live objects on a span, but
they're all marked via allocation or write barriers, then the span
itself won't be marked and the page reclaimer will free the span,
ultimately leading to memory corruption when the memory for those live
allocations gets reused.

Fix this by making gcmarknewobject and wbBufFlush1 also mark pages.

No test because I have no idea how to reliably (or even unreliably)
trigger this.

Fixes #39432.

Performance is a wash or very slightly worse. I benchmarked the
gcmarknewobject and wbBufFlush1 changes independently and both showed
a slight performance improvement, so I'm going to call this noise.

name                                old time/op  new time/op  delta
BiogoIgor                            15.9s ± 2%   15.9s ± 2%    ~     (p=0.758 n=25+25)
BiogoKrishna                         15.7s ± 3%   15.7s ± 3%    ~     (p=0.382 n=21+21)
BleveIndexBatch100                   4.94s ± 3%   5.07s ± 4%  +2.63%  (p=0.000 n=25+25)
CompileTemplate                      204ms ± 1%   205ms ± 1%  +0.43%  (p=0.000 n=21+23)
CompileUnicode                      77.8ms ± 1%  78.1ms ± 1%    ~     (p=0.130 n=23+23)
CompileGoTypes                       731ms ± 1%   733ms ± 1%  +0.30%  (p=0.006 n=22+22)
CompileCompiler                      3.64s ± 2%   3.65s ± 3%    ~     (p=0.179 n=24+25)
CompileSSA                           8.44s ± 1%   8.46s ± 1%  +0.30%  (p=0.003 n=22+23)
CompileFlate                         132ms ± 1%   133ms ± 1%    ~     (p=0.098 n=22+22)
CompileGoParser                      164ms ± 1%   164ms ± 1%  +0.37%  (p=0.000 n=21+23)
CompileReflect                       455ms ± 1%   457ms ± 2%  +0.50%  (p=0.002 n=20+22)
CompileTar                           182ms ± 2%   182ms ± 1%    ~     (p=0.382 n=22+22)
CompileXML                           245ms ± 3%   245ms ± 1%    ~     (p=0.070 n=21+23)
CompileStdCmd                        16.5s ± 2%   16.5s ± 3%    ~     (p=0.486 n=23+23)
FoglemanFauxGLRenderRotateBoat       12.9s ± 1%   13.0s ± 1%  +0.97%  (p=0.000 n=21+24)
FoglemanPathTraceRenderGopherIter1   18.6s ± 1%   18.7s ± 0%    ~     (p=0.083 n=23+24)
GopherLuaKNucleotide                 28.4s ± 1%   29.3s ± 1%  +2.84%  (p=0.000 n=25+25)
MarkdownRenderXHTML                  252ms ± 0%   251ms ± 1%  -0.50%  (p=0.000 n=23+24)
Tile38WithinCircle100kmRequest       516µs ± 2%   516µs ± 2%    ~     (p=0.763 n=24+25)
Tile38IntersectsCircle100kmRequest   689µs ± 2%   689µs ± 2%    ~     (p=0.617 n=24+24)
Tile38KNearestLimit100Request        608µs ± 1%   606µs ± 2%  -0.35%  (p=0.030 n=19+22)
[Geo mean]                           522ms        524ms       +0.41%

https://perf.golang.org/search?q=upload:20200606.4

Change-Id: I8b331f310dbfaba0468035f207467c8403005bf5
Reviewed-on: https://go-review.googlesource.com/c/go/+/236817
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2020-06-08 17:09:33 +00:00
Roland Shoemaker 5b9304e0be crypto/x509: match RFC suggested SKID generation method
Rather than hashing the encoding of the SPKI structure, hash the
bytes of the public key itself.

Fixes #39429

Change-Id: I55a0f8f08ab1f1b5702590b47d8b9a92d1dbcc1f
Reviewed-on: https://go-review.googlesource.com/c/go/+/236878
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-06-08 16:09:45 +00:00
Dmitri Shuralyov bb8901456c cmd/internal/moddeps: don't skip directories if there are unusual files
Previously, if there was a non-directory file with the name vendor or
testdata in the Go source tree, it was possible for some directories
to be skipped by filepath.Walk performed in findGorootModules.

As unusual and unlikely as such non-directory files are, it's better
to ensure all directories are visited, and all modules in the GOROOT
source tree are found.

This increases confidence that tests relying on findGorootModule
will not have unexpected false negatives.

For #36851.
For #36907.

Change-Id: I468e80d8f57119e2c72d546b3fd1e23c31fd6e6c
Reviewed-on: https://go-review.googlesource.com/c/go/+/236600
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-06-08 15:44:05 +00:00
Dmitri Shuralyov ee379d2b08 all: treat all files as binary, but check in .bat with CRLF
This is a followup to CL 96495.

It should be simpler and more robust to achieve .bat files having
CRLF line endings by treating it as a binary file, like all other
files, and checking it in with the desired CRLF line endings.

A test is used to check the entire Go tree, short of directories
starting with "." and named "testdata", for any .bat files that
have anything other than strict CRLF line endings. This will help
catch any accidental modifications to existing .bat files or check
ins of new .bat files.

Importantly, this is compatible with how Gerrit serves .tar.gz files,
making it so that CRLF line endings are preserved.

The Go project is supported on many different environments, some of
which may have limited git implementations available, or none at all.
Relying on fewer git features and special rules makes it easier to
have confidence in the exact content of all files. Additionally, Go
development started in Subversion, moved to Perforce, then Mercurial,
and now uses Git.¹ Reducing its reliance on git-specific features will
help if there will be another transition in the project's future.

There are only 5 .bat files in the entire Go source tree, so a new one
being added is a rare event, and we prefer to do things in Go instead.
We still have the option of improving the experience for developers by
adding a pre-commit converter for .bat files to the git-codereview tool.

¹ https://groups.google.com/d/msg/golang-dev/sckirqOWepg/YmyT7dWJiocJ

Fixes #39391.
For #37791.

Change-Id: I6e202216322872f0307ac96f1b8d3f57cb901e6b
Reviewed-on: https://go-review.googlesource.com/c/go/+/236437
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-06-08 15:31:43 +00:00
Filippo Valsorda 608cdcaede all: replace usages of whitelist/blacklist and master/slave
There's been plenty of discussion on the usage of these terms in tech.
I'm not trying to have yet another debate. It's clear that there are
people who are hurt by them and who are made to feel unwelcome by their
use due not to technical reasons but to their historical and social
context. That's simply enough reason to replace them.

Anyway, allowlist and blocklist are more self-explanatory than whitelist
and blacklist, so this change has negative cost.

Didn't change vendored, bundled, and minified files. Nearly all changes
are tests or comments, with a couple renames in cmd/link and cmd/oldlink
which are extremely safe. This should be fine to land during the freeze
without even asking for an exception.

Change-Id: I8fc54a3c8f9cc1973b710bbb9558a9e45810b896
Reviewed-on: https://go-review.googlesource.com/c/go/+/236857
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Khosrow Moossavi <khos2ow@gmail.com>
Reviewed-by: Leigh McCulloch <leighmcc@gmail.com>
Reviewed-by: Urban Ishimwe <urbainishimwe@gmail.com>
2020-06-08 01:03:14 +00:00
Brad Fitzpatrick 3c35eec618 runtime: clarify wording/grammar on GODEBUG=invalidptr
Change-Id: Ia06b6be262922991bae3528e7b061d1db9e4c3c0
Reviewed-on: https://go-review.googlesource.com/c/go/+/236679
Reviewed-by: Austin Clements <austin@google.com>
2020-06-05 19:11:07 +00:00
Russ Cox b6faed1326 cmd/asm, cmd/compile, doc: document -spectre flags
Most of the docs are in the new wiki page
https://golang.org/wiki/Spectre.

Updates #37419.

Change-Id: I6e8f76670593c089de895e1665b41d874f879df9
Reviewed-on: https://go-review.googlesource.com/c/go/+/236599
Reviewed-by: Austin Clements <austin@google.com>
2020-06-05 16:54:48 +00:00
Roland Shoemaker 60cbff6f19 crypto/x509: match cgo and Apple behavior in domain fallback of macOS roots
This change makes the direct call darwin loadSystemRoots implementation
match the existing cgo implementation, which in turn _mostly_ matches
the Apple implementation. The main change here is that when
SecTrustSettingsCopyTrustSettings the error is ignored, and can either
cause a fallback to check admin trust settings, or cause the
certificate to be marked kSecTrustSettingsResultUnspecified.

As well as updating the implementation to match the cgo one, this
change also updates the documentation of how the fallbacks work and
how they match the Apple implementations. References are made to the
Apple source where appropriate. This change does not update the
existing comments in the cgo implementation, since the goal is to
delete that code once the direct call implementation is matured.

Updates #38888

Change-Id: Id0344ea9d2eede3b715f341e9cbd3c1c661b7a90
Reviewed-on: https://go-review.googlesource.com/c/go/+/233360
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-06-05 16:50:47 +00:00
Tobias Klauser 4489f4bc84 cmd/compile/internal: gofmt
Change-Id: I67a4375d8eb976d48e4a57e482390f473658b4b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/236457
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-05 05:00:28 +00:00
Katie Hockman fb86c70bda crypto/tls: set CipherSuite for VerifyConnection
The ConnectionState's CipherSuite was not set prior
to the VerifyConnection callback in TLS 1.2 servers,
both for full handshakes and resumptions.

Change-Id: Iab91783eff84d1b42ca09c8df08e07861e18da30
Reviewed-on: https://go-review.googlesource.com/c/go/+/236558
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-06-04 20:16:53 +00:00
Austin Clements 07ced37013 syscall: document float arguments and results on windows/amd64
Updates #6510.
Updates #37273.

Change-Id: Id2732fcff0a0c5e4a324cd33ef995c7e528f5e1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/236562
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-06-04 17:50:16 +00:00
Austin Clements 7e47757324 syscall: hide internal comment from Syscall documentation
There's a comment on the Syscall function that's supposed to be an
internal implementation note, but since it's not separated from the
function definition, it appears in godoc. Add a blank line to prevent
this.

Change-Id: Iba307f1cc3844689ec3c6d82c21d441852e35bca
Reviewed-on: https://go-review.googlesource.com/c/go/+/236561
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-06-04 17:50:15 +00:00