Commit Graph

44386 Commits

Author SHA1 Message Date
Ian Lance Taylor 09a02162ee test: add a couple of pointer method test cases
Change-Id: If91c8a61fcda93eeb5affe51ef8f537736a28bce
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/768839
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:54 -07:00
Robert Griesemer d65e7b7b0f go/types: take pointer designation of type parameters into account
There are still a couple of issues with pointer type parameters
that have constraints containing type lists, but at least as far
as method constraints are concerned the code is now matching the
design.

Passes all.bash.

Change-Id: I7b7ad9e03bc6ed159dca2343d3fa6a04fc188659
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/765805
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor 730419578e go/go2go: handle references to embedded instantiated types
Change-Id: I4f54a7820483e6b79169d319301943063a26ac53
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/767868
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor a685620169 test: catch go2go panics in test runner
Change-Id: Ie59118941f732fc9111e77dcf8422d1e1afcd563
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/767865
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor 3df5cb5c52 go/go2go: improve handling of self-referential types
Also, resolve types when looking up instantiations.

Change-Id: I8b2e976d9c0d313fe3c1dd9dafce41dcb59b33bf
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/767864
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor 73c4e1f380 test: add AbsDifference test case from design draft
Change-Id: I184ca0949200064947a3c974f8aa9c3738d93e33
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/765523
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer 7307dda747 go/types: report error if type list contains duplicate entries
Passes all.bash.

Change-Id: I9a795c931100af662c9c62223d4e4ca0103d2af3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/765675
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer 61c4506052 go/types: permit at most one type list in an interface (excluding embeddings)
Change-Id: Ib5f658341a746d4ac04852b558864bdb1ae3292f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/765552
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor 44579f1e8e cmd/go2go: lock map in metrics Count methods
Change-Id: I4a5e74a3b13ce5ac29f6fedc6d6a6da1dabcc33b
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/765662
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer 468a8d7345 go/types: remove support for contracts
Also: Some additions/corrections to the NOTES file.

Passes all.bash.

Change-Id: I580c7f6f9769b8108e6d8e5a3473b92362eb246d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/764658
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer 3ec98e186b go/types: implement intersection for embedded type lists
Implement intersection of (sum) type lists so we can correctly
compute a type bound's type list if a type bound embeds other
type bounds (interfaces).

For type bounds A, B we want to preserve the property

   "A embeds B" implies "A satisfies B"

Because type bounds are interfaces this is already true when
considering method sets only. But type bounds also may contain
type lists, and for this property to be true, type lists must
be intersected.

The intersection of two non-empty type lists with different types
may be the empty list (nil), which means that no type satisfies
the type bound. Because we already use nil to indicate the absence
of a type list (i.e., ignoring methods, any type satisfies the type
bound) we need a separate representation. This CL introduces two
new internal types, bottom and top, which stand for "no type" and
"any type" (they represent the bottom and top of the type lattice).
Since nil is already used for what should be the top type, and we
rely on the fact that the zero value for an Interface type is a
valid empty interface, we keep using nil in type lists to indicate
the top type. Eventually we may want to clean this up.

This CL also refines the understanding of type parameters: The
underlying type of a type parameter must be itself (it cannot be
defined by the associated type bound as assumed in a prior CL).
Consider the declaration

	type T(type P) P

which declares a new defined, generic type. The question is, what
is the underlying type of T, i.e., the type which T represents
with a (new) name? (This type is stored in the underlying field
of a Named type.) The only possible answer is P, because otherwise
instantiation of T with any other type Q wouldn't produce that type
Q.

Thus, when checking if an operation is applicable on a value of type
parameter type, we need to explicitly get the type parameter's
"operational type" which is defined by the type parameter's type
bound; specifically the type bounds's type list (which is represented
as a sum type).

Passes all.bash.

Change-Id: Iad7e99884fd8f40a70f75c6470f1817d74994f48
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/764158
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer 690131b027 go/types: add Config flag to enable method type parameters
The type-checker type-checks method type parameters like
function type parameters without any extra work. But the
current design draft does not permit them and the go2go
translator does not expect them.

Add a flag to enable them for type checker tests, but do
not accept them by default. Instead, type-check but report
an error.

Passes all.bash.

Change-Id: Iec02f4a951a3faccd2409d97d48bc4dd4536a750
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/764012
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer d3a2e0e245 go/types: disable type assertions on variables of generic type
This matches the latest design draft. It's unclear what the
correct approach is here, and there is an easy work-around:
just assign to an interface variable first.

Passes all.bash.

Change-Id: Ic1d6ed3de6333505e2044a318ea05fb984b408cf
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/764001
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor 35eefe6b79 test/gen: add some FromStrings test cases
These are from the latest version of the design draft.

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

Change-Id: I057875820d8250012c06faeabda4637f0585b6f8
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/763941
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor a6b6ca6dc9 cmd/go2go: use consistent spacing in package doc
Change-Id: Ic3b03820ebfb6c4b0881b18663f46b64227ea93d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/763940
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer 1bc39b26bf go/types: treat type bound type lists as underlying types of type parameters
If a type parameter's type bound contains a type list, we can view that as
the underlying type(s) of the type parameter. If there is no type list the
underlying type of a type parameter is itself.

This approach resolves several open issues and clarifies the relationship
between type bound type lists and the type parameters. It also provides a
sensible definition for the underlying type of a type parameter (it will
take some more experimentation to see if this view is holding up within
the axiomatic framework of generic Go).

To implement this new view, in this CL we introduce the (implementation-
internal) notion of a sum type. A sum type is a set of two or more
distinct types. With this, we can view an interface with a type list as
an interface that provides a _single_ underlying type, which may be a
sum type.

Defining the underlying type of a type parameter this way enables a lot
of so far failing tests to work. In other instances, we have to implement
type-checking for sum types and can ignore the connection with generic code.
This simplifies the implementation and leads to a better separation of
concerns.

As part of this change:

- Several test cases in testdata/todos.go2 now work as expected
  and move to testdata/issues.go2.

- Fix, clarify, and add various comments.

Passes all.bash.

Change-Id: I25a435b2ccd0c9f9fda5369bc998e52fe120ee0b
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/762619
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer cdabf71580 cmd/compile/internal/types2: disallow interfaces with type constraints as variable types
Port of corresponding go/types change:
https://team-review.git.corp.google.com/c/golang/go2-dev/+/760779

Change-Id: Ibdb9b61bb99f34481e2e466b0d024fb14bf1add0
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/760899
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer 25675854ad go/types: disallow interfaces with type constraints as variable types
Passes all.bash.

Change-Id: I0e080e740f5a70f480859196e34b96d47f914755
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/760779
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer 3650c7d512 cmd/compile/internal/types2: fix numeric conversions between type parameter types
This is a simple port of the corresponding go/types change in
https://team-review.git.corp.google.com/c/golang/go2-dev/+/759562.

Also: Added missing newline at end of go/types/testdata/issues.go2.
Change-Id: I8301488d46fa046c0a1f52b47d889864ee094f87
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/759563
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer 0fa4f81317 go/types: fix numeric conversions between type parameter types
The implementation of conversions T(x) between integers and floating-point
numbers checks that both T and x have either integer or floating-point
type. When the type of T or x is a type parameter, the respective simple
predicate disjunction in the implementation was wrong because if a type list
contains both an integer and a floating-point type, the type parameter is
neither an integer or a floating-point number.

Change-Id: I007aa956007ab1a0228e0ee2fca05804686b404c
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/759562
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer 716d51681b go/{ast,parser,types}: remove support for "underlying" in type lists again
Match the latest generics design draft.

Passes all.bash.

Change-Id: I81880a40e3532cd4e28b753472379e3dfed2f362
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/759561
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer fd86e2cab9 cmd/compile/internal/syntax: accept embedded instantiated types in interfaces
Add some smoke tests.

Passes all.bash.

Change-Id: I29ef9a0a8e8b18a6a3c5af151934d38622067857
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/756090
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer cb7d43b2ea cmd/compile/internal/syntax: actually collect type list types (fix bug)
The existing code collected empty fields. Collect the actual
field and added type string test.

(This was not found before because the generic tests are still
disabled in this port because of different position information.)

Change-Id: I959711892aac3c8f7587a4025c4b32f1598f5df3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/756088
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer 8355f8a9ee cmd/compile/internal/{syntax, types2}: accept type parameter pointer designation
Accept but (for now) ignore the pointer designation.
This is a port of the relevant changes in go/types:

https://team-review.git.corp.google.com/c/golang/go2-dev/+/750582
https://team-review.git.corp.google.com/c/golang/go2-dev/+/751264

Passes all.bash.

Change-Id: I4767c3addc881691bebf22cb030fa578124b7db0
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/755797
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer 380193353c cmd/compile/internal/types2: make "make" work for generic types
This is a port of the equivalent changes in go/types
(https://team-review.git.corp.google.com/c/golang/go2-dev/+/755783).

Change-Id: I2533a76ea1c5662c93bfd76125946151aa80f660
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/755796
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer 188ddaf79c go/types: make "make" work for generic types
Passes all.bash.

Change-Id: I524878e0299e12633c633540cc8f76deab81ce48
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/755783
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Ian Lance Taylor 7116b1df5f cmd/go2go, go/go2go: use PathListSeparator
Don't assume that path lists use colon separators.

Fixes golang/go#39211

Change-Id: Ibce7295dcc290a7826ee6b25a06aa36b8e40f961
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/755784
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer 8df9c7a8fa go/types: make type bound instantiation optional if bound has one type parameter
If a type bound expects one type parameter, permit omitting explicit
instantiation of the type bound in a type parameter list. In that case,
the type bound is instantiated with each respective type parameter
and becomes that type bound for that type parameter.

For example, given:

	type Bound(type T) interface { ... }

the type parameter list:

	(type P, Q Bound)

is syntactic sugar for:

	(type P Bound(P), Q Bound(Q))

This is a generalization of the former change:

https://team-review.git.corp.google.com/c/golang/go2-dev/+/728411

Passes all.bash.

Change-Id: I0191dcf3fbccf6e777f01dfa8ccef5aba0310213
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/751267
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer c64ef0ed90 go/types: recognize (but for now ignore) pointer and "underlying" designations
1) Recognize pointer designation in type parameter lists.
2) Recognize "underlying" type designation in interface type lists.

Adjust a few tests.

Passes all.bash.

Change-Id: Ic33195f2802698f957cbbda1770c78dc4d8a5e2a
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/751264
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer 1be59591cc go/parser: accept "underlying type" lists in interfaces
A type list may now be preceeded with "underlying" "type":

interface {
    // type list
    underlying type int, int32, int64

    // method
    underlying(int) int32
}

Change-Id: I37ea2ce3ca0e56f1fc35542ae04481dc7665b17c
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/750491
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer f59b75aff6 go/parser: accept "untyped type" lists in interfaces
A type list may now be preceeded with "untyped" "type":

interface {
	// type list
	untyped type int, int32, int64

	// method
	untyped(int) int32
}

Passes all.bash.

Change-Id: I745c5f05ab5d6013d585da278b27e1eb781c0762
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/750483
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer 774de94abe go/parser: accept pointer type parameter marking
Accept type parameters marked with a '*' as in:

(type A, *B bound)

indicating that the Bound requires pointer methods for B.
The notation is accepted but not yet recorded in the AST.

While at it, clean up some residue in parameter parsing
and disable acceptance of contract notation.

Passes all.bash.

Change-Id: I8d0c4614322bfed885ab26ef2da65a57208a9552
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/750582
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Ian Lance Taylor 4b7067c133 cmd/go2go: rename testdata contracts to constraints
Change-Id: I52eaf2e87abc53b79b2fbcfcb156f093298341ef
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/750508
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:51 -07:00
Ian Lance Taylor db04e7cb2e go/go2go, cmd/go2go, test: rewrite example code to not use contracts
Don't emit interfaces that are type bounds in the generated .go file.

Change-Id: I9b0fd2f6041e9464147ad6d82d349fe894ea762d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/735474
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer e83c4715b0 cmd/compile/internal/types2: apply latest go/types changes
After rebasing on top of master, the go/types version of
this branch includes the latest changes of go/types in
the std library. Apply the same changes to types2.

(Created a CL containing the differences between the starting
point for types2 (commit 89463ec, which was a copy of a
prior go/types) and the current go/types, and then cherry-
picked those differences on top of types2.)

Passes all.bash.

Change-Id: I6137a476dc90f5dbd0b90e9fbe144dc7bc13a9e3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/748099
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer 75b401bccf cmd/compile/internal/types2: make go vet happy
Also, gofmt a few files.

Change-Id: Ie430556f5c1ae9c8acc24bbc5500a2579275fd39
2020-06-13 12:24:51 -07:00
Robert Griesemer 821d2a635c cmd/compile/internal/types: fix const/var decl handling and enable StdTest
Change-Id: Id06e34bcdfddf6bc0cd990b2eb3d0f1c6ccfdeb3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/747119
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer 3f276cd882 cmd/compile/internal/types2: make all tests of TestTypesInfo run
Change-Id: I02069af89e86b2bd5bf3c84e8f8119d84be0aad9
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/746891
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer e37af78043 cmd/compile: fix Formats test
Change-Id: I0c5b7e330fb77b4d2b87e93a3af149f0b35ed9fa
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/746630
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer 5887a08520 cmd/compile/internal/gc: report error when compiling generic code
The compiler can parse but not actually compile generic code.

Change-Id: Icfaa61811bdcc80f59d656a25c26db40b6fd7877
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/746626
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer 176a871ff3 cmd/compile/internal/types2: make tests depending on imports work
Passes most types2 tests, incl. type-checking of std library.
Passes all.bash.

Change-Id: I5d452ecb3decf1bdfee864c594e3f2a01525e548
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/744664
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer c0558e3405 cmd/compile/internal/importer: make importer work with types2
Passes all its tests.

Change-Id: I0ba20a284f08e10531976b6253e3c340bbd84dcd
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/744663
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer cdfaff44de cmd/compile/internal/importer: starting point for new importer
Make an exact copy of go/internal/gcimporter in
cmd/compile/internal/importer. Serves as starting
point for a types2-based importer.

Change-Id: Ib676794622bc1cb1614e396df6b391f374757cda
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/744662
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer 56162a1a5f cmd/compile/internal/types2: make type2 work with syntax package
Snapshot of work in progress.

- Entire package converted to use syntax package.
  (We still need to convert syntax.Operators to token.Tokens
  in some cases so we can use the go/constant package.)
- Some code is commented out and/or unimplemented.
- The functionality provided by eval.go, eval_test.go, gotype.go
  is not needed and was removed.
- Compiles cleanly and many tests run at this point.
- Skips tests that require import to work.

Passes all.bash.

Change-Id: I2f215d97c858c22058779a6a5b1a2065b51bd4af
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/741794
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer 73270217c8 cmd/compile/internal/types2: starting point for new type checker
Make an exact copy of go/types in cmd/compile/internal/types2.
Serves as starting point for a cmd/compile/internal/syntax-
based type checker, initially using the go/types logic.

Change-Id: Ide782fdaefd591b7757e54be5c16421bb8e935b2
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/741793
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer 90f286c307 cmd/compile/internal/syntax: record type parameters (don't just parse them)
Also: Distribute type parameter names if necessary.
Change-Id: I59d83c29548b62f21a65b225ee3e743c95287adc
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/744598
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer 5f8feb36c0 cmd/compile/internal/syntax: encode interface type lists more accurately
Encode an interface list element as a Field (like methods) but with
the special name "type" (no method can have that name as it is a
keyword). Types belonging to the same type list share the same name
pointer. This preserves full position information and removes the
need for another list in InterfaceType.

Change-Id: Ib7f02f7272078445546e47b394ed9e112dd5821f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/741894
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer d234c93a9b cmd/compile/internal/syntax: clear pragma at the right place (fix build)
The previous CL changed the parser.list implementation to not consume
the opening token anymore; this was changed so it could be used for
parsing type parameter lists which start with a "(" and a "type".

Consequently, parser.appendGroup was changed to consume the opening
"(" early, before parser.clearPragma was invoked. As a result, a
correctly placed pragma for the next declaration was consumed too
early, leading to an error with test/directive.go. Fixed.

Passes all.bash.

Change-Id: Ief2f71228697e5516ebdecb773fdc30438f1fa9f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/738661
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer 70f1138c60 cmd/compile/internal/syntax: accept Go2 syntax
Specifically, this change accepts now:

1) Type parameters in type and function declarations, such as:

	type B(type T) interface {
		m(T) T
	}

	func f(type T B) (list []T) T

2) Type instantiations:

	type T B(int)

3) Embedded instantiated types, with necessary extra parentheses:

	type T struct {
		(B(int))	// ()'s to distinguish from field B of type (int)
	}

	type T interface {
		(B(int))	// ()'s to distinguish from method B with int argument
	}

The compiler simply ignores the new constructs.

Change-Id: Iecb8354d3846d7a5786cbe7d92870d8a2d578133
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/736539
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer bc3ba78503 go/types: implemented AcceptContracts flag to enable/disable contracts
AcceptContracts is a global flag (api.go) to enable/disable contracts.
All go/types tests pass with the flag in either setting, i.e., all
go/types tests involving contracts have been rewritten or disabled.
To ensure the existing go2go code runs, AcceptContracts is set to true
for now.

If contracts are disabled, "comparable" is a predeclared interface
(without type parameters) rather than a predeclared contract (with
one type parameter).

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