diff options
author | Dan Scales <danscales@google.com> | 2020-12-01 14:48:03 -0800 |
---|---|---|
committer | Dan Scales <danscales@google.com> | 2021-01-20 22:53:32 +0000 |
commit | 1760d736f61265b3c78a6a48f2e1904341806643 (patch) | |
tree | fbf7575c435f30ae41e97589adeca569cbe0225e /test/closure5.dir | |
parent | 92cb157cf3aa51d28e441dbb2b671795f22140f8 (diff) | |
download | go-1760d736f61265b3c78a6a48f2e1904341806643.tar.gz go-1760d736f61265b3c78a6a48f2e1904341806643.zip |
[dev.regabi] cmd/compile: exporting, importing, and inlining functions with OCLOSURE
I have exporting, importing, and inlining of functions with closures
working in all cases (issue #28727). all.bash runs successfully without
errors.
Approach:
- Write out the Func type, Dcls, ClosureVars, and Body when exporting
an OCLOSURE.
- When importing an OCLOSURE, read in the type, dcls, closure vars,
and body, and then do roughly equivalent code to (*noder).funcLit
- During inlining of a closure within inlined function, create new
nodes for all params and local variables (including closure
variables), so they can have a new Curfn and some other field
values. Must substitute not only on the Nbody of the closure, but
also the Type, Cvars, and Dcl fields.
Fixes #28727
Change-Id: I4da1e2567c3fa31a5121afbe82dc4e5ee32b3170
Reviewed-on: https://go-review.googlesource.com/c/go/+/283112
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>
Diffstat (limited to 'test/closure5.dir')
-rw-r--r-- | test/closure5.dir/a.go | 11 | ||||
-rw-r--r-- | test/closure5.dir/main.go | 15 |
2 files changed, 26 insertions, 0 deletions
diff --git a/test/closure5.dir/a.go b/test/closure5.dir/a.go new file mode 100644 index 0000000000..de8082b7b1 --- /dev/null +++ b/test/closure5.dir/a.go @@ -0,0 +1,11 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check correctness of various closure corner cases +// that are expected to be inlined + +package a + +func f() bool { return true } +func G() func() func() bool { return func() func() bool { return f } } diff --git a/test/closure5.dir/main.go b/test/closure5.dir/main.go new file mode 100644 index 0000000000..ee5dba6481 --- /dev/null +++ b/test/closure5.dir/main.go @@ -0,0 +1,15 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check correctness of various closure corner cases +// that are expected to be inlined +package main + +import "a" + +func main() { + if !a.G()()() { + panic("FAIL") + } +} |