aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/expr.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2023-08-23 13:52:25 -0700
committerGopher Robot <gobot@golang.org>2023-08-24 07:17:27 +0000
commitd5c5808534f0ad97333b1fd5fff81998f44986fe (patch)
tree5fb63e5dd9910566ecf7f86fca171e95d20fe61c /src/cmd/compile/internal/noder/expr.go
parent43e69b330a71e0d101bd57f0a1ea83bc4da259f3 (diff)
downloadgo-d5c5808534f0ad97333b1fd5fff81998f44986fe.tar.xz
cmd/compile/internal/syntax: add Unparen and UnpackListExpr helpers
We've added Unparen to go/ast, so add syntax.Unparen to be consistent (and because it's similarly useful). Also, types2 and noder both have similar functions for unpacking ListExprs, so might as well add a common implementation in package syntax too. Finally, addressing the TODO: UnpackListExpr is small enough to be inlined (when default optimizations are enabled), and for typical uses of UnpackListExpr (e.g., "range UnpackListExpr(x)") the single-element slice result is stack allocated in the caller. This CL adds a test using testing.AllocsPerRun to ensure this remains so in the future. Change-Id: I96a5591d202193ed5bf1ce6f290919107e3dc01b Reviewed-on: https://go-review.googlesource.com/c/go/+/522336 Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder/expr.go')
-rw-r--r--src/cmd/compile/internal/noder/expr.go21
1 files changed, 0 insertions, 21 deletions
diff --git a/src/cmd/compile/internal/noder/expr.go b/src/cmd/compile/internal/noder/expr.go
index 51b0656385..14ef3b958f 100644
--- a/src/cmd/compile/internal/noder/expr.go
+++ b/src/cmd/compile/internal/noder/expr.go
@@ -11,17 +11,6 @@ import (
"cmd/compile/internal/syntax"
)
-func unpackListExpr(expr syntax.Expr) []syntax.Expr {
- switch expr := expr.(type) {
- case nil:
- return nil
- case *syntax.ListExpr:
- return expr.ElemList
- default:
- return []syntax.Expr{expr}
- }
-}
-
// constExprOp returns an ir.Op that represents the outermost
// operation of the given constant expression. It's intended for use
// with ir.RawOrigExpr.
@@ -43,13 +32,3 @@ func constExprOp(expr syntax.Expr) ir.Op {
return binOps[expr.Op]
}
}
-
-func unparen(expr syntax.Expr) syntax.Expr {
- for {
- paren, ok := expr.(*syntax.ParenExpr)
- if !ok {
- return expr
- }
- expr = paren.X
- }
-}