Commit Graph

44364 Commits

Author SHA1 Message Date
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
Robert Griesemer 4efa3ddb87 go/types: make type bound instantiation optional if there's only one type parameter
This simplifies the use of parameterized interfaces as type bounds.
For example, given:

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

we can use this interface as a type bound with or without instantiation
in a type parameter list:

	func _(type T Bound(T))	...  // with explicit instantiation
	func _(type T Bound) ...     // instantiation left away

In the latter example, Bound is syntactic sugar for Bound(T).

In general, in a type parameter list, instantiation of an interface
type bound is optional iff the the type bound applies to exactly one
type parameter and the type bound expects exactly one type argument.

Change-Id: I0e820a0e214427cce6397069c1d5268494096812
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/728411
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer 7c99cab23e go/types: better error when accessing non-existent methods of type parameters
Track the contract or type name specifying a type bound
in the corresponding interface and use that information
for more specific error messages.

Change-Id: I8aa3458addd1e8446a3a5766a03fd50e338fc8ed
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/727599
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer e871c64307 go/types: updated README and NOTES
Change-Id: Id80b2a63ab7d358b5818730dfcc75f9e8b6e48a5
2020-06-13 12:24:50 -07:00
Robert Griesemer 4843595d7f go/types: implement specific converter methods for *instance types
This is fixing a known issue (see below) and many unknown issues:
An *instance type may legally represent any kind of type after
instantiation.

Given the declaration:

	type T(type P) P

T(int) is now a valid constant type, and T([]int) is a valid
slice type.

Also, fixed the implementation of isTyped/isUntyped which caused
types to expand prematurely.

Change-Id: Ic71c7252e3b066b0f97c2f1892cf20b2c4c2ef98
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/723717
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer 37801e2c49 go/types: don't forget *contractType in sanitation code (fix cmd/go2go test)
Change-Id: Ie736a1dba7aa73641d2869bc3a6c36c5400d6c09
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/724470
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer bfe0923cc7 go/types: sanitize Info.Defs/Uses and add tests
Change-Id: I4c7003a88009f142ca674c8ea6b138a444a2bac5
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/722935
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer 975f454e6a go/types: report error for infinite generic types
To make this work for embedded fields, delay checking of
embedded field properties to the end of type checking to
avoid expanding possibly incomplete types.

Change-Id: I0ff7f86398deb05dcd4d0d5b5f94309d63db7a67
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/723398
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Ian Lance Taylor c2d160bafc cmd/go2go: add List example
Change-Id: Id12b3489c2cd17f48d918563b002fe704db6a177
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/723255
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer 4ba2f1d5fd go/types: fix type substitution
When instantiating a type, cache a new version with a valid (non-nil)
underlying type so that we don't run into a missing underlying type
if instantiation is self-recursive.

Added more tests, also for issues found while debugging.

Change-Id: I520a4f71e60bd9020977276db078582d41a677f1
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/723252
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer 4b95e48766 api: update except.txt to accomodate for bigger types.Type
Fixing API check to make it pass. Adding the extra methods
to types.Type is not backward-compatible, but this is a
prototype, so we don't care too much for now.

Passes all.bash.

Change-Id: I7d1ab5d4eb2d69d10302e2aed2718b4a03ab36cc
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/722390
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer 67da60ed50 go/types: sanitize types.Info maps
Don't export Instance anymore (renamed to instance).

Added sanitizer that expands any *instance type
into an instantiated *Named type as a last pass
of a type checker run.

Note: For now only the Info.Types and Info.Inferred map
      entries are sanitized to make go2go tests pass.

Passes all.bash except for api check.

Change-Id: I2a937b0e7e94c597dfd58af23c314cd20b3f7776
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/722383
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer 6300d5adf9 go/types: instantiate generic types lazily
Until now, a generic type instantiation T(P1, P2, ...) was evaluated
eagerly, that is the formal type parameters of T were substituted with
the actual type arguments P1, P2, ... upon encountering that expression.
This caused problems when the type being instantiated wasn't fully set
up yet (i.e., it's declaration wasn't completely processed yet).

With this CL, a type expression of the form T(P1, P2, ...) is
represented via the new "syntactic" Instance type. The instantiation
is not checked eagerly, and no substitution takes place. Only when
needed, is an Instance type "expanded"; this is typically necessary
when operations on the instantiated type need to be performed. The
new exported function Expand(Type) Type takes a type and expands it
(i.e., instantiates it) if the argument was an Instance type. The
type string of an Instance type is prefixed with a '#' as in #T(int),
to distinguish it from the type string of the expanded type T(int).

Operations on types usually require the underlying type, and thus a
new method Type.Under returns the fully expanded underlying type of
a type (incl. following of forwarding chains). Type.Underlying remains
unchanged for backward-compatibility and use by clients expecting the
old behavior.

This CL is also a first step towards more lazy evaluation and checking
of properties that are better deferred to the end, when all types are
fully set up. For instance, when collecting embedded interfaces, we
now just collect the types (they may be Instances of generic interfaces)
and only expand and check if they are indeed interfaces when interfaces
are completed.

This new lazy approach should also permit the (future) introduction of
an Alias type to cleanly track alias types.

Passes go/types tests (but not all.bash).

Change-Id: Id5fb0e2fa497f506c2e938ca6a6606835c8a8b20
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/719901
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer 63f4460f70 go/types: implement type conversion methods
Provide easy accessors to a type's underlying type. Instead of

	if t, _ := typ.Underlying().(*XXX); t != nil { ... }

we can now write

	if t := typ.XXX(); t != nil { ... }

where XXX is a type such as Basic, Array, Slice, Pointer, etc.
This removes a type assertion in all cases where typ is not a *Named
type and the code is easier to read.

Also, made Named.Underlying more robust by tracking cycles and nil
underlying types.

The Named.Underlying change is a first step towards making type
checking more lazy which eventually should permit dealing with
cycles that we cannot yet handle properly.

This change briefly breaks some external code (gcimporter, gccgoimporter)
due to the change in semantics of type.Underlying. This will be fixed by
the next change.

Passes go/types tests (but not all.bash).

Change-Id: I493a949e554da6f2a944e7e9b1f1f6f38f597042
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/717606
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor 04f9e20db3 go/build: permit go/go2go to depend on internal/goroot
Change-Id: I22ee40f6ea529628bebc4e21ba2ae7789f3f6b60
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/721561
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor 39dc66f9c2 go/types: improve contract error messages
If a type or type parameter does not satisfy a contract because the
type or type constraint is not found in the list of type constraints,
change
    T does not satisfy C(T) (T type constraint int not found in interface{type ...})
to
    T does not satisfy C(T) (T type constraint int not found in [type ...])
Also, before this change, if the contract had any required methods,
those were also listed; now we just list the type constraints.

If a defined type does not satisfy a contract because the underlying
type is not found in the list of type constraints, change
    MyUint does not satisfy C(T) (MyUint not found in interface{type ...})
to
    MyUint does not satisfy C(T) (uint not found in [type ...])
That is, when describing the type that is not found, use the underlying type,
not the defined type.

Change-Id: I345836c44921e2e13e7f02041839b5eb4df75c45
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/718718
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor 7d185f0ba6 go/types: improve contract error messages
If a type parameter that has no type constraints is trying to satisfy
a contract that does have type constraints, change
    T does not satisfy C(T) (missing type int)
to
    T does not satisfy C(T) (T has no type constraints)

If a type parameter that has type constraints is trying to satisfy a
contract that has type constraints, but the parameter has type
constraints that the contract does not permit, change
    T does not satisfy C(T) (missing type int)
to
    T does not satisfy C(T) (T type constraint int not found in interface{type ...}

Change-Id: I3bd4f59b0544b382399d9b9d891a509ce62f56c3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/718426
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer 67b6f218e9 go/types: fix type bound check
A type argument with an empty type list bound never satisfies
a type parameter with a non-empty type list bound.

Change-Id: Ic4206f74fd4625b4207baa28bdb0de0fc669b37e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/717296
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Jonathan Amsterdam 7a57f4d76e slices: fix Equal contract
slices.Equal only requires comparable, not Ordered.

Change-Id: I0150f1370e478aaa33bbd8788a1f9c9d33b85e06
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/716483
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer 63d4750592 go/types: avoid crashes when printing/tracing invalid interfaces
Rewrite Interface.Empty to not be dependent on an interface being
complete. Be careful when printing invalid interfaces.

This fixes a couple of crashes when running tests with -v (trace)
mode enabled.

Change-Id: I4be416eac7e3fae83c08608ed74bf3987b2a7457
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/716089
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer a89350ee85 go/types: interfaces are comparable (bug fix)
Also: Updated NOTES (unrelated).

Change-Id: I12ce0465e408920d4cd430ab529f346281f4ac64
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/716118
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor 2b5e8d70c0 go/go2go: parse Go1 packages using go/types
When a Go2 package imports a Go1 package, then if the Go1 package is
in the standard library use the default importer, but otherwise
parse the package ourselves by recursively calling go/types.
This supports a Go2 package importing a Go1 package that imports
a Go2 package.

Change-Id: I8906d8ea5b81e6239652c0e46de79b5c1b59cfcd
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/716063
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor c2d8b59433 go/go2go: record types of instantiated AST types
Otherwise we don't know the type of an instantiated type in an
instantiated function.

Change-Id: If7eb75dd920a3c9fc1b6992addcd3b91b6d425a9
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/715718
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00