]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: change ir.InstExpr.Targs from Node to Ntype
authorMatthew Dempsky <mdempsky@google.com>
Tue, 3 May 2022 19:51:25 +0000 (12:51 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 5 May 2022 18:48:54 +0000 (18:48 +0000)
Type arguments are always type expressions, which are semantically
represented by Ntype.

In fact, the slice should probably just be []*types.Type instead, and
that would remove a lot of ir.TypeNode wrapping/unwrapping. But this
lead to issues within the stenciling code, and I can't immediately
make sense why.

Change-Id: Ib944db30e4d21284bc2d8d954b68ecb70b4205a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/403843
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/ir/node_gen.go
src/cmd/compile/internal/noder/expr.go
src/cmd/compile/internal/noder/object.go
src/cmd/compile/internal/noder/stencil.go
src/cmd/compile/internal/typecheck/iimport.go
src/cmd/compile/internal/typecheck/subr.go

index e54b6f067593181916e0b73fbeeefb3618573f13..986fb29e454329a030d3dc6822935047854925bf 100644 (file)
@@ -741,10 +741,10 @@ func (n *InstExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
 type InstExpr struct {
        miniExpr
        X     Node
-       Targs []Node
+       Targs []Ntype
 }
 
-func NewInstExpr(pos src.XPos, op Op, x Node, targs []Node) *InstExpr {
+func NewInstExpr(pos src.XPos, op Op, x Node, targs []Ntype) *InstExpr {
        n := &InstExpr{X: x, Targs: targs}
        n.pos = pos
        n.op = op
index 0d094ae76bd2f33219c65cd0647860b7ba6963d3..5b82b5569416d5d101cdd591e7f558c3c7f3a7c7 100644 (file)
@@ -683,7 +683,7 @@ func (n *InstExpr) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) }
 func (n *InstExpr) copy() Node {
        c := *n
        c.init = copyNodes(c.init)
-       c.Targs = copyNodes(c.Targs)
+       c.Targs = copyNtypes(c.Targs)
        return &c
 }
 func (n *InstExpr) doChildren(do func(Node) bool) bool {
@@ -693,7 +693,7 @@ func (n *InstExpr) doChildren(do func(Node) bool) bool {
        if n.X != nil && do(n.X) {
                return true
        }
-       if doNodes(n.Targs, do) {
+       if doNtypes(n.Targs, do) {
                return true
        }
        return false
@@ -703,7 +703,7 @@ func (n *InstExpr) editChildren(edit func(Node) Node) {
        if n.X != nil {
                n.X = edit(n.X).(Node)
        }
-       editNodes(n.Targs, edit)
+       editNtypes(n.Targs, edit)
 }
 
 func (n *JumpTableStmt) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) }
@@ -1409,3 +1409,27 @@ func editNodes(list []Node, edit func(Node) Node) {
                }
        }
 }
+
+func copyNtypes(list []Ntype) []Ntype {
+       if list == nil {
+               return nil
+       }
+       c := make([]Ntype, len(list))
+       copy(c, list)
+       return c
+}
+func doNtypes(list []Ntype, do func(Node) bool) bool {
+       for _, x := range list {
+               if x != nil && do(x) {
+                       return true
+               }
+       }
+       return false
+}
+func editNtypes(list []Ntype, edit func(Node) Node) {
+       for i, x := range list {
+               if x != nil {
+                       list[i] = edit(x).(Ntype)
+               }
+       }
+}
index e37e4cd661d42b8a53404d3c2d67bdbddafc4f17..a1160d42c44030bd8582adeb79d4d1de4d7497fe 100644 (file)
@@ -197,7 +197,7 @@ func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
 // substType does a normal type substition, but tparams is in the form of a field
 // list, and targs is in terms of a slice of type nodes. substType records any newly
 // instantiated types into g.instTypeList.
-func (g *irgen) substType(typ *types.Type, tparams *types.Type, targs []ir.Node) *types.Type {
+func (g *irgen) substType(typ *types.Type, tparams *types.Type, targs []ir.Ntype) *types.Type {
        fields := tparams.FieldSlice()
        tparams1 := make([]*types.Type, len(fields))
        for i, f := range fields {
@@ -339,7 +339,7 @@ func (g *irgen) selectorExpr(pos src.XPos, typ types2.Type, expr *syntax.Selecto
                                typed(method.Type(), n)
 
                                xt := deref(x.Type())
-                               targs := make([]ir.Node, len(xt.RParams()))
+                               targs := make([]ir.Ntype, len(xt.RParams()))
                                for i := range targs {
                                        targs[i] = ir.TypeNode(xt.RParams()[i])
                                }
index ee9e0e26800d4807eaf4d2d521e27ba94a0e78a4..3b60760a34db454543751e3ebfc837d4f835724c 100644 (file)
@@ -42,7 +42,7 @@ func (g *irgen) use(name *syntax.Name) ir.Node {
                if inst, ok := g.info.Instances[name]; ok {
                        // This is the case where inferring types required the
                        // types of the function arguments.
-                       targs := make([]ir.Node, inst.TypeArgs.Len())
+                       targs := make([]ir.Ntype, inst.TypeArgs.Len())
                        for i := range targs {
                                targs[i] = ir.TypeNode(g.typ(inst.TypeArgs.At(i)))
                        }
index 66e48b0e7e726b3d98f4c3918917e5aa86d30f97..34ba6bb8d5556ec88312603b75e6a6fb63a64b73 100644 (file)
@@ -1865,7 +1865,7 @@ func (g *genInst) getDictionaryValue(pos src.XPos, gf *ir.Name, targs []*types.T
 }
 
 // hasShapeNodes returns true if the type of any node in targs has a shape.
-func hasShapeNodes(targs []ir.Node) bool {
+func hasShapeNodes(targs []ir.Ntype) bool {
        for _, n := range targs {
                if n.Type().HasShape() {
                        return true
index d2ea954a50881b75c5ca57c3c09c1ac2e9c88031..851b1ead634cca3044eaca7839170d7f69dcdb6c 100644 (file)
@@ -1724,13 +1724,9 @@ func (r *importReader) node() ir.Node {
        case ir.OFUNCINST:
                pos := r.pos()
                x := r.expr()
-               ntargs := r.uint64()
-               var targs []ir.Node
-               if ntargs > 0 {
-                       targs = make([]ir.Node, ntargs)
-                       for i := range targs {
-                               targs[i] = ir.TypeNode(r.typ())
-                       }
+               targs := make([]ir.Ntype, r.uint64())
+               for i := range targs {
+                       targs[i] = ir.TypeNode(r.typ())
                }
                n := ir.NewInstExpr(pos, ir.OFUNCINST, x, targs)
                n.SetType(r.typ())
index 8cd81cf12b9e4572113165dd81e96bd0d9665b29..8918b9890b7292e315a59b5a5f27ef7119d556c9 100644 (file)
@@ -882,7 +882,7 @@ type symlink struct {
 
 // TypesOf converts a list of nodes to a list
 // of types of those nodes.
-func TypesOf(x []ir.Node) []*types.Type {
+func TypesOf(x []ir.Ntype) []*types.Type {
        r := make([]*types.Type, len(x))
        for i, n := range x {
                r[i] = n.Type()