]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove ir.CompLitExpr.Ntype field
authorMatthew Dempsky <mdempsky@google.com>
Tue, 3 May 2022 01:17:05 +0000 (18:17 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 5 May 2022 18:48:39 +0000 (18:48 +0000)
It's no longer needed, since type expressions are all evaluated by
types2. We can just use Node.Type instead.

Change-Id: If523bd96f96fc4f2337a26f563f84e4f194e654a
Reviewed-on: https://go-review.googlesource.com/c/go/+/403841
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/ir/fmt.go
src/cmd/compile/internal/ir/node_gen.go
src/cmd/compile/internal/typecheck/expr.go
src/cmd/compile/internal/typecheck/iimport.go
src/cmd/compile/internal/typecheck/typecheck.go

index 78b084341a24b94a531eaf2fc841de0b66fbeb12..086be13afdc5c9781c3b4d66c50f18ead183bccd 100644 (file)
@@ -191,7 +191,6 @@ type ClosureExpr struct {
 type CompLitExpr struct {
        miniExpr
        origNode
-       Ntype    Ntype
        List     Nodes // initialized values
        Prealloc *Name
        // For OSLICELIT, Len is the backing array length.
@@ -205,7 +204,7 @@ func NewCompLitExpr(pos src.XPos, op Op, typ *types.Type, list []Node) *CompLitE
        n.pos = pos
        n.SetOp(op)
        if typ != nil {
-               n.Ntype = TypeNode(typ)
+               n.SetType(typ)
        }
        n.orig = n
        return n
index 004d698961d2fe221c3b2cab189a7ce9f4734372..681404bc64ba2f42af8a62e92549bf9c6de6e909 100644 (file)
@@ -667,15 +667,10 @@ func exprFmt(n Node, s fmt.State, prec int) {
                                fmt.Fprintf(s, "%v{%s}", typ, ellipsisIf(len(n.List) != 0))
                                return
                        }
-                       if n.Ntype != nil {
-                               fmt.Fprintf(s, "%v{%s}", n.Ntype, ellipsisIf(len(n.List) != 0))
-                               return
-                       }
-
                        fmt.Fprint(s, "composite literal")
                        return
                }
-               fmt.Fprintf(s, "(%v{ %.v })", n.Ntype, n.List)
+               fmt.Fprintf(s, "(%v{ %.v })", n.Type(), n.List)
 
        case OPTRLIT:
                n := n.(*AddrExpr)
index 8d6fc8c607862f2fa88503c2e498d807f998c122..cf27f48bfc31ab57a6e02cf2f6509598aebf325b 100644 (file)
@@ -346,9 +346,6 @@ func (n *CompLitExpr) doChildren(do func(Node) bool) bool {
        if doNodes(n.init, do) {
                return true
        }
-       if n.Ntype != nil && do(n.Ntype) {
-               return true
-       }
        if doNodes(n.List, do) {
                return true
        }
@@ -359,9 +356,6 @@ func (n *CompLitExpr) doChildren(do func(Node) bool) bool {
 }
 func (n *CompLitExpr) editChildren(edit func(Node) Node) {
        editNodes(n.init, edit)
-       if n.Ntype != nil {
-               n.Ntype = edit(n.Ntype).(Ntype)
-       }
        editNodes(n.List, edit)
        if n.Prealloc != nil {
                n.Prealloc = edit(n.Prealloc).(*Name)
index f0b7b74aedd5ebc10ca3d98a9eb11d882f51e707..4d96a7df5c0ff501b7648397150eb522e2c6a2bb 100644 (file)
@@ -207,24 +207,13 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
                base.Pos = lno
        }()
 
-       if n.Ntype == nil {
-               base.ErrorfAt(n.Pos(), "missing type in composite literal")
-               n.SetType(nil)
-               return n
-       }
-
        // Save original node (including n.Right)
        n.SetOrig(ir.Copy(n))
 
-       ir.SetPos(n.Ntype)
+       ir.SetPos(n)
 
-       n.Ntype = typecheckNtype(n.Ntype)
-       t := n.Ntype.Type()
-       if t == nil {
-               n.SetType(nil)
-               return n
-       }
-       n.SetType(t)
+       t := n.Type()
+       base.AssertfAt(t != nil, n.Pos(), "missing type in composite literal")
 
        switch t.Kind() {
        default:
@@ -234,12 +223,10 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
        case types.TARRAY:
                typecheckarraylit(t.Elem(), t.NumElem(), n.List, "array literal")
                n.SetOp(ir.OARRAYLIT)
-               n.Ntype = nil
 
        case types.TSLICE:
                length := typecheckarraylit(t.Elem(), -1, n.List, "slice literal")
                n.SetOp(ir.OSLICELIT)
-               n.Ntype = nil
                n.Len = length
 
        case types.TMAP:
@@ -253,18 +240,15 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
                        l := l.(*ir.KeyExpr)
 
                        r := l.Key
-                       r = pushtype(r, t.Key())
                        r = Expr(r)
                        l.Key = AssignConv(r, t.Key(), "map key")
 
                        r = l.Value
-                       r = pushtype(r, t.Elem())
                        r = Expr(r)
                        l.Value = AssignConv(r, t.Elem(), "map value")
                }
 
                n.SetOp(ir.OMAPLIT)
-               n.Ntype = nil
 
        case types.TSTRUCT:
                // Need valid field offsets for Xoffset below.
@@ -345,7 +329,6 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
                }
 
                n.SetOp(ir.OSTRUCTLIT)
-               n.Ntype = nil
        }
 
        return n
index cee952b6592233ecfa238cdc7d6bd49fd630b691..962b6cbb12c9429feaebaabff01bd4b59e480170 100644 (file)
@@ -1410,23 +1410,18 @@ func (r *importReader) node() ir.Node {
                pos := r.pos()
                typ := r.typ()
                list := r.fieldList()
-               n := ir.NewCompLitExpr(pos, ir.OSTRUCTLIT, nil, list)
-               n.SetType(typ)
-               return n
+               return ir.NewCompLitExpr(pos, ir.OSTRUCTLIT, typ, list)
 
        case ir.OCOMPLIT:
                pos := r.pos()
                t := r.typ()
-               n := ir.NewCompLitExpr(pos, ir.OCOMPLIT, t, r.exprList())
-               n.SetType(t)
-               return n
+               return ir.NewCompLitExpr(pos, ir.OCOMPLIT, t, r.exprList())
 
        case ir.OARRAYLIT, ir.OSLICELIT, ir.OMAPLIT:
                pos := r.pos()
                typ := r.typ()
                list := r.exprList()
                n := ir.NewCompLitExpr(pos, op, typ, list)
-               n.SetType(typ)
                if op == ir.OSLICELIT {
                        n.Len = int64(r.uint64())
                }
index 6e61d9f3094e7fe23a6263940112f0f06d6258f3..44a0717fa6d0e12665f5b165efbed0905b651cf8 100644 (file)
@@ -1451,43 +1451,6 @@ func fielddup(name string, hash map[string]bool) {
        hash[name] = true
 }
 
-// iscomptype reports whether type t is a composite literal type.
-func iscomptype(t *types.Type) bool {
-       switch t.Kind() {
-       case types.TARRAY, types.TSLICE, types.TSTRUCT, types.TMAP:
-               return true
-       default:
-               return false
-       }
-}
-
-// pushtype adds elided type information for composite literals if
-// appropriate, and returns the resulting expression.
-func pushtype(nn ir.Node, t *types.Type) ir.Node {
-       if nn == nil || nn.Op() != ir.OCOMPLIT {
-               return nn
-       }
-       n := nn.(*ir.CompLitExpr)
-       if n.Ntype != nil {
-               return n
-       }
-
-       switch {
-       case iscomptype(t):
-               // For T, return T{...}.
-               n.Ntype = ir.TypeNode(t)
-
-       case t.IsPtr() && iscomptype(t.Elem()):
-               // For *T, return &T{...}.
-               n.Ntype = ir.TypeNode(t.Elem())
-
-               addr := NodAddrAt(n.Pos(), n)
-               addr.SetImplicit(true)
-               return addr
-       }
-       return n
-}
-
 // typecheckarraylit type-checks a sequence of slice/array literal elements.
 func typecheckarraylit(elemType *types.Type, bound int64, elts []ir.Node, ctx string) int64 {
        // If there are key/value pairs, create a map to keep seen
@@ -1516,7 +1479,6 @@ func typecheckarraylit(elemType *types.Type, bound int64, elts []ir.Node, ctx st
                        r = elt.Value
                }
 
-               r = pushtype(r, elemType)
                r = Expr(r)
                r = AssignConv(r, elemType, ctx)
                if kv != nil {