]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: split SliceHeaderExpr.LenCap into separate fields
authorMatthew Dempsky <mdempsky@google.com>
Wed, 23 Dec 2020 13:40:11 +0000 (05:40 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 23 Dec 2020 14:09:23 +0000 (14:09 +0000)
Passes toolstash -cmp.

Change-Id: Ifc98a408c154a05997963e2c731466842ebbf50e
Reviewed-on: https://go-review.googlesource.com/c/go/+/279958
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.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/ssagen/ssa.go
src/cmd/compile/internal/typecheck/expr.go
src/cmd/compile/internal/walk/builtin.go
src/cmd/compile/internal/walk/expr.go

index 640cc039546ecbf198ed006eae84d636677148f0..d862a645d0eb67d396396fd23a4a7149be2fc9df 100644 (file)
@@ -695,16 +695,16 @@ func (o Op) IsSlice3() bool {
 // A SliceHeader expression constructs a slice header from its parts.
 type SliceHeaderExpr struct {
        miniExpr
-       Ptr    Node
-       LenCap Nodes // TODO(rsc): Split into two Node fields
+       Ptr Node
+       Len Node
+       Cap Node
 }
 
 func NewSliceHeaderExpr(pos src.XPos, typ *types.Type, ptr, len, cap Node) *SliceHeaderExpr {
-       n := &SliceHeaderExpr{Ptr: ptr}
+       n := &SliceHeaderExpr{Ptr: ptr, Len: len, Cap: cap}
        n.pos = pos
        n.op = OSLICEHEADER
        n.typ = typ
-       n.LenCap = []Node{len, cap}
        return n
 }
 
index 268290853910fa5bef171f8a5106724de0f3fe19..8cfc38a9ae499aba84c85e6af54acc0bef9b5158 100644 (file)
@@ -800,10 +800,7 @@ func exprFmt(n Node, s fmt.State, prec int) {
 
        case OSLICEHEADER:
                n := n.(*SliceHeaderExpr)
-               if len(n.LenCap) != 2 {
-                       base.Fatalf("bad OSLICEHEADER list length %d", len(n.LenCap))
-               }
-               fmt.Fprintf(s, "sliceheader{%v,%v,%v}", n.Ptr, n.LenCap[0], n.LenCap[1])
+               fmt.Fprintf(s, "sliceheader{%v,%v,%v}", n.Ptr, n.Len, n.Cap)
 
        case OCOMPLEX, OCOPY:
                n := n.(*BinaryExpr)
index 89b1c0ba23a0f0e3baf5fa353661973c8518c94d..d11e7bf9183b2cb95e2fd9d8ae58dec60bc70175 100644 (file)
@@ -858,20 +858,21 @@ func (n *SliceHeaderExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
 func (n *SliceHeaderExpr) copy() Node {
        c := *n
        c.init = c.init.Copy()
-       c.LenCap = c.LenCap.Copy()
        return &c
 }
 func (n *SliceHeaderExpr) doChildren(do func(Node) error) error {
        var err error
        err = maybeDoList(n.init, err, do)
        err = maybeDo(n.Ptr, err, do)
-       err = maybeDoList(n.LenCap, err, do)
+       err = maybeDo(n.Len, err, do)
+       err = maybeDo(n.Cap, err, do)
        return err
 }
 func (n *SliceHeaderExpr) editChildren(edit func(Node) Node) {
        editList(n.init, edit)
        n.Ptr = maybeEdit(n.Ptr, edit)
-       editList(n.LenCap, edit)
+       n.Len = maybeEdit(n.Len, edit)
+       n.Cap = maybeEdit(n.Cap, edit)
 }
 
 func (n *SliceType) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
index a77e57a5b6bac1864c50f2a02eaba36038f62d74..6b2ba5a781a25a53e7c9b64f076fd3c71f4667e6 100644 (file)
@@ -2844,8 +2844,8 @@ func (s *state) expr(n ir.Node) *ssa.Value {
        case ir.OSLICEHEADER:
                n := n.(*ir.SliceHeaderExpr)
                p := s.expr(n.Ptr)
-               l := s.expr(n.LenCap[0])
-               c := s.expr(n.LenCap[1])
+               l := s.expr(n.Len)
+               c := s.expr(n.Cap)
                return s.newValue3(ssa.OpSliceMake, n.Type(), p, l, c)
 
        case ir.OSLICE, ir.OSLICEARR, ir.OSLICE3, ir.OSLICE3ARR:
index f940a2e73d913575dbc86109de90492c78a76333..00615c506c17e848257b738bcfa521caddecc851 100644 (file)
@@ -924,30 +924,22 @@ func tcSliceHeader(n *ir.SliceHeaderExpr) ir.Node {
                base.Fatalf("need unsafe.Pointer for OSLICEHEADER")
        }
 
-       if x := len(n.LenCap); x != 2 {
-               base.Fatalf("expected 2 params (len, cap) for OSLICEHEADER, got %d", x)
-       }
-
        n.Ptr = Expr(n.Ptr)
-       l := Expr(n.LenCap[0])
-       c := Expr(n.LenCap[1])
-       l = DefaultLit(l, types.Types[types.TINT])
-       c = DefaultLit(c, types.Types[types.TINT])
+       n.Len = DefaultLit(Expr(n.Len), types.Types[types.TINT])
+       n.Cap = DefaultLit(Expr(n.Cap), types.Types[types.TINT])
 
-       if ir.IsConst(l, constant.Int) && ir.Int64Val(l) < 0 {
+       if ir.IsConst(n.Len, constant.Int) && ir.Int64Val(n.Len) < 0 {
                base.Fatalf("len for OSLICEHEADER must be non-negative")
        }
 
-       if ir.IsConst(c, constant.Int) && ir.Int64Val(c) < 0 {
+       if ir.IsConst(n.Cap, constant.Int) && ir.Int64Val(n.Cap) < 0 {
                base.Fatalf("cap for OSLICEHEADER must be non-negative")
        }
 
-       if ir.IsConst(l, constant.Int) && ir.IsConst(c, constant.Int) && constant.Compare(l.Val(), token.GTR, c.Val()) {
+       if ir.IsConst(n.Len, constant.Int) && ir.IsConst(n.Cap, constant.Int) && constant.Compare(n.Len.Val(), token.GTR, n.Cap.Val()) {
                base.Fatalf("len larger than cap for OSLICEHEADER")
        }
 
-       n.LenCap[0] = l
-       n.LenCap[1] = c
        return n
 }
 
index 61a555b773c87ea89d4d16dad0e176c2e0c93015..63f79258639747b1ef786544e2e380ac5dc88318 100644 (file)
@@ -438,7 +438,8 @@ func walkMakeSlice(n *ir.MakeExpr, init *ir.Nodes) ir.Node {
        fn := typecheck.LookupRuntime(fnname)
        m.Ptr = mkcall1(fn, types.Types[types.TUNSAFEPTR], init, reflectdata.TypePtr(t.Elem()), typecheck.Conv(len, argtype), typecheck.Conv(cap, argtype))
        m.Ptr.MarkNonNil()
-       m.LenCap = []ir.Node{typecheck.Conv(len, types.Types[types.TINT]), typecheck.Conv(cap, types.Types[types.TINT])}
+       m.Len = typecheck.Conv(len, types.Types[types.TINT])
+       m.Cap = typecheck.Conv(cap, types.Types[types.TINT])
        return walkExpr(typecheck.Expr(m), init)
 }
 
@@ -471,7 +472,8 @@ func walkMakeSliceCopy(n *ir.MakeExpr, init *ir.Nodes) ir.Node {
                sh := ir.NewSliceHeaderExpr(base.Pos, nil, nil, nil, nil)
                sh.Ptr = mkcall1(fn, types.Types[types.TUNSAFEPTR], init, size, typecheck.NodNil(), ir.NewBool(false))
                sh.Ptr.MarkNonNil()
-               sh.LenCap = []ir.Node{length, length}
+               sh.Len = length
+               sh.Cap = length
                sh.SetType(t)
 
                s := typecheck.Temp(t)
@@ -493,7 +495,8 @@ func walkMakeSliceCopy(n *ir.MakeExpr, init *ir.Nodes) ir.Node {
        s := ir.NewSliceHeaderExpr(base.Pos, nil, nil, nil, nil)
        s.Ptr = mkcall1(fn, types.Types[types.TUNSAFEPTR], init, reflectdata.TypePtr(t.Elem()), length, copylen, typecheck.Conv(copyptr, types.Types[types.TUNSAFEPTR]))
        s.Ptr.MarkNonNil()
-       s.LenCap = []ir.Node{length, length}
+       s.Len = length
+       s.Cap = length
        s.SetType(t)
        return walkExpr(typecheck.Expr(s), init)
 }
index 2029a6aef68d8f0c0734a96a80da724e323c9a44..4f57962205b50b8ded5781afe5a2d2c3bcfd00b3 100644 (file)
@@ -817,8 +817,8 @@ func walkSlice(n *ir.SliceExpr, init *ir.Nodes) ir.Node {
 // walkSliceHeader walks an OSLICEHEADER node.
 func walkSliceHeader(n *ir.SliceHeaderExpr, init *ir.Nodes) ir.Node {
        n.Ptr = walkExpr(n.Ptr, init)
-       n.LenCap[0] = walkExpr(n.LenCap[0], init)
-       n.LenCap[1] = walkExpr(n.LenCap[1], init)
+       n.Len = walkExpr(n.Len, init)
+       n.Cap = walkExpr(n.Cap, init)
        return n
 }