mirror of
https://github.com/golang/go.git
synced 2025-10-19 11:03:18 +00:00
[dev.regabi] cmd/compile: remove SelectorExpr.Offset field
Now that the previous CL ensures we always set SelectorExpr.Selection, we can replace the SelectorExpr.Offset field with a helper method that simply returns SelectorExpr.Selection.Offset. Passes toolstash -cmp. Change-Id: Id0f22b8b1980397b668f6860d27cb197b90ff52a Reviewed-on: https://go-review.googlesource.com/c/go/+/280433 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
a4f335f420
commit
0de8eafd98
8 changed files with 18 additions and 35 deletions
|
@ -572,14 +572,12 @@ type SelectorExpr struct {
|
|||
miniExpr
|
||||
X Node
|
||||
Sel *types.Sym
|
||||
Offset int64
|
||||
Selection *types.Field
|
||||
}
|
||||
|
||||
func NewSelectorExpr(pos src.XPos, op Op, x Node, sel *types.Sym) *SelectorExpr {
|
||||
n := &SelectorExpr{X: x, Sel: sel}
|
||||
n.pos = pos
|
||||
n.Offset = types.BADWIDTH
|
||||
n.SetOp(op)
|
||||
return n
|
||||
}
|
||||
|
@ -596,6 +594,7 @@ func (n *SelectorExpr) SetOp(op Op) {
|
|||
func (n *SelectorExpr) Sym() *types.Sym { return n.Sel }
|
||||
func (n *SelectorExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
|
||||
func (n *SelectorExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
|
||||
func (n *SelectorExpr) Offset() int64 { return n.Selection.Offset }
|
||||
|
||||
// Before type-checking, bytes.Buffer is a SelectorExpr.
|
||||
// After type-checking it becomes a Name.
|
||||
|
|
|
@ -1863,7 +1863,7 @@ func MarkUsedIfaceMethod(n *ir.CallExpr) {
|
|||
r.Sym = tsym
|
||||
// dot.Xoffset is the method index * Widthptr (the offset of code pointer
|
||||
// in itab).
|
||||
midx := dot.Offset / int64(types.PtrSize)
|
||||
midx := dot.Offset() / int64(types.PtrSize)
|
||||
r.Add = InterfaceMethodOffset(ityp, midx)
|
||||
r.Type = objabi.R_USEIFACEMETHOD
|
||||
}
|
||||
|
|
|
@ -2743,7 +2743,7 @@ func (s *state) expr(n ir.Node) *ssa.Value {
|
|||
case ir.ODOTPTR:
|
||||
n := n.(*ir.SelectorExpr)
|
||||
p := s.exprPtr(n.X, n.Bounded(), n.Pos())
|
||||
p = s.newValue1I(ssa.OpOffPtr, types.NewPtr(n.Type()), n.Offset, p)
|
||||
p = s.newValue1I(ssa.OpOffPtr, types.NewPtr(n.Type()), n.Offset(), p)
|
||||
return s.load(n.Type(), p)
|
||||
|
||||
case ir.OINDEX:
|
||||
|
@ -4924,7 +4924,7 @@ func (s *state) getClosureAndRcvr(fn *ir.SelectorExpr) (*ssa.Value, *ssa.Value)
|
|||
i := s.expr(fn.X)
|
||||
itab := s.newValue1(ssa.OpITab, types.Types[types.TUINTPTR], i)
|
||||
s.nilCheck(itab)
|
||||
itabidx := fn.Offset + 2*int64(types.PtrSize) + 8 // offset of fun field in runtime.itab
|
||||
itabidx := fn.Offset() + 2*int64(types.PtrSize) + 8 // offset of fun field in runtime.itab
|
||||
closure := s.newValue1I(ssa.OpOffPtr, s.f.Config.Types.UintptrPtr, itabidx, itab)
|
||||
rcvr := s.newValue1(ssa.OpIData, s.f.Config.Types.BytePtr, i)
|
||||
return closure, rcvr
|
||||
|
@ -5028,11 +5028,11 @@ func (s *state) addr(n ir.Node) *ssa.Value {
|
|||
case ir.ODOT:
|
||||
n := n.(*ir.SelectorExpr)
|
||||
p := s.addr(n.X)
|
||||
return s.newValue1I(ssa.OpOffPtr, t, n.Offset, p)
|
||||
return s.newValue1I(ssa.OpOffPtr, t, n.Offset(), p)
|
||||
case ir.ODOTPTR:
|
||||
n := n.(*ir.SelectorExpr)
|
||||
p := s.exprPtr(n.X, n.Bounded(), n.Pos())
|
||||
return s.newValue1I(ssa.OpOffPtr, t, n.Offset, p)
|
||||
return s.newValue1I(ssa.OpOffPtr, t, n.Offset(), p)
|
||||
case ir.OCLOSUREREAD:
|
||||
n := n.(*ir.ClosureReadExpr)
|
||||
return s.newValue1I(ssa.OpOffPtr, t, n.Offset,
|
||||
|
@ -7069,21 +7069,17 @@ func (s *State) UseArgs(n int64) {
|
|||
// fieldIdx finds the index of the field referred to by the ODOT node n.
|
||||
func fieldIdx(n *ir.SelectorExpr) int {
|
||||
t := n.X.Type()
|
||||
f := n.Sel
|
||||
if !t.IsStruct() {
|
||||
panic("ODOT's LHS is not a struct")
|
||||
}
|
||||
|
||||
var i int
|
||||
for _, t1 := range t.Fields().Slice() {
|
||||
if t1.Sym != f {
|
||||
i++
|
||||
continue
|
||||
for i, f := range t.Fields().Slice() {
|
||||
if f.Sym == n.Sel {
|
||||
if f.Offset != n.Offset() {
|
||||
panic("field offset doesn't match")
|
||||
}
|
||||
return i
|
||||
}
|
||||
if t1.Offset != n.Offset {
|
||||
panic("field offset doesn't match")
|
||||
}
|
||||
return i
|
||||
}
|
||||
panic(fmt.Sprintf("can't find field in expr %v\n", n))
|
||||
|
||||
|
|
|
@ -469,7 +469,7 @@ func StaticLoc(n ir.Node) (name *ir.Name, offset int64, ok bool) {
|
|||
if name, offset, ok = StaticLoc(n.X); !ok {
|
||||
break
|
||||
}
|
||||
offset += n.Offset
|
||||
offset += n.Offset()
|
||||
return name, offset, true
|
||||
|
||||
case ir.OINDEX:
|
||||
|
|
|
@ -929,7 +929,7 @@ func evalunsafe(n ir.Node) int64 {
|
|||
fallthrough
|
||||
case ir.ODOT:
|
||||
r := r.(*ir.SelectorExpr)
|
||||
v += r.Offset
|
||||
v += r.Offset()
|
||||
next = r.X
|
||||
default:
|
||||
ir.Dump("unsafenmagic", tsel)
|
||||
|
|
|
@ -1232,7 +1232,7 @@ func lookdot(n *ir.SelectorExpr, t *types.Type, dostrcmp int) *types.Field {
|
|||
if f1.Offset == types.BADWIDTH {
|
||||
base.Fatalf("lookdot badwidth %v %p", f1, f1)
|
||||
}
|
||||
n.Offset = f1.Offset
|
||||
n.Selection = f1
|
||||
n.SetType(f1.Type)
|
||||
if t.IsInterface() {
|
||||
if n.X.Type().IsPtr() {
|
||||
|
@ -1243,7 +1243,6 @@ func lookdot(n *ir.SelectorExpr, t *types.Type, dostrcmp int) *types.Field {
|
|||
|
||||
n.SetOp(ir.ODOTINTER)
|
||||
}
|
||||
n.Selection = f1
|
||||
return f1
|
||||
}
|
||||
|
||||
|
@ -1299,10 +1298,9 @@ func lookdot(n *ir.SelectorExpr, t *types.Type, dostrcmp int) *types.Field {
|
|||
}
|
||||
|
||||
n.Sel = ir.MethodSym(n.X.Type(), f2.Sym)
|
||||
n.Offset = f2.Offset
|
||||
n.Selection = f2
|
||||
n.SetType(f2.Type)
|
||||
n.SetOp(ir.ODOTMETH)
|
||||
n.Selection = f2
|
||||
|
||||
return f2
|
||||
}
|
||||
|
|
|
@ -965,22 +965,13 @@ func usefield(n *ir.SelectorExpr) {
|
|||
case ir.ODOT, ir.ODOTPTR:
|
||||
break
|
||||
}
|
||||
if n.Sel == nil {
|
||||
// No field name. This DOTPTR was built by the compiler for access
|
||||
// to runtime data structures. Ignore.
|
||||
return
|
||||
}
|
||||
|
||||
t := n.X.Type()
|
||||
if t.IsPtr() {
|
||||
t = t.Elem()
|
||||
}
|
||||
field := n.Selection
|
||||
if field == nil {
|
||||
base.Fatalf("usefield %v %v without paramfld", n.X.Type(), n.Sel)
|
||||
}
|
||||
if field.Sym != n.Sel || field.Offset != n.Offset {
|
||||
base.Fatalf("field inconsistency: %v,%v != %v,%v", field.Sym, field.Offset, n.Sel, n.Offset)
|
||||
if field.Sym != n.Sel {
|
||||
base.Fatalf("field inconsistency: %v != %v", field.Sym, n.Sel)
|
||||
}
|
||||
if !strings.Contains(field.Note, "go:\"track\"") {
|
||||
return
|
||||
|
|
|
@ -553,7 +553,6 @@ var itabTypeField *types.Field
|
|||
func boundedDotPtr(pos src.XPos, ptr ir.Node, field *types.Field) *ir.SelectorExpr {
|
||||
sel := ir.NewSelectorExpr(pos, ir.ODOTPTR, ptr, field.Sym)
|
||||
sel.Selection = field
|
||||
sel.Offset = field.Offset
|
||||
sel.SetType(field.Type)
|
||||
sel.SetTypecheck(1)
|
||||
sel.SetBounded(true) // guaranteed not to fault
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue