]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile/internal/types: add pos/sym/typ params to NewField
authorMatthew Dempsky <mdempsky@google.com>
Mon, 23 Nov 2020 08:15:40 +0000 (00:15 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 24 Nov 2020 01:33:25 +0000 (01:33 +0000)
These are almost always set, so might as well expect callers to
provide them. They're also all required by go/types's corresponding
New{Field,Func,Param,Var} functions, so this eases API compatibility.

Passes toolstash-check.

Change-Id: Ib3fa355d4961243cd285b41915e87652ae2c22f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/272386
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/align.go
src/cmd/compile/internal/gc/closure.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/iimport.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/universe.go
src/cmd/compile/internal/types/type.go

index a3a0c8fce822e43226bbaa70a17d5d2e5ee42ccd..1f7631d19900ef8aa873b4be5e08cbd5337d7452 100644 (file)
@@ -74,11 +74,8 @@ func expandiface(t *types.Type) {
                // (including broken ones, if any) and add to t's
                // method set.
                for _, t1 := range m.Type.Fields().Slice() {
-                       f := types.NewField()
-                       f.Pos = m.Pos // preserve embedding position
-                       f.Sym = t1.Sym
-                       f.Type = t1.Type
-                       f.SetBroke(t1.Broke())
+                       // Use m.Pos rather than t1.Pos to preserve embedding position.
+                       f := types.NewField(m.Pos, t1.Sym, t1.Type)
                        addMethod(f, false)
                }
        }
index bd350f696e8cecbbaccbfdbc23b63a3451c4ce3b..42a9b4f3e88763fddf5517e9ef501f7ea9150a7b 100644 (file)
@@ -7,6 +7,7 @@ package gc
 import (
        "cmd/compile/internal/syntax"
        "cmd/compile/internal/types"
+       "cmd/internal/src"
        "fmt"
 )
 
@@ -266,10 +267,8 @@ func transformclosure(xfunc *Node) {
                        v.SetClass(PPARAM)
                        decls = append(decls, v)
 
-                       fld := types.NewField()
+                       fld := types.NewField(src.NoXPos, v.Sym, v.Type)
                        fld.Nname = asTypesNode(v)
-                       fld.Type = v.Type
-                       fld.Sym = v.Sym
                        params = append(params, fld)
                }
 
index 6e90eb4d65bcd66ab882068a0e1186c1f99939e1..96c3a6faba9db4d34a4c836ab63c236311e15054 100644 (file)
@@ -543,35 +543,19 @@ func structfield(n *Node) *types.Field {
                Fatalf("structfield: oops %v\n", n)
        }
 
-       f := types.NewField()
-       f.Pos = n.Pos
-       f.Sym = n.Sym
-
        if n.Left != nil {
                n.Left = typecheck(n.Left, ctxType)
                n.Type = n.Left.Type
                n.Left = nil
        }
 
-       f.Type = n.Type
-       if f.Type == nil {
-               f.SetBroke(true)
-       }
-
+       f := types.NewField(n.Pos, n.Sym, n.Type)
        if n.Embedded() {
                checkembeddedtype(n.Type)
                f.Embedded = 1
-       } else {
-               f.Embedded = 0
        }
-
-       switch u := n.Val().U.(type) {
-       case string:
-               f.Note = u
-       default:
-               yyerror("field tag must be a string")
-       case nil:
-               // no-op
+       if n.HasVal() {
+               f.Note = n.Val().U.(string)
        }
 
        lineno = lno
@@ -671,13 +655,7 @@ func interfacefield(n *Node) *types.Field {
                n.Left = nil
        }
 
-       f := types.NewField()
-       f.Pos = n.Pos
-       f.Sym = n.Sym
-       f.Type = n.Type
-       if f.Type == nil {
-               f.SetBroke(true)
-       }
+       f := types.NewField(n.Pos, n.Sym, n.Type)
 
        lineno = lno
        return f
@@ -705,9 +683,7 @@ func fakeRecv() *Node {
 }
 
 func fakeRecvField() *types.Field {
-       f := types.NewField()
-       f.Type = types.FakeRecvType()
-       return f
+       return types.NewField(src.NoXPos, nil, types.FakeRecvType())
 }
 
 // isifacemethod reports whether (field) m is
@@ -920,10 +896,7 @@ func addmethod(msym *types.Sym, t *types.Type, local, nointerface bool) *types.F
                return f
        }
 
-       f := types.NewField()
-       f.Pos = lineno
-       f.Sym = msym
-       f.Type = t
+       f := types.NewField(lineno, msym, t)
        f.SetNointerface(nointerface)
 
        mt.Methods().Append(f)
index c0114d0e53b166be1daf6cc9554006ad744b1ff2..376a167e166da503f1bb6468623e2e092572db13 100644 (file)
@@ -327,11 +327,7 @@ func (r *importReader) doDecl(n *Node) {
                        recv := r.param()
                        mtyp := r.signature(recv)
 
-                       f := types.NewField()
-                       f.Pos = mpos
-                       f.Sym = msym
-                       f.Type = mtyp
-                       ms[i] = f
+                       ms[i] = types.NewField(mpos, msym, mtyp)
 
                        m := newfuncnamel(mpos, methodSym(recv.Type, msym))
                        m.Type = mtyp
@@ -547,10 +543,7 @@ func (r *importReader) typ1() *types.Type {
                        emb := r.bool()
                        note := r.string()
 
-                       f := types.NewField()
-                       f.Pos = pos
-                       f.Sym = sym
-                       f.Type = typ
+                       f := types.NewField(pos, sym, typ)
                        if emb {
                                f.Embedded = 1
                        }
@@ -571,10 +564,7 @@ func (r *importReader) typ1() *types.Type {
                        pos := r.pos()
                        typ := r.typ()
 
-                       f := types.NewField()
-                       f.Pos = pos
-                       f.Type = typ
-                       embeddeds[i] = f
+                       embeddeds[i] = types.NewField(pos, nil, typ)
                }
 
                methods := make([]*types.Field, r.uint64())
@@ -583,11 +573,7 @@ func (r *importReader) typ1() *types.Type {
                        sym := r.ident()
                        typ := r.signature(fakeRecvField())
 
-                       f := types.NewField()
-                       f.Pos = pos
-                       f.Sym = sym
-                       f.Type = typ
-                       methods[i] = f
+                       methods[i] = types.NewField(pos, sym, typ)
                }
 
                t := types.New(TINTER)
@@ -624,11 +610,7 @@ func (r *importReader) paramList() []*types.Field {
 }
 
 func (r *importReader) param() *types.Field {
-       f := types.NewField()
-       f.Pos = r.pos()
-       f.Sym = r.ident()
-       f.Type = r.typ()
-       return f
+       return types.NewField(r.pos(), r.ident(), r.typ())
 }
 
 func (r *importReader) bool() bool {
index 9401eba7a5021af1ecdd7dea5555363dcfa17d53..05e476b76b2335a594bdbde985fd174e30119a71 100644 (file)
@@ -73,10 +73,8 @@ func uncommonSize(t *types.Type) int { // Sizeof(runtime.uncommontype{})
 }
 
 func makefield(name string, t *types.Type) *types.Field {
-       f := types.NewField()
-       f.Type = t
-       f.Sym = (*types.Pkg)(nil).Lookup(name)
-       return f
+       sym := (*types.Pkg)(nil).Lookup(name)
+       return types.NewField(src.NoXPos, sym, t)
 }
 
 // bmap makes the map bucket type given the type of the map.
@@ -301,13 +299,11 @@ func hiter(t *types.Type) *types.Type {
 // stksize bytes of args.
 func deferstruct(stksize int64) *types.Type {
        makefield := func(name string, typ *types.Type) *types.Field {
-               f := types.NewField()
-               f.Type = typ
                // Unlike the global makefield function, this one needs to set Pkg
                // because these types might be compared (in SSA CSE sorting).
                // TODO: unify this makefield and the global one above.
-               f.Sym = &types.Sym{Name: name, Pkg: localpkg}
-               return f
+               sym := &types.Sym{Name: name, Pkg: localpkg}
+               return types.NewField(src.NoXPos, sym, typ)
        }
        argtype := types.NewArray(types.Types[TUINT8], stksize)
        argtype.Width = stksize
index ff8cabd8e38c215a558066fb68b71455d845c783..559d47da1a090a4f1b5c0bebce7bf8995949727a 100644 (file)
@@ -6,7 +6,10 @@
 
 package gc
 
-import "cmd/compile/internal/types"
+import (
+       "cmd/compile/internal/types"
+       "cmd/internal/src"
+)
 
 // builtinpkg is a fake package that declares the universe block.
 var builtinpkg *types.Pkg
@@ -355,16 +358,14 @@ func typeinit() {
 }
 
 func makeErrorInterface() *types.Type {
-       field := types.NewField()
-       field.Type = types.Types[TSTRING]
-       f := functypefield(fakeRecvField(), nil, []*types.Field{field})
+       sig := functypefield(fakeRecvField(), nil, []*types.Field{
+               types.NewField(src.NoXPos, nil, types.Types[TSTRING]),
+       })
 
-       field = types.NewField()
-       field.Sym = lookup("Error")
-       field.Type = f
+       method := types.NewField(src.NoXPos, lookup("Error"), sig)
 
        t := types.New(TINTER)
-       t.SetInterface([]*types.Field{field})
+       t.SetInterface([]*types.Field{method})
        return t
 }
 
index 023ab9af88aee048f29fd88b5596e515360f0fd2..c6d14e9e0981d0f51456671da221567e117f0ef5 100644 (file)
@@ -583,10 +583,17 @@ func NewFuncArgs(f *Type) *Type {
        return t
 }
 
-func NewField() *Field {
-       return &Field{
+func NewField(pos src.XPos, sym *Sym, typ *Type) *Field {
+       f := &Field{
+               Pos:    pos,
+               Sym:    sym,
+               Type:   typ,
                Offset: BADWIDTH,
        }
+       if typ == nil {
+               f.SetBroke(true)
+       }
+       return f
 }
 
 // SubstAny walks t, replacing instances of "any" with successive