aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/gc/main.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2020-11-16 17:00:10 -0500
committerRuss Cox <rsc@golang.org>2020-11-24 20:58:11 +0000
commitfd11a32c92a2621c6f52edec2a0339f4b7d794e8 (patch)
treef6d9ef5fad26d935c3485b57db45917815e70f54 /src/cmd/compile/internal/gc/main.go
parent8e2106327cf27b2d281a3e4432fcae552d4b29aa (diff)
downloadgo-fd11a32c92a2621c6f52edec2a0339f4b7d794e8.tar.gz
go-fd11a32c92a2621c6f52edec2a0339f4b7d794e8.zip
[dev.regabi] cmd/compile: clean up Node.Func
The original meaning of type Func was "extra fields factored out of a few cases of type Node having to do with functions", but those specific cases didn't necessarily have any relation. A typical declared function is represented by an ODCLFUNC Node at its declaration and an ONAME node at its uses, and both those have a .Func field, but they are *different* Funcs. Similarly, a closure is represented both by an OCLOSURE Node for the value itself and an ODCLFUNC Node for the underlying function implementing the closure. Those too have *different* Funcs, and the Func.Closure field in one points to the other and vice versa. This has led to no end of confusion over the years. This CL elevates type Func to be the canonical identifier for a given Go function. This looks like a trivial CL but in fact is the result of a lot of scaffolding and rewriting, discarded once the result was achieved, to separate out the three different kinds of Func nodes into three separate fields, limited in use to each specific Node type, to understand which Func fields are used by which Node types and what the possible overlaps are. There were a few overlaps, most notably around closures, which led to more fields being added to type Func to keep them separate even though there is now a single Func instead of two different ones for each function. A future CL can and should change Curfn to be a *Func instead of a *Node, finally eliminating the confusion about whether Curfn is an ODCLFUNC node (as it is most of the time) or an ONAME node (as it is when type-checking an inlined function body). Although sizeof_test.go makes it look like Func is growing by two words, there are now half as many Funcs in a running compilation, so the memory footprint has actually been reduced substantially. Change-Id: I598bd96c95728093dc769a835d48f2154a406a61 Reviewed-on: https://go-review.googlesource.com/c/go/+/272253 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/gc/main.go')
-rw-r--r--src/cmd/compile/internal/gc/main.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go
index 89dbca0cf1..cf4ec039f1 100644
--- a/src/cmd/compile/internal/gc/main.go
+++ b/src/cmd/compile/internal/gc/main.go
@@ -651,7 +651,7 @@ func Main(archInit func(*Arch)) {
// because variables captured by value do not escape.
timings.Start("fe", "capturevars")
for _, n := range xtop {
- if n.Op == ODCLFUNC && n.Func.Closure != nil {
+ if n.Op == ODCLFUNC && n.Func.OClosure != nil {
Curfn = n
capturevars(n)
}
@@ -724,7 +724,7 @@ func Main(archInit func(*Arch)) {
// before walk reaches a call of a closure.
timings.Start("fe", "xclosures")
for _, n := range xtop {
- if n.Op == ODCLFUNC && n.Func.Closure != nil {
+ if n.Op == ODCLFUNC && n.Func.OClosure != nil {
Curfn = n
transformclosure(n)
}
@@ -829,7 +829,7 @@ func Main(archInit func(*Arch)) {
func numNonClosures(list []*Node) int {
count := 0
for _, n := range list {
- if n.Func.Closure == nil {
+ if n.Func.OClosure == nil {
count++
}
}