mirror of
https://github.com/golang/go.git
synced 2025-10-20 03:23:18 +00:00
[dev.regabi] cmd/compile: split SliceHeaderExpr.LenCap into separate fields
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>
This commit is contained in:
parent
53f082b0ee
commit
d19018e8f1
7 changed files with 24 additions and 31 deletions
|
@ -695,16 +695,16 @@ func (o Op) IsSlice3() bool {
|
||||||
// A SliceHeader expression constructs a slice header from its parts.
|
// A SliceHeader expression constructs a slice header from its parts.
|
||||||
type SliceHeaderExpr struct {
|
type SliceHeaderExpr struct {
|
||||||
miniExpr
|
miniExpr
|
||||||
Ptr Node
|
Ptr Node
|
||||||
LenCap Nodes // TODO(rsc): Split into two Node fields
|
Len Node
|
||||||
|
Cap Node
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSliceHeaderExpr(pos src.XPos, typ *types.Type, ptr, len, cap Node) *SliceHeaderExpr {
|
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.pos = pos
|
||||||
n.op = OSLICEHEADER
|
n.op = OSLICEHEADER
|
||||||
n.typ = typ
|
n.typ = typ
|
||||||
n.LenCap = []Node{len, cap}
|
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -800,10 +800,7 @@ func exprFmt(n Node, s fmt.State, prec int) {
|
||||||
|
|
||||||
case OSLICEHEADER:
|
case OSLICEHEADER:
|
||||||
n := n.(*SliceHeaderExpr)
|
n := n.(*SliceHeaderExpr)
|
||||||
if len(n.LenCap) != 2 {
|
fmt.Fprintf(s, "sliceheader{%v,%v,%v}", n.Ptr, n.Len, n.Cap)
|
||||||
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])
|
|
||||||
|
|
||||||
case OCOMPLEX, OCOPY:
|
case OCOMPLEX, OCOPY:
|
||||||
n := n.(*BinaryExpr)
|
n := n.(*BinaryExpr)
|
||||||
|
|
|
@ -858,20 +858,21 @@ func (n *SliceHeaderExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||||
func (n *SliceHeaderExpr) copy() Node {
|
func (n *SliceHeaderExpr) copy() Node {
|
||||||
c := *n
|
c := *n
|
||||||
c.init = c.init.Copy()
|
c.init = c.init.Copy()
|
||||||
c.LenCap = c.LenCap.Copy()
|
|
||||||
return &c
|
return &c
|
||||||
}
|
}
|
||||||
func (n *SliceHeaderExpr) doChildren(do func(Node) error) error {
|
func (n *SliceHeaderExpr) doChildren(do func(Node) error) error {
|
||||||
var err error
|
var err error
|
||||||
err = maybeDoList(n.init, err, do)
|
err = maybeDoList(n.init, err, do)
|
||||||
err = maybeDo(n.Ptr, 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
|
return err
|
||||||
}
|
}
|
||||||
func (n *SliceHeaderExpr) editChildren(edit func(Node) Node) {
|
func (n *SliceHeaderExpr) editChildren(edit func(Node) Node) {
|
||||||
editList(n.init, edit)
|
editList(n.init, edit)
|
||||||
n.Ptr = maybeEdit(n.Ptr, 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) }
|
func (n *SliceType) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||||
|
|
|
@ -2844,8 +2844,8 @@ func (s *state) expr(n ir.Node) *ssa.Value {
|
||||||
case ir.OSLICEHEADER:
|
case ir.OSLICEHEADER:
|
||||||
n := n.(*ir.SliceHeaderExpr)
|
n := n.(*ir.SliceHeaderExpr)
|
||||||
p := s.expr(n.Ptr)
|
p := s.expr(n.Ptr)
|
||||||
l := s.expr(n.LenCap[0])
|
l := s.expr(n.Len)
|
||||||
c := s.expr(n.LenCap[1])
|
c := s.expr(n.Cap)
|
||||||
return s.newValue3(ssa.OpSliceMake, n.Type(), p, l, c)
|
return s.newValue3(ssa.OpSliceMake, n.Type(), p, l, c)
|
||||||
|
|
||||||
case ir.OSLICE, ir.OSLICEARR, ir.OSLICE3, ir.OSLICE3ARR:
|
case ir.OSLICE, ir.OSLICEARR, ir.OSLICE3, ir.OSLICE3ARR:
|
||||||
|
|
|
@ -924,30 +924,22 @@ func tcSliceHeader(n *ir.SliceHeaderExpr) ir.Node {
|
||||||
base.Fatalf("need unsafe.Pointer for OSLICEHEADER")
|
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)
|
n.Ptr = Expr(n.Ptr)
|
||||||
l := Expr(n.LenCap[0])
|
n.Len = DefaultLit(Expr(n.Len), types.Types[types.TINT])
|
||||||
c := Expr(n.LenCap[1])
|
n.Cap = DefaultLit(Expr(n.Cap), types.Types[types.TINT])
|
||||||
l = DefaultLit(l, types.Types[types.TINT])
|
|
||||||
c = DefaultLit(c, 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")
|
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")
|
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")
|
base.Fatalf("len larger than cap for OSLICEHEADER")
|
||||||
}
|
}
|
||||||
|
|
||||||
n.LenCap[0] = l
|
|
||||||
n.LenCap[1] = c
|
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -438,7 +438,8 @@ func walkMakeSlice(n *ir.MakeExpr, init *ir.Nodes) ir.Node {
|
||||||
fn := typecheck.LookupRuntime(fnname)
|
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 = mkcall1(fn, types.Types[types.TUNSAFEPTR], init, reflectdata.TypePtr(t.Elem()), typecheck.Conv(len, argtype), typecheck.Conv(cap, argtype))
|
||||||
m.Ptr.MarkNonNil()
|
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)
|
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 := 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 = mkcall1(fn, types.Types[types.TUNSAFEPTR], init, size, typecheck.NodNil(), ir.NewBool(false))
|
||||||
sh.Ptr.MarkNonNil()
|
sh.Ptr.MarkNonNil()
|
||||||
sh.LenCap = []ir.Node{length, length}
|
sh.Len = length
|
||||||
|
sh.Cap = length
|
||||||
sh.SetType(t)
|
sh.SetType(t)
|
||||||
|
|
||||||
s := typecheck.Temp(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 := 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 = mkcall1(fn, types.Types[types.TUNSAFEPTR], init, reflectdata.TypePtr(t.Elem()), length, copylen, typecheck.Conv(copyptr, types.Types[types.TUNSAFEPTR]))
|
||||||
s.Ptr.MarkNonNil()
|
s.Ptr.MarkNonNil()
|
||||||
s.LenCap = []ir.Node{length, length}
|
s.Len = length
|
||||||
|
s.Cap = length
|
||||||
s.SetType(t)
|
s.SetType(t)
|
||||||
return walkExpr(typecheck.Expr(s), init)
|
return walkExpr(typecheck.Expr(s), init)
|
||||||
}
|
}
|
||||||
|
|
|
@ -817,8 +817,8 @@ func walkSlice(n *ir.SliceExpr, init *ir.Nodes) ir.Node {
|
||||||
// walkSliceHeader walks an OSLICEHEADER node.
|
// walkSliceHeader walks an OSLICEHEADER node.
|
||||||
func walkSliceHeader(n *ir.SliceHeaderExpr, init *ir.Nodes) ir.Node {
|
func walkSliceHeader(n *ir.SliceHeaderExpr, init *ir.Nodes) ir.Node {
|
||||||
n.Ptr = walkExpr(n.Ptr, init)
|
n.Ptr = walkExpr(n.Ptr, init)
|
||||||
n.LenCap[0] = walkExpr(n.LenCap[0], init)
|
n.Len = walkExpr(n.Len, init)
|
||||||
n.LenCap[1] = walkExpr(n.LenCap[1], init)
|
n.Cap = walkExpr(n.Cap, init)
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue