]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: get rid of Type's {This,In,Out}tuple fields
authorMatthew Dempsky <mdempsky@google.com>
Thu, 17 Mar 2016 08:47:16 +0000 (01:47 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 17 Mar 2016 19:38:30 +0000 (19:38 +0000)
Boolean expressions involving t.Thistuple were converted to use
t.Recv(), because it's a bit clearer and will hopefully reveal cases
where we could remove redundant calls to t.Recv() (in followup CLs).

The other cases were all converted to use t.Recvs().NumFields(),
t.Params().NumFields(), or t.Results().NumFields().

Change-Id: I4df91762e7dc4b2ddae35995f8dd604a52c09b09
Reviewed-on: https://go-review.googlesource.com/20796
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>

15 files changed:
src/cmd/compile/internal/gc/closure.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/esc.go
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/fmt.go
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/order.go
src/cmd/compile/internal/gc/pgen.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/sizeof_test.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/type.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/universe.go
src/cmd/compile/internal/gc/walk.go

index ed373568ad8d37efdf059397340fd7dc24fc851c..10faf52a6f5dd2de1f2253cd361f0ee5d243f04c 100644 (file)
@@ -595,7 +595,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
        call := Nod(OCALL, Nod(OXDOT, ptr, meth), nil)
        call.List.Set(callargs)
        call.Isddd = ddd
-       if t0.Outtuple == 0 {
+       if t0.Results().NumFields() == 0 {
                body = append(body, call)
        } else {
                n := Nod(OAS2, nil, nil)
index 6d1e6f4223711f4d0a9323a0ab6b17f562e87bca..8b05cdb23ae5a2b30ba0364d0fbd3def98eba222 100644 (file)
@@ -655,37 +655,31 @@ func funcargs2(t *Type) {
                Fatalf("funcargs2 %v", t)
        }
 
-       if t.Thistuple != 0 {
-               for _, ft := range t.Recvs().Fields().Slice() {
-                       if ft.Nname == nil || ft.Nname.Sym == nil {
-                               continue
-                       }
-                       n := ft.Nname // no need for newname(ft->nname->sym)
-                       n.Type = ft.Type
-                       declare(n, PPARAM)
+       for _, ft := range t.Recvs().Fields().Slice() {
+               if ft.Nname == nil || ft.Nname.Sym == nil {
+                       continue
                }
+               n := ft.Nname // no need for newname(ft->nname->sym)
+               n.Type = ft.Type
+               declare(n, PPARAM)
        }
 
-       if t.Intuple != 0 {
-               for _, ft := range t.Params().Fields().Slice() {
-                       if ft.Nname == nil || ft.Nname.Sym == nil {
-                               continue
-                       }
-                       n := ft.Nname
-                       n.Type = ft.Type
-                       declare(n, PPARAM)
+       for _, ft := range t.Params().Fields().Slice() {
+               if ft.Nname == nil || ft.Nname.Sym == nil {
+                       continue
                }
+               n := ft.Nname
+               n.Type = ft.Type
+               declare(n, PPARAM)
        }
 
-       if t.Outtuple != 0 {
-               for _, ft := range t.Results().Fields().Slice() {
-                       if ft.Nname == nil || ft.Nname.Sym == nil {
-                               continue
-                       }
-                       n := ft.Nname
-                       n.Type = ft.Type
-                       declare(n, PPARAMOUT)
+       for _, ft := range t.Results().Fields().Slice() {
+               if ft.Nname == nil || ft.Nname.Sym == nil {
+                       continue
                }
+               n := ft.Nname
+               n.Type = ft.Type
+               declare(n, PPARAMOUT)
        }
 }
 
@@ -1068,13 +1062,8 @@ func functype0(t *Type, this *Node, in, out []*Node) {
                t.Broke = true
        }
 
-       if this != nil {
-               t.Thistuple = 1
-       }
-       t.Outtuple = len(out)
-       t.Intuple = len(in)
        t.Outnamed = false
-       if t.Outtuple > 0 && out[0].Left != nil && out[0].Left.Orig != nil {
+       if len(out) > 0 && out[0].Left != nil && out[0].Left.Orig != nil {
                s := out[0].Left.Orig.Sym
                if s != nil && (s.Name[0] != '~' || s.Name[1] != 'r') { // ~r%d is the name invented for an unnamed result
                        t.Outnamed = true
index 21fc2695a0e148bd4b1f576553c0d3722a6e1b97..aa75cc7cbd200a14f39adba379a9354175065f46 100644 (file)
@@ -810,7 +810,7 @@ func esc(e *EscState, n *Node, up *Node) {
 
        case ORETURN:
                ll := n.List
-               if n.List.Len() == 1 && Curfn.Type.Outtuple > 1 {
+               if n.List.Len() == 1 && Curfn.Type.Results().NumFields() > 1 {
                        // OAS2FUNC in disguise
                        // esccall already done on n->list->n
                        // tie n->list->n->escretval to curfn->dcl PPARAMOUT's
index ef0d856c8ded2bd2e573a66dd2e31b253cb78601..3e6b517436a914548e5e832d578a55a74361ec1c 100644 (file)
@@ -130,7 +130,7 @@ func reexportdep(n *Node) {
                        }
 
                        // nodes for method calls.
-                       if n.Type == nil || n.Type.Thistuple > 0 {
+                       if n.Type == nil || n.Type.Recv() != nil {
                                break
                        }
                        fallthrough
index 3af269d4ddfeadf01a42c4cd75df5bd2e3714213..73b030dd8a04f0ecc94add64248f9eaa3fd2e7d5 100644 (file)
@@ -630,7 +630,7 @@ func typefmt(t *Type, flag FmtFlag) string {
                if flag&FmtShort != 0 {
                        // no leading func
                } else {
-                       if t.Thistuple != 0 {
+                       if t.Recv() != nil {
                                buf.WriteString("method")
                                buf.WriteString(Tconv(t.Recvs(), 0))
                                buf.WriteString(" ")
@@ -639,7 +639,7 @@ func typefmt(t *Type, flag FmtFlag) string {
                }
                buf.WriteString(Tconv(t.Params(), 0))
 
-               switch t.Outtuple {
+               switch t.Results().NumFields() {
                case 0:
                        break
 
index abe576eed18e40f81064efae2bd0af0b6e9baf41..15922abb590b0b92655199bc5ae640362710218e 100644 (file)
@@ -34,7 +34,7 @@ import (
 // Get the function's package. For ordinary functions it's on the ->sym, but for imported methods
 // the ->sym can be re-used in the local package, so peel it off the receiver's type.
 func fnpkg(fn *Node) *Pkg {
-       if fn.Type.Thistuple != 0 {
+       if fn.Type.Recv() != nil {
                // method
                rcvr := fn.Type.Recv().Type
 
@@ -592,7 +592,7 @@ func mkinlcall1(np **Node, fn *Node, isddd bool) {
        }
 
        // assign receiver.
-       if fn.Type.Thistuple != 0 && n.Left.Op == ODOTMETH {
+       if fn.Type.Recv() != nil && n.Left.Op == ODOTMETH {
                // method call with a receiver.
                t := fn.Type.Recv()
 
@@ -635,8 +635,8 @@ func mkinlcall1(np **Node, fn *Node, isddd bool) {
        if n.List.Len() == 1 {
                switch n.List.First().Op {
                case OCALL, OCALLFUNC, OCALLINTER, OCALLMETH:
-                       if n.List.First().Left.Type.Outtuple > 1 {
-                               multiret = n.List.First().Left.Type.Outtuple - 1
+                       if n.List.First().Left.Type.Results().NumFields() > 1 {
+                               multiret = n.List.First().Left.Type.Results().NumFields() - 1
                        }
                }
        }
@@ -644,9 +644,9 @@ func mkinlcall1(np **Node, fn *Node, isddd bool) {
        if variadic {
                varargcount = n.List.Len() + multiret
                if n.Left.Op != ODOTMETH {
-                       varargcount -= fn.Type.Thistuple
+                       varargcount -= fn.Type.Recvs().NumFields()
                }
-               varargcount -= fn.Type.Intuple - 1
+               varargcount -= fn.Type.Params().NumFields() - 1
        }
 
        // assign arguments to the parameters' temp names
@@ -656,7 +656,7 @@ func mkinlcall1(np **Node, fn *Node, isddd bool) {
        li := 0
 
        // TODO: if len(nlist) == 1 but multiple args, check that n->list->n is a call?
-       if fn.Type.Thistuple != 0 && n.Left.Op != ODOTMETH {
+       if fn.Type.Recv() != nil && n.Left.Op != ODOTMETH {
                // non-method call to method
                if n.List.Len() == 0 {
                        Fatalf("non-method call to method without first arg: %v", Nconv(n, FmtSign))
index 14e70be10dd840e378f9d5c363e9fac44affaaea..fa2cea7fbf65ecb59c71a0b4dddb6da3c319f327 100644 (file)
@@ -326,14 +326,14 @@ func ismulticall(l Nodes) bool {
        }
 
        // call must return multiple values
-       return n.Left.Type.Outtuple > 1
+       return n.Left.Type.Results().NumFields() > 1
 }
 
 // Copyret emits t1, t2, ... = n, where n is a function call,
 // and then returns the list t1, t2, ....
 func copyret(n *Node, order *Order) []*Node {
        if n.Type.Etype != TSTRUCT || !n.Type.Funarg {
-               Fatalf("copyret %v %d", n.Type, n.Left.Type.Outtuple)
+               Fatalf("copyret %v %d", n.Type, n.Left.Type.Results().NumFields())
        }
 
        var l1 []*Node
index 6abb57d490c19b83baa57cd635eb53f3693cf384..43b692d59d1fa4dad63d05f69c74765b6a9645ac 100644 (file)
@@ -147,18 +147,18 @@ func emitptrargsmap() {
        nptr := int(Curfn.Type.Argwid / int64(Widthptr))
        bv := bvalloc(int32(nptr) * 2)
        nbitmap := 1
-       if Curfn.Type.Outtuple > 0 {
+       if Curfn.Type.Results().NumFields() > 0 {
                nbitmap = 2
        }
        off := duint32(sym, 0, uint32(nbitmap))
        off = duint32(sym, off, uint32(bv.n))
        var xoffset int64
-       if Curfn.Type.Thistuple > 0 {
+       if Curfn.Type.Recv() != nil {
                xoffset = 0
                onebitwalktype1(Curfn.Type.Recvs(), &xoffset, bv)
        }
 
-       if Curfn.Type.Intuple > 0 {
+       if Curfn.Type.Params().NumFields() > 0 {
                xoffset = 0
                onebitwalktype1(Curfn.Type.Params(), &xoffset, bv)
        }
@@ -166,7 +166,7 @@ func emitptrargsmap() {
        for j := 0; int32(j) < bv.n; j += 32 {
                off = duint32(sym, off, bv.b[j/32])
        }
-       if Curfn.Type.Outtuple > 0 {
+       if Curfn.Type.Results().NumFields() > 0 {
                xoffset = 0
                onebitwalktype1(Curfn.Type.Results(), &xoffset, bv)
                for j := 0; int32(j) < bv.n; j += 32 {
@@ -503,7 +503,7 @@ func genlegacy(ptxt *obj.Prog, gcargs, gclocals *Sym) {
                lineno = Curfn.Func.Endlineno
        }
 
-       if Curfn.Type.Outtuple != 0 {
+       if Curfn.Type.Results().NumFields() != 0 {
                Ginscall(throwreturn, 0)
        }
 
index b5a7a97c8547f80acddc78293ee6a0d4e4c2cb78..a414d1b3c0b8994ae573c9263965f02bcde3bc06 100644 (file)
@@ -286,7 +286,7 @@ func methods(t *Type) []*Sig {
        // generating code if necessary.
        var ms []*Sig
        for _, f := range mt.AllMethods().Slice() {
-               if f.Type.Etype != TFUNC || f.Type.Thistuple == 0 {
+               if f.Type.Etype != TFUNC || f.Type.Recv() == nil {
                        Fatalf("non-method on %v method %v %v\n", mt, f.Sym, f)
                }
                if f.Type.Recv() == nil {
@@ -1041,8 +1041,8 @@ ok:
                }
 
                ot = dcommontype(s, ot, t)
-               inCount := t.Thistuple + t.Intuple
-               outCount := t.Outtuple
+               inCount := t.Recvs().NumFields() + t.Params().NumFields()
+               outCount := t.Results().NumFields()
                if isddd {
                        outCount |= 1 << 15
                }
@@ -1052,7 +1052,7 @@ ok:
                        ot += 4 // align for *rtype
                }
 
-               dataAdd := (inCount + t.Outtuple) * Widthptr
+               dataAdd := (inCount + t.Results().NumFields()) * Widthptr
                ot = dextratype(s, ot, t, dataAdd)
 
                // Array of rtype pointers follows funcType.
index 6578593a8c5ca7dbb55be3ae557791f8f6c43c52..11c0f419da50e26d66ace38a35391b190e338973 100644 (file)
@@ -27,7 +27,7 @@ func TestSizeof(t *testing.T) {
                {Name{}, 52, 80},
                {Node{}, 92, 144},
                {Sym{}, 60, 112},
-               {Type{}, 132, 224},
+               {Type{}, 116, 184},
        }
 
        for _, tt := range tests {
index 26d45700e5d0a0be8b9f36e2a74b9ec470ce20c9..8d2d5008e3187a0860c99260bda0cf5486c6ddb3 100644 (file)
@@ -1556,7 +1556,7 @@ func lookdot0(s *Sym, t *Type, save **Field, ignorecase bool) int {
        c := 0
        if u.Etype == TSTRUCT || u.Etype == TINTER {
                for _, f := range u.Fields().Slice() {
-                       if f.Sym == s || (ignorecase && f.Type.Etype == TFUNC && f.Type.Thistuple > 0 && strings.EqualFold(f.Sym.Name, s.Name)) {
+                       if f.Sym == s || (ignorecase && f.Type.Etype == TFUNC && f.Type.Recv() != nil && strings.EqualFold(f.Sym.Name, s.Name)) {
                                if save != nil {
                                        *save = f
                                }
@@ -1807,7 +1807,7 @@ func expandmeth(t *Type) {
                }
 
                // dotpath may have dug out arbitrary fields, we only want methods.
-               if f.Type.Etype != TFUNC || f.Type.Thistuple == 0 {
+               if f.Type.Etype != TFUNC || f.Type.Recv() == nil {
                        continue
                }
 
@@ -1981,7 +1981,7 @@ func genwrapper(rcvr *Type, method *Field, newnam *Sym, iface int) {
                call := Nod(OCALL, dot, nil)
                call.List.Set(args)
                call.Isddd = isddd
-               if method.Type.Outtuple > 0 {
+               if method.Type.Results().NumFields() > 0 {
                        n := Nod(ORETURN, nil, nil)
                        n.List.Set1(call)
                        call = n
@@ -2051,7 +2051,7 @@ func ifacelookdot(s *Sym, t *Type, followptr *bool, ignorecase bool) *Field {
                }
        }
 
-       if m.Type.Etype != TFUNC || m.Type.Thistuple == 0 {
+       if m.Type.Etype != TFUNC || m.Type.Recv() == nil {
                Yyerror("%v.%v is a field, not a method", t, s)
                return nil
        }
index d328d2b96d7db72509835f7b1541fd1a01641232..624c506626018430a97fa19dd4ab6049897f2251 100644 (file)
@@ -112,22 +112,17 @@ type Type struct {
        Broke       bool // broken type definition.
        Align       uint8
        Haspointers uint8 // 0 unknown, 1 no, 2 yes
+       Outnamed    bool  // on TFUNC
 
-       Nod    *Node // canonical OTYPE node
-       Orig   *Type // original type (type literal or predefined type)
-       Lineno int32
-
-       // TFUNC
-       Thistuple int
-       Outtuple  int
-       Intuple   int
-       Outnamed  bool
+       Nod  *Node // canonical OTYPE node
+       Orig *Type // original type (type literal or predefined type)
 
        methods    Fields
        allMethods Fields
 
        Sym    *Sym
        Vargen int32 // unique name for OTYPE/ONAME
+       Lineno int32
 
        Nname  *Node
        Argwid int64
index d0de0834c208096a64c44d7baa8a0c6af3aa6abb..1a28745f7489be301f89fd3df0e18bc7d91fa577 100644 (file)
@@ -845,7 +845,7 @@ OpSwitch:
                                return
                        }
 
-                       if n.Type.Etype != TFUNC || n.Type.Thistuple != 1 {
+                       if n.Type.Etype != TFUNC || n.Type.Recv() == nil {
                                Yyerror("type %v has no method %v", n.Left.Type, Sconv(n.Right.Sym, FmtShort))
                                n.Type = nil
                                n.Type = nil
@@ -1327,11 +1327,11 @@ OpSwitch:
 
                typecheckaste(OCALL, n.Left, n.Isddd, t.Params(), n.List, func() string { return fmt.Sprintf("argument to %v", n.Left) })
                ok |= Etop
-               if t.Outtuple == 0 {
+               if t.Results().NumFields() == 0 {
                        break OpSwitch
                }
                ok |= Erv
-               if t.Outtuple == 1 {
+               if t.Results().NumFields() == 1 {
                        n.Type = l.Type.Results().Field(0).Type
 
                        if n.Op == OCALLFUNC && n.Left.Op == ONAME && (compiling_runtime != 0 || n.Left.Sym.Pkg == Runtimepkg) && n.Left.Sym.Name == "getg" {
@@ -1445,8 +1445,8 @@ OpSwitch:
                        }
 
                        t := n.List.First().Left.Type
-                       if t.Outtuple != 2 {
-                               Yyerror("invalid operation: complex expects two arguments, %v returns %d results", n.List.First(), t.Outtuple)
+                       if t.Results().NumFields() != 2 {
+                               Yyerror("invalid operation: complex expects two arguments, %v returns %d results", n.List.First(), t.Results().NumFields())
                                n.Type = nil
                                return
                        }
@@ -3957,7 +3957,7 @@ func (n *Node) isterminating() bool {
 }
 
 func checkreturn(fn *Node) {
-       if fn.Type.Outtuple != 0 && len(fn.Nbody.Slice()) != 0 {
+       if fn.Type.Results().NumFields() != 0 && len(fn.Nbody.Slice()) != 0 {
                markbreaklist(fn.Nbody, nil)
                if !fn.Nbody.isterminating() {
                        yyerrorl(fn.Func.Endlineno, "missing return at end of function")
index 277a530ff34e7043da8b4881535681d79cc77421..cf310d49f03e3749501c5decaa843f52a95d9178 100644 (file)
@@ -387,10 +387,6 @@ func lexinit1() {
        *f.RecvsP() = rcvr
        *f.ResultsP() = out
        *f.ParamsP() = in
-       f.Thistuple = 1
-       f.Intuple = 0
-       f.Outnamed = false
-       f.Outtuple = 1
 
        t := typ(TINTER)
        field = newField()
index 4e3079fd7e9f59ca1a6a7a7fe7a3047d7ce9b440..6d136f6272df113d6647372efbac82dfd603bc89 100644 (file)
@@ -657,7 +657,7 @@ opswitch:
 
                        // Update type of OCALLFUNC node.
                        // Output arguments had not changed, but their offsets could.
-                       if n.Left.Type.Outtuple == 1 {
+                       if n.Left.Type.Results().NumFields() == 1 {
                                n.Type = n.Left.Type.Results().Field(0).Type
                        } else {
                                n.Type = n.Left.Type.Results()
@@ -2634,11 +2634,11 @@ func vmkcall(fn *Node, t *Type, init *Nodes, va []*Node) *Node {
                Fatalf("mkcall %v %v", fn, fn.Type)
        }
 
-       n := fn.Type.Intuple
+       n := fn.Type.Params().NumFields()
 
        r := Nod(OCALL, fn, nil)
        r.List.Set(va[:n])
-       if fn.Type.Outtuple > 0 {
+       if fn.Type.Results().NumFields() > 0 {
                typecheck(&r, Erv|Efnstruct)
        } else {
                typecheck(&r, Etop)