]> Cypherpunks.ru repositories - gostls13.git/commit
[dev.typeparams] cmd/compile: support generic types (with stenciling of method calls)
authorDan Scales <danscales@google.com>
Thu, 11 Feb 2021 18:50:20 +0000 (10:50 -0800)
committerDan Scales <danscales@google.com>
Thu, 18 Feb 2021 22:37:06 +0000 (22:37 +0000)
commit20050a15fee5b03735d6a14fcd96c059a05e149c
treeebe294d807231d8d57b0d85a448488378f7fce4e
parent2ff1e05a4ce132dec2a640d9fa941c2d33f90c36
[dev.typeparams] cmd/compile:  support generic types (with stenciling of method calls)

A type may now have a type param in it, either because it has been
composed from a function type param, or it has been declared as or
derived from a reference to a generic type. No objects or types with
type params can be exported yet. No generic type has a runtime
descriptor (but will likely eventually be associated with a dictionary).

types.Type now has an RParam field, which for a Named type can specify
the type params (in order) that must be supplied to fully instantiate
the type. Also, there is a new flag HasTParam to indicate if there is
a type param (TTYPEPARAM) anywhere in the type.

An instantiated generic type (whether fully instantiated or
re-instantiated to new type params) is a defined type, even though there
was no explicit declaration. This allows us to handle recursive
instantiated types (and improves printing of types).

To avoid the need to transform later in the compiler, an instantiation
of a method of a generic type is immediately represented as a function
with the method as the first argument.

Added 5 tests on generic types to test/typeparams, including list.go,
which tests recursive generic types.

Change-Id: Ib7ff27abd369a06d1c8ea84edc6ca1fd74bbb7c2
Reviewed-on: https://go-review.googlesource.com/c/go/+/292652
Trust: Dan Scales <danscales@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
14 files changed:
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/noder/expr.go
src/cmd/compile/internal/noder/irgen.go
src/cmd/compile/internal/noder/stencil.go
src/cmd/compile/internal/noder/types.go
src/cmd/compile/internal/reflectdata/reflect.go
src/cmd/compile/internal/types/sizeof_test.go
src/cmd/compile/internal/types/type.go
src/cmd/compile/internal/types2/selection.go
test/typeparam/list.go [new file with mode: 0644]
test/typeparam/pair.go [new file with mode: 0644]
test/typeparam/stringable.go [new file with mode: 0644]
test/typeparam/struct.go [new file with mode: 0644]
test/typeparam/value.go [new file with mode: 0644]