]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: remove SelectorExpr.Offset field
authorMatthew Dempsky <mdempsky@google.com>
Sun, 27 Dec 2020 02:02:33 +0000 (18:02 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 28 Dec 2020 03:39:08 +0000 (03:39 +0000)
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>
src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/reflectdata/reflect.go
src/cmd/compile/internal/ssagen/ssa.go
src/cmd/compile/internal/staticinit/sched.go
src/cmd/compile/internal/typecheck/const.go
src/cmd/compile/internal/typecheck/typecheck.go
src/cmd/compile/internal/walk/expr.go
src/cmd/compile/internal/walk/walk.go

index a79b78fb45b5556879d76800ddfd0d0c295f8aca..1337d356a17e793eba1c1a077700ed1bd3d615f2 100644 (file)
@@ -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.
index 64cc3e87ca180d78e0e10eef5ad684fabfa63fc1..7c424218962b66fcea07e5ad7f0fabcb43260a3e 100644 (file)
@@ -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
 }
index 25efeee112e7139eea59556ff1ebf41bbd01e4db..9cdf902bcb957d8a9561d2653b9f240516d9865e 100644 (file)
@@ -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
-               }
-               if t1.Offset != n.Offset {
-                       panic("field offset doesn't match")
+       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
                }
-               return i
        }
        panic(fmt.Sprintf("can't find field in expr %v\n", n))
 
index 2a499d6eedbaaf8f39b5a5c51bb918d47ce0195d..2711f6cec0a9ec06930119f9a660b1c0da7b78e2 100644 (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 {
                        break
                }
-               offset += n.Offset
+               offset += n.Offset()
                return name, offset, true
 
        case ir.OINDEX:
index 54d70cb8350cad1bfd57927965c95fb0fcfd2c85..e22b284e829d2c7057579aa8bd6e136987c80dab 100644 (file)
@@ -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)
index 05a346b8c889d59f0efb5234f545735e20af25a5..1d070507fadad509eb2ba58b8a3519444953f470 100644 (file)
@@ -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
        }
index 4eee32cf442f86cd37c9459cd7be8147f4eeace9..f0d9e7c2a1d9a6b0d4639cda15b4b1f9af110eed 100644 (file)
@@ -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
index 6def35ef24c1cbb82ddacac12a382116437b8175..c4c3debde4819bd2693a888f26e3086d63dfa179 100644 (file)
@@ -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