diff options
author | Dan Scales <danscales@google.com> | 2021-04-11 09:47:13 -0700 |
---|---|---|
committer | Dan Scales <danscales@google.com> | 2021-04-14 01:28:16 +0000 |
commit | eb433ed5a2ab13567cd5d7f0413308174750d5dd (patch) | |
tree | 46a288276cc027b310388eb3498e07cef9de024e /src/cmd/compile/internal | |
parent | 8dcc071063c0a9f020f0aafd51b7e0a17f0a0746 (diff) | |
download | go-eb433ed5a2ab13567cd5d7f0413308174750d5dd.tar.gz go-eb433ed5a2ab13567cd5d7f0413308174750d5dd.zip |
cmd/compile: set types properly for imported funcs with closures
For the new export/import of node types, we were just missing setting
the types of the closure variables (which have the same types as the
captured variables) and the OCLOSURE node itself (which has the same
type as the Func node).
Re-enabled inlining of functions with closures.
Change-Id: I687149b061f3ffeec3244ff02dc6e946659077a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/308974
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal')
-rw-r--r-- | src/cmd/compile/internal/inline/inl.go | 2 | ||||
-rw-r--r-- | src/cmd/compile/internal/typecheck/iimport.go | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index 4470df1d2a..3cbe932d55 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -354,7 +354,7 @@ func (v *hairyVisitor) doNode(n ir.Node) bool { return true case ir.OCLOSURE: - if base.Debug.InlFuncsWithClosures == 0 || typecheck.Go117ExportTypes { // TODO: remove latter condition + if base.Debug.InlFuncsWithClosures == 0 { v.reason = "not inlining functions with closures" return true } diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go index 0d5d892ef5..42c4619666 100644 --- a/src/cmd/compile/internal/typecheck/iimport.go +++ b/src/cmd/compile/internal/typecheck/iimport.go @@ -1112,6 +1112,14 @@ func (r *importReader) node() ir.Node { cvars := make([]*ir.Name, r.int64()) for i := range cvars { cvars[i] = ir.CaptureName(r.pos(), fn, r.localName().Canonical()) + if go117ExportTypes { + if cvars[i].Type() != nil || cvars[i].Defn == nil { + base.Fatalf("bad import of closure variable") + } + // Closure variable should have Defn set, which is its captured + // variable, and it gets the same type as the captured variable. + cvars[i].SetType(cvars[i].Defn.Type()) + } } fn.ClosureVars = cvars r.allClosureVars = append(r.allClosureVars, cvars...) @@ -1133,6 +1141,9 @@ func (r *importReader) node() ir.Node { clo := ir.NewClosureExpr(pos, fn) fn.OClosure = clo + if go117ExportTypes { + clo.SetType(typ) + } return clo |