Commit Graph

44212 Commits

Author SHA1 Message Date
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