Skip to content

Commit

Permalink
[dev.typeparams] cmd/compile: start adding info needed for typeparams…
Browse files Browse the repository at this point in the history
… in types & ir

We are focusing on generic functions first, and ignoring type lists for
now.

The signatures of types.NewSignature() and ir.NewCallExpr() changed (with
addition of type args/params).

Change-Id: I57480be3d1f65690b2946e15dd74929bf42873f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/287416
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
  • Loading branch information
danscales committed Jan 28, 2021
1 parent c0bf904 commit 2440dd4
Show file tree
Hide file tree
Showing 29 changed files with 164 additions and 154 deletions.
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/inline/inl.go
Expand Up @@ -1228,7 +1228,7 @@ func (subst *inlsubst) closure(n *ir.ClosureExpr) ir.Node {
newrecv = newrecvs[0]
}
newt := types.NewSignature(oldt.Pkg(), newrecv,
subst.fields(oldt.Params()), subst.fields(oldt.Results()))
nil, subst.fields(oldt.Params()), subst.fields(oldt.Results()))

newfn.Nname.SetType(newt)
newfn.Body = subst.list(oldfn.Body)
Expand Down
7 changes: 4 additions & 3 deletions src/cmd/compile/internal/ir/class_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/cmd/compile/internal/ir/expr.go
Expand Up @@ -153,23 +153,25 @@ const (
CallUseStmt // results not used - call is a statement
)

// A CallExpr is a function call X(Args).
// A CallExpr is a function call X[Targs](Args).
type CallExpr struct {
miniExpr
origNode
X Node
Targs Nodes
Args Nodes
KeepAlive []*Name // vars to be kept alive until call returns
IsDDD bool
Use CallUse
NoInline bool
}

func NewCallExpr(pos src.XPos, op Op, fun Node, args []Node) *CallExpr {
func NewCallExpr(pos src.XPos, op Op, fun Node, targs, args []Node) *CallExpr {
n := &CallExpr{X: fun}
n.pos = pos
n.orig = n
n.SetOp(op)
n.Targs = targs
n.Args = args
return n
}
Expand Down
15 changes: 8 additions & 7 deletions src/cmd/compile/internal/ir/name.go
Expand Up @@ -473,13 +473,14 @@ type Class uint8

//go:generate stringer -type=Class name.go
const (
Pxxx Class = iota // no class; used during ssa conversion to indicate pseudo-variables
PEXTERN // global variables
PAUTO // local variables
PAUTOHEAP // local variables or parameters moved to heap
PPARAM // input arguments
PPARAMOUT // output results
PFUNC // global functions
Pxxx Class = iota // no class; used during ssa conversion to indicate pseudo-variables
PEXTERN // global variables
PAUTO // local variables
PAUTOHEAP // local variables or parameters moved to heap
PPARAM // input arguments
PPARAMOUT // output results
PTYPEPARAM // type params
PFUNC // global functions

// Careful: Class is stored in three bits in Node.flags.
_ = uint((1 << 3) - iota) // static assert for iota <= (1 << 3)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/noder/helpers.go
Expand Up @@ -82,7 +82,7 @@ func Binary(pos src.XPos, op ir.Op, x, y ir.Node) ir.Node {
func Call(pos src.XPos, fun ir.Node, args []ir.Node, dots bool) ir.Node {
// TODO(mdempsky): This should not be so difficult.

n := ir.NewCallExpr(pos, ir.OCALL, fun, args)
n := ir.NewCallExpr(pos, ir.OCALL, fun, nil, args)
n.IsDDD = dots

// Actually a type conversion.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/noder/noder.go
Expand Up @@ -755,7 +755,7 @@ func (p *noder) expr(expr syntax.Expr) ir.Node {
}
return ir.NewBinaryExpr(pos, op, x, y)
case *syntax.CallExpr:
n := ir.NewCallExpr(p.pos(expr), ir.OCALL, p.expr(expr.Fun), p.exprs(expr.ArgList))
n := ir.NewCallExpr(p.pos(expr), ir.OCALL, p.expr(expr.Fun), nil, p.exprs(expr.ArgList))
n.IsDDD = expr.HasDots
return n

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/noder/types.go
Expand Up @@ -121,7 +121,7 @@ func (g *irgen) signature(recv *types.Field, sig *types2.Signature) *types.Type
params[len(params)-1].SetIsDDD(true)
}

return types.NewSignature(g.tpkg(sig), recv, params, results)
return types.NewSignature(g.tpkg(sig), recv, nil, params, results)
}

func (g *irgen) param(v *types2.Var) *types.Field {
Expand Down
16 changes: 8 additions & 8 deletions src/cmd/compile/internal/reflectdata/alg.go
Expand Up @@ -176,7 +176,7 @@ func genhash(t *types.Type) *obj.LSym {
loop.PtrInit().Append(init)

// h = hashel(&p[i], h)
call := ir.NewCallExpr(base.Pos, ir.OCALL, hashel, nil)
call := ir.NewCallExpr(base.Pos, ir.OCALL, hashel, nil, nil)

nx := ir.NewIndexExpr(base.Pos, np, ni)
nx.SetBounded(true)
Expand All @@ -202,7 +202,7 @@ func genhash(t *types.Type) *obj.LSym {
// Hash non-memory fields with appropriate hash function.
if !isRegularMemory(f.Type) {
hashel := hashfor(f.Type)
call := ir.NewCallExpr(base.Pos, ir.OCALL, hashel, nil)
call := ir.NewCallExpr(base.Pos, ir.OCALL, hashel, nil, nil)
nx := ir.NewSelectorExpr(base.Pos, ir.OXDOT, np, f.Sym) // TODO: fields from other packages?
na := typecheck.NodAddr(nx)
call.Args.Append(na)
Expand All @@ -217,7 +217,7 @@ func genhash(t *types.Type) *obj.LSym {

// h = hashel(&p.first, size, h)
hashel := hashmem(f.Type)
call := ir.NewCallExpr(base.Pos, ir.OCALL, hashel, nil)
call := ir.NewCallExpr(base.Pos, ir.OCALL, hashel, nil, nil)
nx := ir.NewSelectorExpr(base.Pos, ir.OXDOT, np, f.Sym) // TODO: fields from other packages?
na := typecheck.NodAddr(nx)
call.Args.Append(na)
Expand Down Expand Up @@ -289,7 +289,7 @@ func hashfor(t *types.Type) ir.Node {

n := typecheck.NewName(sym)
ir.MarkFunc(n)
n.SetType(types.NewSignature(types.NoPkg, nil, []*types.Field{
n.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
types.NewField(base.Pos, nil, types.NewPtr(t)),
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
}, []*types.Field{
Expand Down Expand Up @@ -672,7 +672,7 @@ func EqString(s, t ir.Node) (eqlen *ir.BinaryExpr, eqmem *ir.CallExpr) {

fn := typecheck.LookupRuntime("memequal")
fn = typecheck.SubstArgTypes(fn, types.Types[types.TUINT8], types.Types[types.TUINT8])
call := ir.NewCallExpr(base.Pos, ir.OCALL, fn, []ir.Node{sptr, tptr, ir.Copy(slen)})
call := ir.NewCallExpr(base.Pos, ir.OCALL, fn, nil, []ir.Node{sptr, tptr, ir.Copy(slen)})
typecheck.Call(call)

cmp := ir.NewBinaryExpr(base.Pos, ir.OEQ, slen, tlen)
Expand Down Expand Up @@ -709,7 +709,7 @@ func EqInterface(s, t ir.Node) (eqtab *ir.BinaryExpr, eqdata *ir.CallExpr) {
sdata.SetTypecheck(1)
tdata.SetTypecheck(1)

call := ir.NewCallExpr(base.Pos, ir.OCALL, fn, []ir.Node{stab, sdata, tdata})
call := ir.NewCallExpr(base.Pos, ir.OCALL, fn, nil, []ir.Node{stab, sdata, tdata})
typecheck.Call(call)

cmp := ir.NewBinaryExpr(base.Pos, ir.OEQ, stab, ttab)
Expand All @@ -725,7 +725,7 @@ func eqmem(p ir.Node, q ir.Node, field *types.Sym, size int64) ir.Node {
ny := typecheck.Expr(typecheck.NodAddr(ir.NewSelectorExpr(base.Pos, ir.OXDOT, q, field)))

fn, needsize := eqmemfunc(size, nx.Type().Elem())
call := ir.NewCallExpr(base.Pos, ir.OCALL, fn, nil)
call := ir.NewCallExpr(base.Pos, ir.OCALL, fn, nil, nil)
call.Args.Append(nx)
call.Args.Append(ny)
if needsize {
Expand Down Expand Up @@ -777,7 +777,7 @@ func hashmem(t *types.Type) ir.Node {

n := typecheck.NewName(sym)
ir.MarkFunc(n)
n.SetType(types.NewSignature(types.NoPkg, nil, []*types.Field{
n.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
types.NewField(base.Pos, nil, types.NewPtr(t)),
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/reflectdata/reflect.go
Expand Up @@ -1399,7 +1399,7 @@ func WriteBasicTypes() {
// The latter is the type of an auto-generated wrapper.
writeType(types.NewPtr(types.ErrorType))

writeType(types.NewSignature(types.NoPkg, nil, []*types.Field{
writeType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
types.NewField(base.Pos, nil, types.ErrorType),
}, []*types.Field{
types.NewField(base.Pos, nil, types.Types[types.TSTRING]),
Expand Down Expand Up @@ -1747,7 +1747,7 @@ func methodWrapper(rcvr *types.Type, method *types.Field) *obj.LSym {
// generating wrapper from *T to T.
n := ir.NewIfStmt(base.Pos, nil, nil, nil)
n.Cond = ir.NewBinaryExpr(base.Pos, ir.OEQ, nthis, typecheck.NodNil())
call := ir.NewCallExpr(base.Pos, ir.OCALL, typecheck.LookupRuntime("panicwrap"), nil)
call := ir.NewCallExpr(base.Pos, ir.OCALL, typecheck.LookupRuntime("panicwrap"), nil, nil)
n.Body = []ir.Node{call}
fn.Body.Append(n)
}
Expand All @@ -1772,7 +1772,7 @@ func methodWrapper(rcvr *types.Type, method *types.Field) *obj.LSym {
fn.Body.Append(ir.NewTailCallStmt(base.Pos, method.Nname.(*ir.Name)))
} else {
fn.SetWrapper(true) // ignore frame for panic+recover matching
call := ir.NewCallExpr(base.Pos, ir.OCALL, dot, nil)
call := ir.NewCallExpr(base.Pos, ir.OCALL, dot, nil, nil)
call.Args = ir.ParamNames(tfn.Type())
call.IsDDD = tfn.Type().IsVariadic()
if method.Type.NumResults() > 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/ssagen/abi.go
Expand Up @@ -305,7 +305,7 @@ func makeABIWrapper(f *ir.Func, wrapperABI obj.ABI) {

tail = ir.NewTailCallStmt(base.Pos, f.Nname)
} else {
call := ir.NewCallExpr(base.Pos, ir.OCALL, f.Nname, nil)
call := ir.NewCallExpr(base.Pos, ir.OCALL, f.Nname, nil, nil)
call.Args = ir.ParamNames(tfn.Type())
call.IsDDD = tfn.Type().IsVariadic()
tail = call
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/test/abiutilsaux_test.go
Expand Up @@ -57,7 +57,7 @@ func mkFuncType(rcvr *types.Type, ins []*types.Type, outs []*types.Type) *types.
if rcvr != nil {
rf = mkParamResultField(rcvr, q, ir.PPARAM)
}
return types.NewSignature(types.LocalPkg, rf, inf, outf)
return types.NewSignature(types.LocalPkg, rf, nil, inf, outf)
}

type expectedDump struct {
Expand Down

0 comments on commit 2440dd4

Please sign in to comment.