]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile/internal/syntax: add Unparen and UnpackListExpr helpers
authorMatthew Dempsky <mdempsky@google.com>
Wed, 23 Aug 2023 20:52:25 +0000 (13:52 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 24 Aug 2023 07:17:27 +0000 (07:17 +0000)
commitd5c5808534f0ad97333b1fd5fff81998f44986fe
tree5fb63e5dd9910566ecf7f86fca171e95d20fe61c
parent43e69b330a71e0d101bd57f0a1ea83bc4da259f3
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>
15 files changed:
src/cmd/compile/internal/noder/expr.go
src/cmd/compile/internal/noder/quirks.go
src/cmd/compile/internal/noder/writer.go
src/cmd/compile/internal/syntax/parser.go
src/cmd/compile/internal/syntax/parser_test.go
src/cmd/compile/internal/syntax/printer.go
src/cmd/compile/internal/types2/assignments.go
src/cmd/compile/internal/types2/builtins.go
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/resolver.go
src/cmd/compile/internal/types2/return.go
src/cmd/compile/internal/types2/stmt.go
src/cmd/compile/internal/types2/typexpr.go