]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: remove genericMultiExpr (inline it in genericExprList)
authorRobert Griesemer <gri@golang.org>
Mon, 8 May 2023 20:01:21 +0000 (13:01 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 8 May 2023 21:06:22 +0000 (21:06 +0000)
Also, remove named return values for exprList, genericExprList.

Change-Id: I099abff4572530dd0c3b39c92d6b9a4662d95c2d
Reviewed-on: https://go-review.googlesource.com/c/go/+/493557
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/expr.go
src/go/types/call.go
src/go/types/expr.go

index ac5efad93d255b81afa56edf906639b1d56fe1a4..23738e2aac9ddcb163d442766ddc8a3df67767f0 100644 (file)
@@ -343,41 +343,61 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
 
 // exprList evaluates a list of expressions and returns the corresponding operands.
 // A single-element expression list may evaluate to multiple operands.
-func (check *Checker) exprList(elist []syntax.Expr) (xlist []*operand) {
+func (check *Checker) exprList(elist []syntax.Expr) []*operand {
        switch len(elist) {
        case 0:
-               // nothing to do
+               return nil
+
        case 1:
-               xlist, _ = check.multiExpr(elist[0], false)
+               xlist, _ := check.multiExpr(elist[0], false)
+               return xlist
+
        default:
                // multiple (possibly invalid) values
-               xlist = make([]*operand, len(elist))
+               xlist := make([]*operand, len(elist))
                for i, e := range elist {
                        var x operand
                        check.expr(nil, &x, e)
                        xlist[i] = &x
                }
+               return xlist
        }
-       return
 }
 
 // genericExprList is like exprList but result operands may be generic (not fully instantiated).
-func (check *Checker) genericExprList(elist []syntax.Expr) (xlist []*operand) {
+func (check *Checker) genericExprList(elist []syntax.Expr) []*operand {
        switch len(elist) {
        case 0:
-               // nothing to do
+               return nil
+
        case 1:
-               xlist = check.genericMultiExpr(elist[0])
+               e := elist[0]
+               var x operand
+               check.rawExpr(nil, &x, e, nil, true)
+               check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
+
+               if t, ok := x.typ.(*Tuple); ok && x.mode != invalid {
+                       // multiple values - cannot be generic
+                       xlist := make([]*operand, t.Len())
+                       for i, v := range t.vars {
+                               xlist[i] = &operand{mode: value, expr: e, typ: v.typ}
+                       }
+                       return xlist
+               }
+
+               // exactly one (possible invalid or generic) value
+               return []*operand{&x}
+
        default:
                // multiple (possibly invalid) values
-               xlist = make([]*operand, len(elist))
+               xlist := make([]*operand, len(elist))
                for i, e := range elist {
                        var x operand
                        check.genericExpr(&x, e)
                        xlist[i] = &x
                }
+               return xlist
        }
-       return
 }
 
 // xlist is the list of type argument expressions supplied in the source code.
index c4e8a4696c03e5b8588b03e71e013ffd188ab715..93ca24addc19efd13ff219e0d1f409fa0c2b01f9 100644 (file)
@@ -1876,27 +1876,6 @@ func (check *Checker) multiExpr(e syntax.Expr, allowCommaOk bool) (list []*opera
        return
 }
 
-// genericMultiExpr is like multiExpr but a one-element result may also be generic
-// and potential comma-ok expressions are returned as single values.
-func (check *Checker) genericMultiExpr(e syntax.Expr) (list []*operand) {
-       var x operand
-       check.rawExpr(nil, &x, e, nil, true)
-       check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
-
-       if t, ok := x.typ.(*Tuple); ok && x.mode != invalid {
-               // multiple values - cannot be generic
-               list = make([]*operand, t.Len())
-               for i, v := range t.vars {
-                       list[i] = &operand{mode: value, expr: e, typ: v.typ}
-               }
-               return
-       }
-
-       // exactly one (possible invalid or generic) value
-       list = []*operand{&x}
-       return
-}
-
 // exprWithHint typechecks expression e and initializes x with the expression value;
 // hint is the type of a composite literal element.
 // If an error occurred, x.mode is set to invalid.
index 4ee84c2f73f2d8113a6e4f620a67bc158619a8c5..f2ff4cf857b029fcaca376656012fa855aa7702f 100644 (file)
@@ -348,41 +348,61 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
 
 // exprList evaluates a list of expressions and returns the corresponding operands.
 // A single-element expression list may evaluate to multiple operands.
-func (check *Checker) exprList(elist []ast.Expr) (xlist []*operand) {
+func (check *Checker) exprList(elist []ast.Expr) []*operand {
        switch len(elist) {
        case 0:
-               // nothing to do
+               return nil
+
        case 1:
-               xlist, _ = check.multiExpr(elist[0], false)
+               xlist, _ := check.multiExpr(elist[0], false)
+               return xlist
+
        default:
                // multiple (possibly invalid) values
-               xlist = make([]*operand, len(elist))
+               xlist := make([]*operand, len(elist))
                for i, e := range elist {
                        var x operand
                        check.expr(nil, &x, e)
                        xlist[i] = &x
                }
+               return xlist
        }
-       return
 }
 
 // genericExprList is like exprList but result operands may be generic (not fully instantiated).
-func (check *Checker) genericExprList(elist []ast.Expr) (xlist []*operand) {
+func (check *Checker) genericExprList(elist []ast.Expr) []*operand {
        switch len(elist) {
        case 0:
-               // nothing to do
+               return nil
+
        case 1:
-               xlist = check.genericMultiExpr(elist[0])
+               e := elist[0]
+               var x operand
+               check.rawExpr(nil, &x, e, nil, true)
+               check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
+
+               if t, ok := x.typ.(*Tuple); ok && x.mode != invalid {
+                       // multiple values - cannot be generic
+                       xlist := make([]*operand, t.Len())
+                       for i, v := range t.vars {
+                               xlist[i] = &operand{mode: value, expr: e, typ: v.typ}
+                       }
+                       return xlist
+               }
+
+               // exactly one (possible invalid or generic) value
+               return []*operand{&x}
+
        default:
                // multiple (possibly invalid) values
-               xlist = make([]*operand, len(elist))
+               xlist := make([]*operand, len(elist))
                for i, e := range elist {
                        var x operand
                        check.genericExpr(&x, e)
                        xlist[i] = &x
                }
+               return xlist
        }
-       return
 }
 
 // xlist is the list of type argument expressions supplied in the source code.
index 2923d9eb36097d7780fbc1f26e316d00eda940d7..59f0b7481a5ec9d06265c6201d5f8c7793423b42 100644 (file)
@@ -1823,27 +1823,6 @@ func (check *Checker) multiExpr(e ast.Expr, allowCommaOk bool) (list []*operand,
        return
 }
 
-// genericMultiExpr is like multiExpr but a one-element result may also be generic
-// and potential comma-ok expressions are returned as single values.
-func (check *Checker) genericMultiExpr(e ast.Expr) (list []*operand) {
-       var x operand
-       check.rawExpr(nil, &x, e, nil, true)
-       check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
-
-       if t, ok := x.typ.(*Tuple); ok && x.mode != invalid {
-               // multiple values - cannot be generic
-               list = make([]*operand, t.Len())
-               for i, v := range t.vars {
-                       list[i] = &operand{mode: value, expr: e, typ: v.typ}
-               }
-               return
-       }
-
-       // exactly one (possible invalid or generic) value
-       list = []*operand{&x}
-       return
-}
-
 // exprWithHint typechecks expression e and initializes x with the expression value;
 // hint is the type of a composite literal element.
 // If an error occurred, x.mode is set to invalid.