]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: use Ntype where possible
authorMatthew Dempsky <mdempsky@google.com>
Tue, 29 Dec 2020 07:42:49 +0000 (23:42 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 29 Dec 2020 08:22:45 +0000 (08:22 +0000)
For nodes that are always a type expression, we can use Ntype instead
of Node.

Passes toolstash -cmp.

Change-Id: I28f9fa235015ab48d0da06b78b30c49d74c64e3a
Reviewed-on: https://go-review.googlesource.com/c/go/+/280642
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/compile/internal/ir/func.go
src/cmd/compile/internal/ir/node_gen.go
src/cmd/compile/internal/ir/type.go
src/cmd/compile/internal/typecheck/expr.go
src/cmd/compile/internal/typecheck/func.go
src/cmd/compile/internal/typecheck/type.go

index a4f5875aabde7ce8a5b050fb14b0effb02498131..4613425f1a3404edd14ee7712b5fd3664d8b3f67 100644 (file)
@@ -67,7 +67,7 @@ type Func struct {
        Dcl []*Name
 
        ClosureEnter Nodes   // list of ONAME nodes (or OADDR-of-ONAME nodes, for output parameters) of captured variables
-       ClosureType  Node    // closure representation type
+       ClosureType  Ntype   // closure representation type
        ClosureVars  []*Name // closure params; each has closurevar set
 
        // Parents records the parent scope of each scope within a
index 1d24904a3f34c8b719702b2cf56bfd49d2adcd5b..fe54b62f1805b16b826b4defd7f922b7744ae235 100644 (file)
@@ -52,7 +52,7 @@ func (n *ArrayType) doChildren(do func(Node) error) error {
 }
 func (n *ArrayType) editChildren(edit func(Node) Node) {
        n.Len = maybeEdit(n.Len, edit)
-       n.Elem = maybeEdit(n.Elem, edit)
+       n.Elem = toNtype(maybeEdit(n.Elem, edit))
 }
 
 func (n *AssignListStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
@@ -241,7 +241,7 @@ func (n *ChanType) doChildren(do func(Node) error) error {
        return err
 }
 func (n *ChanType) editChildren(edit func(Node) Node) {
-       n.Elem = maybeEdit(n.Elem, edit)
+       n.Elem = toNtype(maybeEdit(n.Elem, edit))
 }
 
 func (n *ClosureExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
@@ -632,8 +632,8 @@ func (n *MapType) doChildren(do func(Node) error) error {
        return err
 }
 func (n *MapType) editChildren(edit func(Node) Node) {
-       n.Key = maybeEdit(n.Key, edit)
-       n.Elem = maybeEdit(n.Elem, edit)
+       n.Key = toNtype(maybeEdit(n.Key, edit))
+       n.Elem = toNtype(maybeEdit(n.Elem, edit))
 }
 
 func (n *Name) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
@@ -873,7 +873,7 @@ func (n *SliceType) doChildren(do func(Node) error) error {
        return err
 }
 func (n *SliceType) editChildren(edit func(Node) Node) {
-       n.Elem = maybeEdit(n.Elem, edit)
+       n.Elem = toNtype(maybeEdit(n.Elem, edit))
 }
 
 func (n *StarExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
index bd3a05d06e573dd9ee6a4de6cab719d1290ecedd..408f6ed56372ea231951661c87224e0b1a0e691d 100644 (file)
@@ -46,7 +46,7 @@ func (n *miniType) Type() *types.Type { return n.typ }
 // setOTYPE also records t.Nod = self if t.Nod is not already set.
 // (Some types are shared by multiple OTYPE nodes, so only
 // the first such node is used as t.Nod.)
-func (n *miniType) setOTYPE(t *types.Type, self Node) {
+func (n *miniType) setOTYPE(t *types.Type, self Ntype) {
        if n.typ != nil {
                panic(n.op.String() + " SetType: type already set")
        }
@@ -61,11 +61,11 @@ func (n *miniType) Implicit() bool  { return false } // for Format OTYPE
 // A ChanType represents a chan Elem syntax with the direction Dir.
 type ChanType struct {
        miniType
-       Elem Node
+       Elem Ntype
        Dir  types.ChanDir
 }
 
-func NewChanType(pos src.XPos, elem Node, dir types.ChanDir) *ChanType {
+func NewChanType(pos src.XPos, elem Ntype, dir types.ChanDir) *ChanType {
        n := &ChanType{Elem: elem, Dir: dir}
        n.op = OTCHAN
        n.pos = pos
@@ -80,11 +80,11 @@ func (n *ChanType) SetOTYPE(t *types.Type) {
 // A MapType represents a map[Key]Value type syntax.
 type MapType struct {
        miniType
-       Key  Node
-       Elem Node
+       Key  Ntype
+       Elem Ntype
 }
 
-func NewMapType(pos src.XPos, key, elem Node) *MapType {
+func NewMapType(pos src.XPos, key, elem Ntype) *MapType {
        n := &MapType{Key: key, Elem: elem}
        n.op = OTMAP
        n.pos = pos
@@ -246,11 +246,11 @@ func editFields(list []*Field, edit func(Node) Node) {
 // If DDD is true, it's the ...Elem at the end of a function list.
 type SliceType struct {
        miniType
-       Elem Node
+       Elem Ntype
        DDD  bool
 }
 
-func NewSliceType(pos src.XPos, elem Node) *SliceType {
+func NewSliceType(pos src.XPos, elem Ntype) *SliceType {
        n := &SliceType{Elem: elem}
        n.op = OTSLICE
        n.pos = pos
@@ -267,11 +267,11 @@ func (n *SliceType) SetOTYPE(t *types.Type) {
 type ArrayType struct {
        miniType
        Len  Node
-       Elem Node
+       Elem Ntype
 }
 
-func NewArrayType(pos src.XPos, size Node, elem Node) *ArrayType {
-       n := &ArrayType{Len: size, Elem: elem}
+func NewArrayType(pos src.XPos, len Node, elem Ntype) *ArrayType {
+       n := &ArrayType{Len: len, Elem: elem}
        n.op = OTARRAY
        n.pos = pos
        return n
index f3e3a93150cb324c7cb0ed1777866cb6f5967e4b..5752139c0b92a84cb922ee01e00557247a6080c1 100644 (file)
@@ -230,7 +230,7 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
 
        // Need to handle [...]T arrays specially.
        if array, ok := n.Ntype.(*ir.ArrayType); ok && array.Elem != nil && array.Len == nil {
-               array.Elem = typecheck(array.Elem, ctxType)
+               array.Elem = typecheckNtype(array.Elem)
                elemType := array.Elem.Type()
                if elemType == nil {
                        n.SetType(nil)
@@ -243,7 +243,7 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
                return n
        }
 
-       n.Ntype = ir.Node(typecheck(n.Ntype, ctxType)).(ir.Ntype)
+       n.Ntype = typecheckNtype(n.Ntype)
        t := n.Ntype.Type()
        if t == nil {
                n.SetType(nil)
index c58fef10ecd21950a602db25312572a7ec868461..9bb9245d4a4437de3905e5d7cf163fa0847dc3d8 100644 (file)
@@ -342,7 +342,7 @@ func tcClosure(clo *ir.ClosureExpr, top int) {
                fn.Iota = x
        }
 
-       fn.ClosureType = typecheck(fn.ClosureType, ctxType)
+       fn.ClosureType = typecheckNtype(fn.ClosureType)
        clo.SetType(fn.ClosureType.Type())
        fn.SetClosureCalled(top&ctxCallee != 0)
 
index 0c2ebb8b26a0c24567b93d97982917d209372674..6fdafef77d926f75388d99ea8451b61c20b1cfa7 100644 (file)
@@ -14,7 +14,7 @@ import (
 
 // tcArrayType typechecks an OTARRAY node.
 func tcArrayType(n *ir.ArrayType) ir.Node {
-       n.Elem = typecheck(n.Elem, ctxType)
+       n.Elem = typecheckNtype(n.Elem)
        if n.Elem.Type() == nil {
                return n
        }
@@ -59,7 +59,7 @@ func tcArrayType(n *ir.ArrayType) ir.Node {
 
 // tcChanType typechecks an OTCHAN node.
 func tcChanType(n *ir.ChanType) ir.Node {
-       n.Elem = typecheck(n.Elem, ctxType)
+       n.Elem = typecheckNtype(n.Elem)
        l := n.Elem
        if l.Type() == nil {
                return n
@@ -103,7 +103,7 @@ func tcInterfaceType(n *ir.InterfaceType) ir.Node {
                n.SetOTYPE(types.Types[types.TINTER])
                return n
        }
-       
+
        lno := base.Pos
        methods := tcFields(n.Methods, nil)
        base.Pos = lno
@@ -114,8 +114,8 @@ func tcInterfaceType(n *ir.InterfaceType) ir.Node {
 
 // tcMapType typechecks an OTMAP node.
 func tcMapType(n *ir.MapType) ir.Node {
-       n.Key = typecheck(n.Key, ctxType)
-       n.Elem = typecheck(n.Elem, ctxType)
+       n.Key = typecheckNtype(n.Key)
+       n.Elem = typecheckNtype(n.Elem)
        l := n.Key
        r := n.Elem
        if l.Type() == nil || r.Type() == nil {
@@ -134,7 +134,7 @@ func tcMapType(n *ir.MapType) ir.Node {
 
 // tcSliceType typechecks an OTSLICE node.
 func tcSliceType(n *ir.SliceType) ir.Node {
-       n.Elem = typecheck(n.Elem, ctxType)
+       n.Elem = typecheckNtype(n.Elem)
        if n.Elem.Type() == nil {
                return n
        }