Commit Graph

44180 Commits

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