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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>