]> Cypherpunks repositories - gostls13.git/commit
[dev.typeparams] cmd/compile: refactor closure construction
authorMatthew Dempsky <mdempsky@google.com>
Fri, 11 Jun 2021 10:09:26 +0000 (03:09 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Sat, 12 Jun 2021 13:53:19 +0000 (13:53 +0000)
commit0132b91127c3cf6e19e0e1db014a04219427171e
tree577fb27f75e4b57916072c31f343bde8f8a6aefc
parent8f00eb009978e2e1bb681e698a0b51e20333eb05
[dev.typeparams] cmd/compile: refactor closure construction

typecheck.tcClosure is complicated with many code flows because all of
its callers setup the closure funcs in slightly different ways. E.g.,
it's non-obvious who's responsible for setting the underlying func's
Sym or adding it to target.Decls, or how to write new code that
constructs a closure without interfering with existing code.

This CL refactors everything to use three common functions in package
ir: NewClosureFunc (which handle creating the Func, Name, and
ClosureExpr and wiring them together), NameClosure (which generates
and assigns its unique Sym), and UseClosure (which handles adding the
Func to target.Decls).

Most IR builders can actually name the closure right away, but the
legacy noder+typecheck path may not yet know the name of the enclosing
function. In particular, for methods declared with aliased receiver
parameters, we need to wait until after typechecking top-level
declarations to know the method's true name. So they're left anonymous
until typecheck.

UseClosure does relatively little work today, but it serves as a
useful spot to check that the code setting up closures got it right.
It may also eventually serve as an optimization point for early
lifting of trivial closures, which may or may not ultimately be
beneficial.

Change-Id: I7da1e93c70d268f575b12d6aaeb2336eb910a6f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/327051
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/inline/inl.go
src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/ir/func.go
src/cmd/compile/internal/noder/expr.go
src/cmd/compile/internal/noder/noder.go
src/cmd/compile/internal/noder/stencil.go
src/cmd/compile/internal/typecheck/func.go
src/cmd/compile/internal/typecheck/iimport.go
src/cmd/compile/internal/typecheck/typecheck.go
src/cmd/compile/internal/walk/order.go