[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:
Matthew Dempsky 2020-12-26 18:02:33 -08:00
parent a4f335f420
commit 0de8eafd98
8 changed files with 18 additions and 35 deletions

View file

@ -572,14 +572,12 @@ type SelectorExpr struct {
miniExpr miniExpr
X Node X Node
Sel *types.Sym Sel *types.Sym
Offset int64
Selection *types.Field Selection *types.Field
} }
func NewSelectorExpr(pos src.XPos, op Op, x Node, sel *types.Sym) *SelectorExpr { func NewSelectorExpr(pos src.XPos, op Op, x Node, sel *types.Sym) *SelectorExpr {
n := &SelectorExpr{X: x, Sel: sel} n := &SelectorExpr{X: x, Sel: sel}
n.pos = pos n.pos = pos
n.Offset = types.BADWIDTH
n.SetOp(op) n.SetOp(op)
return n return n
} }
@ -596,6 +594,7 @@ func (n *SelectorExpr) SetOp(op Op) {
func (n *SelectorExpr) Sym() *types.Sym { return n.Sel } func (n *SelectorExpr) Sym() *types.Sym { return n.Sel }
func (n *SelectorExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 } func (n *SelectorExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
func (n *SelectorExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) } 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. // Before type-checking, bytes.Buffer is a SelectorExpr.
// After type-checking it becomes a Name. // After type-checking it becomes a Name.

View file

@ -1863,7 +1863,7 @@ func MarkUsedIfaceMethod(n *ir.CallExpr) {
r.Sym = tsym r.Sym = tsym
// dot.Xoffset is the method index * Widthptr (the offset of code pointer // dot.Xoffset is the method index * Widthptr (the offset of code pointer
// in itab). // in itab).
midx := dot.Offset / int64(types.PtrSize) midx := dot.Offset() / int64(types.PtrSize)
r.Add = InterfaceMethodOffset(ityp, midx) r.Add = InterfaceMethodOffset(ityp, midx)
r.Type = objabi.R_USEIFACEMETHOD r.Type = objabi.R_USEIFACEMETHOD
} }

View file

@ -2743,7 +2743,7 @@ func (s *state) expr(n ir.Node) *ssa.Value {
case ir.ODOTPTR: case ir.ODOTPTR:
n := n.(*ir.SelectorExpr) n := n.(*ir.SelectorExpr)
p := s.exprPtr(n.X, n.Bounded(), n.Pos()) 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) return s.load(n.Type(), p)
case ir.OINDEX: case ir.OINDEX:
@ -4924,7 +4924,7 @@ func (s *state) getClosureAndRcvr(fn *ir.SelectorExpr) (*ssa.Value, *ssa.Value)
i := s.expr(fn.X) i := s.expr(fn.X)
itab := s.newValue1(ssa.OpITab, types.Types[types.TUINTPTR], i) itab := s.newValue1(ssa.OpITab, types.Types[types.TUINTPTR], i)
s.nilCheck(itab) 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) closure := s.newValue1I(ssa.OpOffPtr, s.f.Config.Types.UintptrPtr, itabidx, itab)
rcvr := s.newValue1(ssa.OpIData, s.f.Config.Types.BytePtr, i) rcvr := s.newValue1(ssa.OpIData, s.f.Config.Types.BytePtr, i)
return closure, rcvr return closure, rcvr
@ -5028,11 +5028,11 @@ func (s *state) addr(n ir.Node) *ssa.Value {
case ir.ODOT: case ir.ODOT:
n := n.(*ir.SelectorExpr) n := n.(*ir.SelectorExpr)
p := s.addr(n.X) 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: case ir.ODOTPTR:
n := n.(*ir.SelectorExpr) n := n.(*ir.SelectorExpr)
p := s.exprPtr(n.X, n.Bounded(), n.Pos()) 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: case ir.OCLOSUREREAD:
n := n.(*ir.ClosureReadExpr) n := n.(*ir.ClosureReadExpr)
return s.newValue1I(ssa.OpOffPtr, t, n.Offset, return s.newValue1I(ssa.OpOffPtr, t, n.Offset,
@ -7069,22 +7069,18 @@ func (s *State) UseArgs(n int64) {
// fieldIdx finds the index of the field referred to by the ODOT node n. // fieldIdx finds the index of the field referred to by the ODOT node n.
func fieldIdx(n *ir.SelectorExpr) int { func fieldIdx(n *ir.SelectorExpr) int {
t := n.X.Type() t := n.X.Type()
f := n.Sel
if !t.IsStruct() { if !t.IsStruct() {
panic("ODOT's LHS is not a struct") panic("ODOT's LHS is not a struct")
} }
var i int for i, f := range t.Fields().Slice() {
for _, t1 := range t.Fields().Slice() { if f.Sym == n.Sel {
if t1.Sym != f { if f.Offset != n.Offset() {
i++
continue
}
if t1.Offset != n.Offset {
panic("field offset doesn't match") panic("field offset doesn't match")
} }
return i return i
} }
}
panic(fmt.Sprintf("can't find field in expr %v\n", n)) panic(fmt.Sprintf("can't find field in expr %v\n", n))
// TODO: keep the result of this function somewhere in the ODOT Node // TODO: keep the result of this function somewhere in the ODOT Node

View file

@ -469,7 +469,7 @@ func StaticLoc(n ir.Node) (name *ir.Name, offset int64, ok bool) {
if name, offset, ok = StaticLoc(n.X); !ok { if name, offset, ok = StaticLoc(n.X); !ok {
break break
} }
offset += n.Offset offset += n.Offset()
return name, offset, true return name, offset, true
case ir.OINDEX: case ir.OINDEX:

View file

@ -929,7 +929,7 @@ func evalunsafe(n ir.Node) int64 {
fallthrough fallthrough
case ir.ODOT: case ir.ODOT:
r := r.(*ir.SelectorExpr) r := r.(*ir.SelectorExpr)
v += r.Offset v += r.Offset()
next = r.X next = r.X
default: default:
ir.Dump("unsafenmagic", tsel) ir.Dump("unsafenmagic", tsel)

View file

@ -1232,7 +1232,7 @@ func lookdot(n *ir.SelectorExpr, t *types.Type, dostrcmp int) *types.Field {
if f1.Offset == types.BADWIDTH { if f1.Offset == types.BADWIDTH {
base.Fatalf("lookdot badwidth %v %p", f1, f1) base.Fatalf("lookdot badwidth %v %p", f1, f1)
} }
n.Offset = f1.Offset n.Selection = f1
n.SetType(f1.Type) n.SetType(f1.Type)
if t.IsInterface() { if t.IsInterface() {
if n.X.Type().IsPtr() { 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.SetOp(ir.ODOTINTER)
} }
n.Selection = f1
return 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.Sel = ir.MethodSym(n.X.Type(), f2.Sym)
n.Offset = f2.Offset n.Selection = f2
n.SetType(f2.Type) n.SetType(f2.Type)
n.SetOp(ir.ODOTMETH) n.SetOp(ir.ODOTMETH)
n.Selection = f2
return f2 return f2
} }

View file

@ -965,22 +965,13 @@ func usefield(n *ir.SelectorExpr) {
case ir.ODOT, ir.ODOTPTR: case ir.ODOT, ir.ODOTPTR:
break 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 field := n.Selection
if field == nil { if field == nil {
base.Fatalf("usefield %v %v without paramfld", n.X.Type(), n.Sel) base.Fatalf("usefield %v %v without paramfld", n.X.Type(), n.Sel)
} }
if field.Sym != n.Sel || field.Offset != n.Offset { if field.Sym != n.Sel {
base.Fatalf("field inconsistency: %v,%v != %v,%v", field.Sym, field.Offset, n.Sel, n.Offset) base.Fatalf("field inconsistency: %v != %v", field.Sym, n.Sel)
} }
if !strings.Contains(field.Note, "go:\"track\"") { if !strings.Contains(field.Note, "go:\"track\"") {
return return

View file

@ -553,7 +553,6 @@ var itabTypeField *types.Field
func boundedDotPtr(pos src.XPos, ptr ir.Node, field *types.Field) *ir.SelectorExpr { func boundedDotPtr(pos src.XPos, ptr ir.Node, field *types.Field) *ir.SelectorExpr {
sel := ir.NewSelectorExpr(pos, ir.ODOTPTR, ptr, field.Sym) sel := ir.NewSelectorExpr(pos, ir.ODOTPTR, ptr, field.Sym)
sel.Selection = field sel.Selection = field
sel.Offset = field.Offset
sel.SetType(field.Type) sel.SetType(field.Type)
sel.SetTypecheck(1) sel.SetTypecheck(1)
sel.SetBounded(true) // guaranteed not to fault sel.SetBounded(true) // guaranteed not to fault