aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types/type.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-01-28 17:43:18 -0800
committerDan Scales <danscales@google.com>2021-01-30 00:42:35 +0000
commit0aafd6912422570625414da6e5ed5ba2c371fcec (patch)
tree27788ad91dbfa27bbfbbe2239bd1c31aad2b8714 /src/cmd/compile/internal/types/type.go
parenta59cb5109d49ac0dc09337449b9c7760ecc66c0e (diff)
downloadgo-0aafd6912422570625414da6e5ed5ba2c371fcec.tar.gz
go-0aafd6912422570625414da6e5ed5ba2c371fcec.zip
[dev.typeparams] cmd/compile: start translating type params in noder2
Also, make some fmt changes so that the type parameters and the typeparam type are displayed in -W=2. You can now parse a simple generic function (but not generic calls or generic types) and print out the noder IR via 'go tool compile -G=2 -W=2 func.go' Change-Id: I1f070fc4a96174a447763ad37999e61c25905901 Reviewed-on: https://go-review.googlesource.com/c/go/+/287833 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Dan Scales <danscales@google.com> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types/type.go')
-rw-r--r--src/cmd/compile/internal/types/type.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go
index 1d6edcda47..8d07b88ecd 100644
--- a/src/cmd/compile/internal/types/type.go
+++ b/src/cmd/compile/internal/types/type.go
@@ -204,7 +204,8 @@ func (t *Type) SetRecur(b bool) { t.flags.set(typeRecur, b) }
func (t *Type) Kind() Kind { return t.kind }
// Sym returns the name of type t.
-func (t *Type) Sym() *Sym { return t.sym }
+func (t *Type) Sym() *Sym { return t.sym }
+func (t *Type) SetSym(sym *Sym) { t.sym = sym }
// Underlying returns the underlying type of type t.
func (t *Type) Underlying() *Type { return t.underlying }
@@ -285,7 +286,7 @@ type Func struct {
Receiver *Type // function receiver
Results *Type // function results
Params *Type // function params
- Tparams *Type // type params of receiver (if method) or function
+ TParams *Type // type params of receiver (if method) or function
pkg *Pkg
@@ -512,6 +513,8 @@ func New(et Kind) *Type {
t.Extra = new(Tuple)
case TRESULTS:
t.Extra = new(Results)
+ case TTYPEPARAM:
+ t.Extra = new(Interface)
}
return t
}
@@ -769,10 +772,12 @@ func (t *Type) wantEtype(et Kind) {
}
func (t *Type) Recvs() *Type { return t.FuncType().Receiver }
+func (t *Type) TParams() *Type { return t.FuncType().TParams }
func (t *Type) Params() *Type { return t.FuncType().Params }
func (t *Type) Results() *Type { return t.FuncType().Results }
func (t *Type) NumRecvs() int { return t.FuncType().Receiver.NumFields() }
+func (t *Type) NumTParams() int { return t.FuncType().TParams.NumFields() }
func (t *Type) NumParams() int { return t.FuncType().Params.NumFields() }
func (t *Type) NumResults() int { return t.FuncType().Results.NumFields() }
@@ -1648,6 +1653,15 @@ func NewInterface(pkg *Pkg, methods []*Field) *Type {
return t
}
+// NewTypeParam returns a new type param with the given constraint (which may
+// not really be needed except for the type checker).
+func NewTypeParam(pkg *Pkg, constraint *Type) *Type {
+ t := New(TTYPEPARAM)
+ t.methods = constraint.methods
+ t.Extra.(*Interface).pkg = pkg
+ return t
+}
+
// NewSignature returns a new function type for the given receiver,
// parametes, results, and type parameters, any of which may be nil.
func NewSignature(pkg *Pkg, recv *Field, tparams, params, results []*Field) *Type {
@@ -1669,7 +1683,7 @@ func NewSignature(pkg *Pkg, recv *Field, tparams, params, results []*Field) *Typ
}
ft.Receiver = funargs(recvs, FunargRcvr)
- ft.Tparams = funargs(tparams, FunargTparams)
+ ft.TParams = funargs(tparams, FunargTparams)
ft.Params = funargs(params, FunargParams)
ft.Results = funargs(results, FunargResults)
ft.pkg = pkg