2015-02-13 14:40:36 -05:00
|
|
|
// Copyright 2009 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.
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// function literals aka closures
|
2015-02-13 14:40:36 -05:00
|
|
|
func closurehdr(ntype *Node) {
|
|
|
|
var name *Node
|
|
|
|
var a *Node
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
n := Nod(OCLOSURE, nil, nil)
|
2015-05-27 00:44:05 -04:00
|
|
|
n.Func.Ntype = ntype
|
|
|
|
n.Func.Depth = Funcdepth
|
2015-03-25 19:33:01 -07:00
|
|
|
n.Func.Outerfunc = Curfn
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
funchdr(n)
|
|
|
|
|
|
|
|
// steal ntype's argument names and
|
|
|
|
// leave a fresh copy in their place.
|
|
|
|
// references to these variables need to
|
|
|
|
// refer to the variables in the external
|
|
|
|
// function declared below; see walkclosure.
|
2016-03-08 15:10:26 -08:00
|
|
|
n.List.Set(ntype.List.Slice())
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-08 15:10:26 -08:00
|
|
|
n.Rlist.Set(ntype.Rlist.Slice())
|
|
|
|
ntype.List.Set(nil)
|
|
|
|
ntype.Rlist.Set(nil)
|
|
|
|
for _, n1 := range n.List.Slice() {
|
|
|
|
name = n1.Left
|
2015-02-13 14:40:36 -05:00
|
|
|
if name != nil {
|
|
|
|
name = newname(name.Sym)
|
|
|
|
}
|
2016-03-08 15:10:26 -08:00
|
|
|
a = Nod(ODCLFIELD, name, n1.Right)
|
|
|
|
a.Isddd = n1.Isddd
|
2015-02-13 14:40:36 -05:00
|
|
|
if name != nil {
|
|
|
|
name.Isddd = a.Isddd
|
|
|
|
}
|
2016-03-08 15:10:26 -08:00
|
|
|
ntype.List.Append(a)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-08 15:10:26 -08:00
|
|
|
for _, n2 := range n.Rlist.Slice() {
|
|
|
|
name = n2.Left
|
2015-02-13 14:40:36 -05:00
|
|
|
if name != nil {
|
|
|
|
name = newname(name.Sym)
|
|
|
|
}
|
2016-03-08 15:10:26 -08:00
|
|
|
ntype.Rlist.Append(Nod(ODCLFIELD, name, n2.Right))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-09 20:29:21 -08:00
|
|
|
func closurebody(body []*Node) *Node {
|
|
|
|
if len(body) == 0 {
|
|
|
|
body = []*Node{Nod(OEMPTY, nil, nil)}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
func_ := Curfn
|
2016-03-09 20:29:21 -08:00
|
|
|
func_.Nbody.Set(body)
|
2015-03-25 19:33:01 -07:00
|
|
|
func_.Func.Endlineno = lineno
|
2015-02-13 14:40:36 -05:00
|
|
|
funcbody(func_)
|
|
|
|
|
|
|
|
// closure-specific variables are hanging off the
|
|
|
|
// ordinary ones in the symbol table; see oldname.
|
|
|
|
// unhook them.
|
|
|
|
// make the list of pointers for the closure call.
|
2016-02-26 17:03:58 -08:00
|
|
|
for _, v := range func_.Func.Cvars.Slice() {
|
2015-06-03 14:16:01 -04:00
|
|
|
v.Name.Param.Closure.Name.Param.Closure = v.Name.Param.Outer
|
2015-05-27 00:44:05 -04:00
|
|
|
v.Name.Param.Outerexpr = oldname(v.Sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return func_
|
|
|
|
}
|
|
|
|
|
|
|
|
func typecheckclosure(func_ *Node, top int) {
|
2016-02-26 17:03:58 -08:00
|
|
|
for _, ln := range func_.Func.Cvars.Slice() {
|
2016-02-26 13:33:48 -08:00
|
|
|
n := ln.Name.Param.Closure
|
2015-05-15 10:02:19 -07:00
|
|
|
if !n.Name.Captured {
|
|
|
|
n.Name.Captured = true
|
|
|
|
if n.Name.Decldepth == 0 {
|
2016-03-15 13:06:58 -07:00
|
|
|
Fatalf("typecheckclosure: var %v does not have decldepth assigned", Nconv(n, FmtShort))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore assignments to the variable in straightline code
|
|
|
|
// preceding the first capturing by a closure.
|
2015-05-15 10:02:19 -07:00
|
|
|
if n.Name.Decldepth == decldepth {
|
2015-03-06 18:42:58 +11:00
|
|
|
n.Assigned = false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-25 10:35:19 -08:00
|
|
|
for _, ln := range func_.Func.Dcl {
|
|
|
|
if ln.Op == ONAME && (ln.Class == PPARAM || ln.Class == PPARAMOUT) {
|
|
|
|
ln.Name.Decldepth = 1
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
oldfn := Curfn
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
func_.Func.Ntype = typecheck(func_.Func.Ntype, Etype)
|
2015-05-27 00:44:05 -04:00
|
|
|
func_.Type = func_.Func.Ntype.Type
|
|
|
|
func_.Func.Top = top
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
// Type check the body now, but only if we're inside a function.
|
|
|
|
// At top level (in a variable initialization: curfn==nil) we're not
|
|
|
|
// ready to type check code yet; we'll check it later, because the
|
|
|
|
// underlying closure function we create is added to xtop.
|
|
|
|
if Curfn != nil && func_.Type != nil {
|
|
|
|
Curfn = func_
|
2015-02-23 16:07:24 -05:00
|
|
|
olddd := decldepth
|
2015-02-13 14:40:36 -05:00
|
|
|
decldepth = 1
|
2016-03-19 17:02:01 -07:00
|
|
|
typecheckslice(func_.Nbody.Slice(), Etop)
|
2015-02-13 14:40:36 -05:00
|
|
|
decldepth = olddd
|
|
|
|
Curfn = oldfn
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create top-level function
|
2016-03-09 20:29:21 -08:00
|
|
|
xtop = append(xtop, makeclosure(func_))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2015-02-20 13:54:45 -05:00
|
|
|
// closurename returns name for OCLOSURE n.
|
|
|
|
// It is not as simple as it ought to be, because we typecheck nested closures
|
|
|
|
// starting from the innermost one. So when we check the inner closure,
|
|
|
|
// we don't yet have name for the outer closure. This function uses recursion
|
|
|
|
// to generate names all the way up if necessary.
|
|
|
|
|
|
|
|
var closurename_closgen int
|
|
|
|
|
|
|
|
func closurename(n *Node) *Sym {
|
|
|
|
if n.Sym != nil {
|
|
|
|
return n.Sym
|
|
|
|
}
|
2015-02-23 16:07:24 -05:00
|
|
|
gen := 0
|
|
|
|
outer := ""
|
|
|
|
prefix := ""
|
2015-03-25 19:33:01 -07:00
|
|
|
if n.Func.Outerfunc == nil {
|
2015-02-20 13:54:45 -05:00
|
|
|
// Global closure.
|
|
|
|
outer = "glob"
|
|
|
|
|
|
|
|
prefix = "func"
|
|
|
|
closurename_closgen++
|
|
|
|
gen = closurename_closgen
|
2015-03-25 19:33:01 -07:00
|
|
|
} else if n.Func.Outerfunc.Op == ODCLFUNC {
|
2015-02-20 13:54:45 -05:00
|
|
|
// The outermost closure inside of a named function.
|
2015-05-27 10:42:55 -04:00
|
|
|
outer = n.Func.Outerfunc.Func.Nname.Sym.Name
|
2015-02-20 13:54:45 -05:00
|
|
|
|
|
|
|
prefix = "func"
|
|
|
|
|
|
|
|
// Yes, functions can be named _.
|
|
|
|
// Can't use function closgen in such case,
|
|
|
|
// because it would lead to name clashes.
|
2015-05-27 10:42:55 -04:00
|
|
|
if !isblank(n.Func.Outerfunc.Func.Nname) {
|
2015-03-25 19:33:01 -07:00
|
|
|
n.Func.Outerfunc.Func.Closgen++
|
|
|
|
gen = n.Func.Outerfunc.Func.Closgen
|
2015-02-20 13:54:45 -05:00
|
|
|
} else {
|
|
|
|
closurename_closgen++
|
|
|
|
gen = closurename_closgen
|
|
|
|
}
|
2015-03-25 19:33:01 -07:00
|
|
|
} else if n.Func.Outerfunc.Op == OCLOSURE {
|
2015-02-20 13:54:45 -05:00
|
|
|
// Nested closure, recurse.
|
2015-03-25 19:33:01 -07:00
|
|
|
outer = closurename(n.Func.Outerfunc).Name
|
2015-02-20 13:54:45 -05:00
|
|
|
|
|
|
|
prefix = ""
|
2015-03-25 19:33:01 -07:00
|
|
|
n.Func.Outerfunc.Func.Closgen++
|
|
|
|
gen = n.Func.Outerfunc.Func.Closgen
|
2015-02-20 13:54:45 -05:00
|
|
|
} else {
|
2016-03-15 13:06:58 -07:00
|
|
|
Fatalf("closurename called for %v", Nconv(n, FmtShort))
|
2015-02-20 13:54:45 -05:00
|
|
|
}
|
2015-03-06 12:02:24 -08:00
|
|
|
n.Sym = Lookupf("%s.%s%d", outer, prefix, gen)
|
2015-02-20 13:54:45 -05:00
|
|
|
return n.Sym
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
func makeclosure(func_ *Node) *Node {
|
2015-10-22 09:51:12 +09:00
|
|
|
// wrap body in external function
|
|
|
|
// that begins by reading closure parameters.
|
2015-02-23 16:07:24 -05:00
|
|
|
xtype := Nod(OTFUNC, nil, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-08 15:10:26 -08:00
|
|
|
xtype.List.Set(func_.List.Slice())
|
|
|
|
xtype.Rlist.Set(func_.Rlist.Slice())
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
// create the function
|
2015-02-23 16:07:24 -05:00
|
|
|
xfunc := Nod(ODCLFUNC, nil, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-05-27 10:42:55 -04:00
|
|
|
xfunc.Func.Nname = newfuncname(closurename(func_))
|
|
|
|
xfunc.Func.Nname.Sym.Flags |= SymExported // disable export
|
|
|
|
xfunc.Func.Nname.Name.Param.Ntype = xtype
|
|
|
|
xfunc.Func.Nname.Name.Defn = xfunc
|
|
|
|
declare(xfunc.Func.Nname, PFUNC)
|
|
|
|
xfunc.Func.Nname.Name.Funcdepth = func_.Func.Depth
|
2015-05-27 00:44:05 -04:00
|
|
|
xfunc.Func.Depth = func_.Func.Depth
|
2015-03-25 19:33:01 -07:00
|
|
|
xfunc.Func.Endlineno = func_.Func.Endlineno
|
2015-07-15 11:31:30 +12:00
|
|
|
makefuncsym(xfunc.Func.Nname.Sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-02-27 14:31:33 -08:00
|
|
|
xfunc.Nbody.Set(func_.Nbody.Slice())
|
2016-02-25 10:35:19 -08:00
|
|
|
xfunc.Func.Dcl = append(func_.Func.Dcl, xfunc.Func.Dcl...)
|
|
|
|
func_.Func.Dcl = nil
|
2016-02-27 14:31:33 -08:00
|
|
|
if len(xfunc.Nbody.Slice()) == 0 {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("empty body - won't generate any code")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
xfunc = typecheck(xfunc, Etop)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-05-27 00:44:05 -04:00
|
|
|
xfunc.Func.Closure = func_
|
|
|
|
func_.Func.Closure = xfunc
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-02-27 14:31:33 -08:00
|
|
|
func_.Nbody.Set(nil)
|
2016-03-08 15:10:26 -08:00
|
|
|
func_.List.Set(nil)
|
|
|
|
func_.Rlist.Set(nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
return xfunc
|
|
|
|
}
|
|
|
|
|
|
|
|
// capturevars is called in a separate phase after all typechecking is done.
|
|
|
|
// It decides whether each variable captured by a closure should be captured
|
|
|
|
// by value or by reference.
|
|
|
|
// We use value capturing for values <= 128 bytes that are never reassigned
|
|
|
|
// after capturing (effectively constant).
|
|
|
|
func capturevars(xfunc *Node) {
|
|
|
|
var outer *Node
|
|
|
|
|
2016-03-02 17:34:42 -08:00
|
|
|
lno := lineno
|
2015-02-13 14:40:36 -05:00
|
|
|
lineno = xfunc.Lineno
|
|
|
|
|
2015-05-27 00:44:05 -04:00
|
|
|
func_ := xfunc.Func.Closure
|
2016-02-26 14:28:48 -08:00
|
|
|
func_.Func.Enter.Set(nil)
|
2016-02-26 17:03:58 -08:00
|
|
|
for _, v := range func_.Func.Cvars.Slice() {
|
2015-02-13 14:40:36 -05:00
|
|
|
if v.Type == nil {
|
|
|
|
// if v->type is nil, it means v looked like it was
|
|
|
|
// going to be used in the closure but wasn't.
|
|
|
|
// this happens because when parsing a, b, c := f()
|
|
|
|
// the a, b, c gets parsed as references to older
|
|
|
|
// a, b, c before the parser figures out this is a
|
|
|
|
// declaration.
|
|
|
|
v.Op = OXXX
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// type check the & of closed variables outside the closure,
|
|
|
|
// so that the outer frame also grabs them and knows they escape.
|
|
|
|
dowidth(v.Type)
|
|
|
|
|
2015-05-27 00:44:05 -04:00
|
|
|
outer = v.Name.Param.Outerexpr
|
|
|
|
v.Name.Param.Outerexpr = nil
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
// out parameters will be assigned to implicitly upon return.
|
2015-05-27 00:44:05 -04:00
|
|
|
if outer.Class != PPARAMOUT && !v.Name.Param.Closure.Addrtaken && !v.Name.Param.Closure.Assigned && v.Type.Width <= 128 {
|
2015-05-15 10:02:19 -07:00
|
|
|
v.Name.Byval = true
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2015-05-27 00:44:05 -04:00
|
|
|
v.Name.Param.Closure.Addrtaken = true
|
2015-02-13 14:40:36 -05:00
|
|
|
outer = Nod(OADDR, outer, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
if Debug['m'] > 1 {
|
2015-03-02 14:22:05 -05:00
|
|
|
var name *Sym
|
2015-05-27 10:42:55 -04:00
|
|
|
if v.Name.Curfn != nil && v.Name.Curfn.Func.Nname != nil {
|
|
|
|
name = v.Name.Curfn.Func.Nname.Sym
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-02-23 16:07:24 -05:00
|
|
|
how := "ref"
|
2015-05-15 10:02:19 -07:00
|
|
|
if v.Name.Byval {
|
2015-02-13 14:40:36 -05:00
|
|
|
how = "value"
|
|
|
|
}
|
2016-03-02 11:01:25 -08:00
|
|
|
Warnl(v.Lineno, "%v capturing by %s: %v (addr=%v assign=%v width=%d)", name, how, v.Sym, v.Name.Param.Closure.Addrtaken, v.Name.Param.Closure.Assigned, int32(v.Type.Width))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
outer = typecheck(outer, Erv)
|
2016-02-26 14:28:48 -08:00
|
|
|
func_.Func.Enter.Append(outer)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2016-03-02 17:34:42 -08:00
|
|
|
lineno = lno
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// transformclosure is called in a separate phase after escape analysis.
|
|
|
|
// It transform closure bodies to properly reference captured variables.
|
|
|
|
func transformclosure(xfunc *Node) {
|
2016-03-02 17:34:42 -08:00
|
|
|
lno := lineno
|
2015-02-13 14:40:36 -05:00
|
|
|
lineno = xfunc.Lineno
|
2015-05-27 00:44:05 -04:00
|
|
|
func_ := xfunc.Func.Closure
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-05-27 00:44:05 -04:00
|
|
|
if func_.Func.Top&Ecall != 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
// If the closure is directly called, we transform it to a plain function call
|
|
|
|
// with variables passed as args. This avoids allocation of a closure object.
|
|
|
|
// Here we do only a part of the transformation. Walk of OCALLFUNC(OCLOSURE)
|
|
|
|
// will complete the transformation later.
|
|
|
|
// For illustration, the following closure:
|
|
|
|
// func(a int) {
|
|
|
|
// println(byval)
|
|
|
|
// byref++
|
|
|
|
// }(42)
|
|
|
|
// becomes:
|
|
|
|
// func(a int, byval int, &byref *int) {
|
|
|
|
// println(byval)
|
|
|
|
// (*&byref)++
|
2015-07-23 14:17:07 -04:00
|
|
|
// }(byval, &byref, 42)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
// f is ONAME of the actual function.
|
2015-05-27 10:42:55 -04:00
|
|
|
f := xfunc.Func.Nname
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-07-23 14:17:07 -04:00
|
|
|
// We are going to insert captured variables before input args.
|
2016-03-14 01:20:49 -07:00
|
|
|
var params []*Field
|
2016-03-10 19:05:45 -08:00
|
|
|
var decls []*Node
|
2016-02-26 17:03:58 -08:00
|
|
|
for _, v := range func_.Func.Cvars.Slice() {
|
2015-02-13 14:40:36 -05:00
|
|
|
if v.Op == OXXX {
|
|
|
|
continue
|
|
|
|
}
|
2016-03-14 01:20:49 -07:00
|
|
|
fld := newField()
|
2015-09-08 03:51:30 +02:00
|
|
|
fld.Funarg = true
|
2015-05-15 10:02:19 -07:00
|
|
|
if v.Name.Byval {
|
2015-02-13 14:40:36 -05:00
|
|
|
// If v is captured by value, we merely downgrade it to PPARAM.
|
|
|
|
v.Class = PPARAM
|
|
|
|
|
|
|
|
v.Ullman = 1
|
|
|
|
fld.Nname = v
|
|
|
|
} else {
|
|
|
|
// If v of type T is captured by reference,
|
|
|
|
// we introduce function param &v *T
|
|
|
|
// and v remains PPARAMREF with &v heapaddr
|
|
|
|
// (accesses will implicitly deref &v).
|
2016-03-10 19:05:45 -08:00
|
|
|
addr := newname(Lookupf("&%s", v.Sym.Name))
|
2015-02-13 14:40:36 -05:00
|
|
|
addr.Type = Ptrto(v.Type)
|
|
|
|
addr.Class = PPARAM
|
2015-05-15 10:02:19 -07:00
|
|
|
v.Name.Heapaddr = addr
|
2015-02-13 14:40:36 -05:00
|
|
|
fld.Nname = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
fld.Type = fld.Nname.Type
|
|
|
|
fld.Sym = fld.Nname.Sym
|
|
|
|
|
2016-03-10 19:05:45 -08:00
|
|
|
params = append(params, fld)
|
|
|
|
decls = append(decls, fld.Nname)
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-10 19:05:45 -08:00
|
|
|
if len(params) > 0 {
|
|
|
|
// Prepend params and decls.
|
|
|
|
f.Type.Params().SetFields(append(params, f.Type.Params().FieldSlice()...))
|
|
|
|
xfunc.Func.Dcl = append(decls, xfunc.Func.Dcl...)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Recalculate param offsets.
|
|
|
|
if f.Type.Width > 0 {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("transformclosure: width is already calculated")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
dowidth(f.Type)
|
|
|
|
xfunc.Type = f.Type // update type of ODCLFUNC
|
|
|
|
} else {
|
|
|
|
// The closure is not called, so it is going to stay as closure.
|
2016-02-26 14:28:48 -08:00
|
|
|
var body []*Node
|
2015-02-23 16:07:24 -05:00
|
|
|
offset := int64(Widthptr)
|
|
|
|
var addr *Node
|
|
|
|
var cv *Node
|
2016-02-26 17:03:58 -08:00
|
|
|
for _, v := range func_.Func.Cvars.Slice() {
|
2015-02-13 14:40:36 -05:00
|
|
|
if v.Op == OXXX {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// cv refers to the field inside of closure OSTRUCTLIT.
|
|
|
|
cv = Nod(OCLOSUREVAR, nil, nil)
|
|
|
|
|
|
|
|
cv.Type = v.Type
|
2015-05-15 10:02:19 -07:00
|
|
|
if !v.Name.Byval {
|
2015-02-13 14:40:36 -05:00
|
|
|
cv.Type = Ptrto(v.Type)
|
|
|
|
}
|
|
|
|
offset = Rnd(offset, int64(cv.Type.Align))
|
|
|
|
cv.Xoffset = offset
|
|
|
|
offset += cv.Type.Width
|
|
|
|
|
2015-06-29 13:56:27 -04:00
|
|
|
if v.Name.Byval && v.Type.Width <= int64(2*Widthptr) {
|
|
|
|
// If it is a small variable captured by value, downgrade it to PAUTO.
|
2015-02-13 14:40:36 -05:00
|
|
|
v.Class = PAUTO
|
|
|
|
v.Ullman = 1
|
2016-02-25 10:35:19 -08:00
|
|
|
xfunc.Func.Dcl = append(xfunc.Func.Dcl, v)
|
2016-02-26 14:28:48 -08:00
|
|
|
body = append(body, Nod(OAS, v, cv))
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
|
|
|
// Declare variable holding addresses taken from closure
|
|
|
|
// and initialize in entry prologue.
|
2015-03-06 12:02:24 -08:00
|
|
|
addr = newname(Lookupf("&%s", v.Sym.Name))
|
2015-05-27 00:44:05 -04:00
|
|
|
addr.Name.Param.Ntype = Nod(OIND, typenod(v.Type), nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
addr.Class = PAUTO
|
2015-03-06 21:18:41 +11:00
|
|
|
addr.Used = true
|
2015-05-27 07:31:56 -04:00
|
|
|
addr.Name.Curfn = xfunc
|
2016-02-25 10:35:19 -08:00
|
|
|
xfunc.Func.Dcl = append(xfunc.Func.Dcl, addr)
|
2015-05-15 10:02:19 -07:00
|
|
|
v.Name.Heapaddr = addr
|
|
|
|
if v.Name.Byval {
|
2015-02-13 14:40:36 -05:00
|
|
|
cv = Nod(OADDR, cv, nil)
|
|
|
|
}
|
2016-02-26 14:28:48 -08:00
|
|
|
body = append(body, Nod(OAS, addr, cv))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-26 14:28:48 -08:00
|
|
|
if len(body) > 0 {
|
|
|
|
typecheckslice(body, Etop)
|
2016-03-07 22:54:46 -08:00
|
|
|
walkstmtlist(body)
|
2016-02-26 14:28:48 -08:00
|
|
|
xfunc.Func.Enter.Set(body)
|
|
|
|
xfunc.Func.Needctxt = true
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2016-03-02 17:34:42 -08:00
|
|
|
lineno = lno
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2016-03-07 22:54:46 -08:00
|
|
|
func walkclosure(func_ *Node, init *Nodes) *Node {
|
2015-02-13 14:40:36 -05:00
|
|
|
// If no closure vars, don't bother wrapping.
|
2016-02-26 17:03:58 -08:00
|
|
|
if len(func_.Func.Cvars.Slice()) == 0 {
|
2015-05-27 10:42:55 -04:00
|
|
|
return func_.Func.Closure.Func.Nname
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create closure in the form of a composite literal.
|
|
|
|
// supposing the closure captures an int i and a string s
|
|
|
|
// and has one float64 argument and no results,
|
|
|
|
// the generated code looks like:
|
|
|
|
//
|
2015-02-20 13:54:45 -05:00
|
|
|
// clos = &struct{.F uintptr; i *int; s *string}{func.1, &i, &s}
|
2015-02-13 14:40:36 -05:00
|
|
|
//
|
|
|
|
// The use of the struct provides type information to the garbage
|
|
|
|
// collector so that it can walk the closure. We could use (in this case)
|
|
|
|
// [3]unsafe.Pointer instead, but that would leave the gc in the dark.
|
|
|
|
// The information appears in the binary in the form of type descriptors;
|
|
|
|
// the struct is unnamed so that closures in multiple packages with the
|
|
|
|
// same struct type can share the descriptor.
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
typ := Nod(OTSTRUCT, nil, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-10 10:13:42 -08:00
|
|
|
typ.List.Set1(Nod(ODCLFIELD, newname(Lookup(".F")), typenod(Types[TUINTPTR])))
|
2015-02-23 16:07:24 -05:00
|
|
|
var typ1 *Node
|
2016-02-26 17:03:58 -08:00
|
|
|
for _, v := range func_.Func.Cvars.Slice() {
|
2015-02-13 14:40:36 -05:00
|
|
|
if v.Op == OXXX {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
typ1 = typenod(v.Type)
|
2015-05-15 10:02:19 -07:00
|
|
|
if !v.Name.Byval {
|
2015-02-13 14:40:36 -05:00
|
|
|
typ1 = Nod(OIND, typ1, nil)
|
|
|
|
}
|
2016-03-08 15:10:26 -08:00
|
|
|
typ.List.Append(Nod(ODCLFIELD, newname(v.Sym), typ1))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
clos := Nod(OCOMPLIT, nil, Nod(OIND, typ, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
clos.Esc = func_.Esc
|
2015-03-06 21:18:41 +11:00
|
|
|
clos.Right.Implicit = true
|
2016-03-08 15:10:26 -08:00
|
|
|
clos.List.Set(append([]*Node{Nod(OCFUNC, func_.Func.Closure.Func.Nname, nil)}, func_.Func.Enter.Slice()...))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
// Force type conversion from *struct to the func type.
|
|
|
|
clos = Nod(OCONVNOP, clos, nil)
|
|
|
|
|
|
|
|
clos.Type = func_.Type
|
|
|
|
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
clos = typecheck(clos, Erv)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
// typecheck will insert a PTRLIT node under CONVNOP,
|
|
|
|
// tag it with escape analysis result.
|
|
|
|
clos.Left.Esc = func_.Esc
|
|
|
|
|
|
|
|
// non-escaping temp to use, if any.
|
|
|
|
// orderexpr did not compute the type; fill it in now.
|
2015-05-26 23:05:35 -04:00
|
|
|
if x := prealloc[func_]; x != nil {
|
|
|
|
x.Type = clos.Left.Left.Type
|
|
|
|
x.Orig.Type = x.Type
|
|
|
|
clos.Left.Right = x
|
|
|
|
delete(prealloc, func_)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2016-03-23 08:51:38 -07:00
|
|
|
return walkexpr(clos, init)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
cmd/compile: change ODOT and friends to use Sym, not Right
The Node type ODOT and its variants all represent a selector, with a
simple name to the right of the dot. Before this change this was
represented by using an ONAME Node in the Right field. This ONAME node
served no useful purpose. This CL changes these Node types to store the
symbol in the Sym field instead, thus not requiring allocating a Node
for each selector.
When compiling x/tools/go/types this CL eliminates nearly 5000 calls to
newname and reduces the total number of Nodes allocated by about 6.6%.
It seems to cut compilation time by 1 to 2 percent.
Getting this right was somewhat subtle, and I added two dubious changes
to produce the exact same output as before. One is to ishairy in
inl.go: the ONAME node increased the cost of ODOT and friends by 1, and
I retained that, although really ODOT is not more expensive than any
other node. The other is to varexpr in walk.go: because the ONAME in
the Right field of an ODOT has no class, varexpr would always return
false for an ODOT, although in fact for some ODOT's it seemingly ought
to return true; I added an && false for now. I will send separate CLs,
that will break toolstash -cmp, to clean these up.
This CL passes toolstash -cmp.
Change-Id: I4af8a10cc59078c436130ce472f25abc3a9b2f80
Reviewed-on: https://go-review.googlesource.com/20890
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-18 16:52:30 -07:00
|
|
|
func typecheckpartialcall(fn *Node, sym *Sym) {
|
2015-02-13 14:40:36 -05:00
|
|
|
switch fn.Op {
|
2015-04-01 09:38:44 -07:00
|
|
|
case ODOTINTER, ODOTMETH:
|
2015-02-13 14:40:36 -05:00
|
|
|
break
|
|
|
|
|
|
|
|
default:
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("invalid typecheckpartialcall")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create top-level function.
|
2015-05-27 10:42:55 -04:00
|
|
|
xfunc := makepartialcall(fn, fn.Type, sym)
|
|
|
|
fn.Func = xfunc.Func
|
cmd/compile: change ODOT and friends to use Sym, not Right
The Node type ODOT and its variants all represent a selector, with a
simple name to the right of the dot. Before this change this was
represented by using an ONAME Node in the Right field. This ONAME node
served no useful purpose. This CL changes these Node types to store the
symbol in the Sym field instead, thus not requiring allocating a Node
for each selector.
When compiling x/tools/go/types this CL eliminates nearly 5000 calls to
newname and reduces the total number of Nodes allocated by about 6.6%.
It seems to cut compilation time by 1 to 2 percent.
Getting this right was somewhat subtle, and I added two dubious changes
to produce the exact same output as before. One is to ishairy in
inl.go: the ONAME node increased the cost of ODOT and friends by 1, and
I retained that, although really ODOT is not more expensive than any
other node. The other is to varexpr in walk.go: because the ONAME in
the Right field of an ODOT has no class, varexpr would always return
false for an ODOT, although in fact for some ODOT's it seemingly ought
to return true; I added an && false for now. I will send separate CLs,
that will break toolstash -cmp, to clean these up.
This CL passes toolstash -cmp.
Change-Id: I4af8a10cc59078c436130ce472f25abc3a9b2f80
Reviewed-on: https://go-review.googlesource.com/20890
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-18 16:52:30 -07:00
|
|
|
fn.Right = newname(sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
fn.Op = OCALLPART
|
2015-05-27 10:42:55 -04:00
|
|
|
fn.Type = xfunc.Type
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var makepartialcall_gopkg *Pkg
|
|
|
|
|
cmd/compile: change ODOT and friends to use Sym, not Right
The Node type ODOT and its variants all represent a selector, with a
simple name to the right of the dot. Before this change this was
represented by using an ONAME Node in the Right field. This ONAME node
served no useful purpose. This CL changes these Node types to store the
symbol in the Sym field instead, thus not requiring allocating a Node
for each selector.
When compiling x/tools/go/types this CL eliminates nearly 5000 calls to
newname and reduces the total number of Nodes allocated by about 6.6%.
It seems to cut compilation time by 1 to 2 percent.
Getting this right was somewhat subtle, and I added two dubious changes
to produce the exact same output as before. One is to ishairy in
inl.go: the ONAME node increased the cost of ODOT and friends by 1, and
I retained that, although really ODOT is not more expensive than any
other node. The other is to varexpr in walk.go: because the ONAME in
the Right field of an ODOT has no class, varexpr would always return
false for an ODOT, although in fact for some ODOT's it seemingly ought
to return true; I added an && false for now. I will send separate CLs,
that will break toolstash -cmp, to clean these up.
This CL passes toolstash -cmp.
Change-Id: I4af8a10cc59078c436130ce472f25abc3a9b2f80
Reviewed-on: https://go-review.googlesource.com/20890
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-18 16:52:30 -07:00
|
|
|
func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node {
|
2015-02-13 14:40:36 -05:00
|
|
|
var p string
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
rcvrtype := fn.Left.Type
|
cmd/compile: change ODOT and friends to use Sym, not Right
The Node type ODOT and its variants all represent a selector, with a
simple name to the right of the dot. Before this change this was
represented by using an ONAME Node in the Right field. This ONAME node
served no useful purpose. This CL changes these Node types to store the
symbol in the Sym field instead, thus not requiring allocating a Node
for each selector.
When compiling x/tools/go/types this CL eliminates nearly 5000 calls to
newname and reduces the total number of Nodes allocated by about 6.6%.
It seems to cut compilation time by 1 to 2 percent.
Getting this right was somewhat subtle, and I added two dubious changes
to produce the exact same output as before. One is to ishairy in
inl.go: the ONAME node increased the cost of ODOT and friends by 1, and
I retained that, although really ODOT is not more expensive than any
other node. The other is to varexpr in walk.go: because the ONAME in
the Right field of an ODOT has no class, varexpr would always return
false for an ODOT, although in fact for some ODOT's it seemingly ought
to return true; I added an && false for now. I will send separate CLs,
that will break toolstash -cmp, to clean these up.
This CL passes toolstash -cmp.
Change-Id: I4af8a10cc59078c436130ce472f25abc3a9b2f80
Reviewed-on: https://go-review.googlesource.com/20890
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-18 16:52:30 -07:00
|
|
|
if exportname(meth.Name) {
|
|
|
|
p = fmt.Sprintf("(%v).%s-fm", Tconv(rcvrtype, FmtLeft|FmtShort), meth.Name)
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
cmd/compile: change ODOT and friends to use Sym, not Right
The Node type ODOT and its variants all represent a selector, with a
simple name to the right of the dot. Before this change this was
represented by using an ONAME Node in the Right field. This ONAME node
served no useful purpose. This CL changes these Node types to store the
symbol in the Sym field instead, thus not requiring allocating a Node
for each selector.
When compiling x/tools/go/types this CL eliminates nearly 5000 calls to
newname and reduces the total number of Nodes allocated by about 6.6%.
It seems to cut compilation time by 1 to 2 percent.
Getting this right was somewhat subtle, and I added two dubious changes
to produce the exact same output as before. One is to ishairy in
inl.go: the ONAME node increased the cost of ODOT and friends by 1, and
I retained that, although really ODOT is not more expensive than any
other node. The other is to varexpr in walk.go: because the ONAME in
the Right field of an ODOT has no class, varexpr would always return
false for an ODOT, although in fact for some ODOT's it seemingly ought
to return true; I added an && false for now. I will send separate CLs,
that will break toolstash -cmp, to clean these up.
This CL passes toolstash -cmp.
Change-Id: I4af8a10cc59078c436130ce472f25abc3a9b2f80
Reviewed-on: https://go-review.googlesource.com/20890
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-18 16:52:30 -07:00
|
|
|
p = fmt.Sprintf("(%v).(%v)-fm", Tconv(rcvrtype, FmtLeft|FmtShort), Sconv(meth, FmtLeft))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-02-23 16:07:24 -05:00
|
|
|
basetype := rcvrtype
|
2015-03-01 07:54:01 +00:00
|
|
|
if Isptr[rcvrtype.Etype] {
|
2016-03-30 10:57:47 -07:00
|
|
|
basetype = basetype.Elem()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
if basetype.Etype != TINTER && basetype.Sym == nil {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("missing base type for %v", rcvrtype)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2015-03-02 14:22:05 -05:00
|
|
|
var spkg *Pkg
|
2015-02-13 14:40:36 -05:00
|
|
|
if basetype.Sym != nil {
|
|
|
|
spkg = basetype.Sym.Pkg
|
|
|
|
}
|
|
|
|
if spkg == nil {
|
|
|
|
if makepartialcall_gopkg == nil {
|
2015-03-02 16:03:26 -05:00
|
|
|
makepartialcall_gopkg = mkpkg("go")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
spkg = makepartialcall_gopkg
|
|
|
|
}
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
sym := Pkglookup(p, spkg)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
if sym.Flags&SymUniq != 0 {
|
|
|
|
return sym.Def
|
|
|
|
}
|
|
|
|
sym.Flags |= SymUniq
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
savecurfn := Curfn
|
2015-02-13 14:40:36 -05:00
|
|
|
Curfn = nil
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
xtype := Nod(OTFUNC, nil, nil)
|
|
|
|
i := 0
|
2016-03-07 09:36:24 -08:00
|
|
|
var l []*Node
|
|
|
|
var callargs []*Node
|
2015-03-09 16:24:07 +11:00
|
|
|
ddd := false
|
2015-02-23 16:07:24 -05:00
|
|
|
xfunc := Nod(ODCLFUNC, nil, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
Curfn = xfunc
|
2015-02-23 16:07:24 -05:00
|
|
|
var fld *Node
|
|
|
|
var n *Node
|
2016-03-17 01:32:18 -07:00
|
|
|
for _, t := range t0.Params().Fields().Slice() {
|
2016-03-21 10:43:32 -07:00
|
|
|
n = newname(LookupN("a", i))
|
2015-02-13 14:40:36 -05:00
|
|
|
i++
|
|
|
|
n.Class = PPARAM
|
2016-02-25 10:35:19 -08:00
|
|
|
xfunc.Func.Dcl = append(xfunc.Func.Dcl, n)
|
2016-03-07 09:36:24 -08:00
|
|
|
callargs = append(callargs, n)
|
2015-02-13 14:40:36 -05:00
|
|
|
fld = Nod(ODCLFIELD, n, typenod(t.Type))
|
2015-03-09 16:24:07 +11:00
|
|
|
if t.Isddd {
|
|
|
|
fld.Isddd = true
|
|
|
|
ddd = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2016-03-07 09:36:24 -08:00
|
|
|
l = append(l, fld)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2016-03-08 15:10:26 -08:00
|
|
|
xtype.List.Set(l)
|
2015-02-13 14:40:36 -05:00
|
|
|
i = 0
|
|
|
|
l = nil
|
2016-03-07 09:36:24 -08:00
|
|
|
var retargs []*Node
|
2016-03-17 01:32:18 -07:00
|
|
|
for _, t := range t0.Results().Fields().Slice() {
|
2016-03-19 18:17:58 -07:00
|
|
|
n = newname(LookupN("r", i))
|
2015-02-13 14:40:36 -05:00
|
|
|
i++
|
|
|
|
n.Class = PPARAMOUT
|
2016-02-25 10:35:19 -08:00
|
|
|
xfunc.Func.Dcl = append(xfunc.Func.Dcl, n)
|
2016-03-07 09:36:24 -08:00
|
|
|
retargs = append(retargs, n)
|
|
|
|
l = append(l, Nod(ODCLFIELD, n, typenod(t.Type)))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2016-03-08 15:10:26 -08:00
|
|
|
xtype.Rlist.Set(l)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-03-25 19:33:01 -07:00
|
|
|
xfunc.Func.Dupok = true
|
2015-05-27 10:42:55 -04:00
|
|
|
xfunc.Func.Nname = newfuncname(sym)
|
|
|
|
xfunc.Func.Nname.Sym.Flags |= SymExported // disable export
|
|
|
|
xfunc.Func.Nname.Name.Param.Ntype = xtype
|
|
|
|
xfunc.Func.Nname.Name.Defn = xfunc
|
|
|
|
declare(xfunc.Func.Nname, PFUNC)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
// Declare and initialize variable holding receiver.
|
|
|
|
|
2015-03-25 19:33:01 -07:00
|
|
|
xfunc.Func.Needctxt = true
|
2015-02-23 16:07:24 -05:00
|
|
|
cv := Nod(OCLOSUREVAR, nil, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
cv.Xoffset = int64(Widthptr)
|
|
|
|
cv.Type = rcvrtype
|
|
|
|
if int(cv.Type.Align) > Widthptr {
|
|
|
|
cv.Xoffset = int64(cv.Type.Align)
|
|
|
|
}
|
2015-02-23 16:07:24 -05:00
|
|
|
ptr := Nod(ONAME, nil, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
ptr.Sym = Lookup("rcvr")
|
|
|
|
ptr.Class = PAUTO
|
2015-04-02 19:58:37 -07:00
|
|
|
ptr.Addable = true
|
2015-02-13 14:40:36 -05:00
|
|
|
ptr.Ullman = 1
|
2015-03-06 21:18:41 +11:00
|
|
|
ptr.Used = true
|
2015-05-27 07:31:56 -04:00
|
|
|
ptr.Name.Curfn = xfunc
|
2015-10-22 14:22:38 -07:00
|
|
|
ptr.Xoffset = 0
|
2016-02-25 10:35:19 -08:00
|
|
|
xfunc.Func.Dcl = append(xfunc.Func.Dcl, ptr)
|
2016-02-27 14:31:33 -08:00
|
|
|
var body []*Node
|
2015-03-01 07:54:01 +00:00
|
|
|
if Isptr[rcvrtype.Etype] || Isinter(rcvrtype) {
|
2015-05-27 00:44:05 -04:00
|
|
|
ptr.Name.Param.Ntype = typenod(rcvrtype)
|
2016-02-27 14:31:33 -08:00
|
|
|
body = append(body, Nod(OAS, ptr, cv))
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2015-05-27 00:44:05 -04:00
|
|
|
ptr.Name.Param.Ntype = typenod(Ptrto(rcvrtype))
|
2016-02-27 14:31:33 -08:00
|
|
|
body = append(body, Nod(OAS, ptr, Nod(OADDR, cv, nil)))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
cmd/compile: change ODOT and friends to use Sym, not Right
The Node type ODOT and its variants all represent a selector, with a
simple name to the right of the dot. Before this change this was
represented by using an ONAME Node in the Right field. This ONAME node
served no useful purpose. This CL changes these Node types to store the
symbol in the Sym field instead, thus not requiring allocating a Node
for each selector.
When compiling x/tools/go/types this CL eliminates nearly 5000 calls to
newname and reduces the total number of Nodes allocated by about 6.6%.
It seems to cut compilation time by 1 to 2 percent.
Getting this right was somewhat subtle, and I added two dubious changes
to produce the exact same output as before. One is to ishairy in
inl.go: the ONAME node increased the cost of ODOT and friends by 1, and
I retained that, although really ODOT is not more expensive than any
other node. The other is to varexpr in walk.go: because the ONAME in
the Right field of an ODOT has no class, varexpr would always return
false for an ODOT, although in fact for some ODOT's it seemingly ought
to return true; I added an && false for now. I will send separate CLs,
that will break toolstash -cmp, to clean these up.
This CL passes toolstash -cmp.
Change-Id: I4af8a10cc59078c436130ce472f25abc3a9b2f80
Reviewed-on: https://go-review.googlesource.com/20890
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-18 16:52:30 -07:00
|
|
|
call := Nod(OCALL, NodSym(OXDOT, ptr, meth), nil)
|
2016-03-08 15:10:26 -08:00
|
|
|
call.List.Set(callargs)
|
2015-03-09 16:24:07 +11:00
|
|
|
call.Isddd = ddd
|
2016-03-17 01:47:16 -07:00
|
|
|
if t0.Results().NumFields() == 0 {
|
2016-02-27 14:31:33 -08:00
|
|
|
body = append(body, call)
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2015-02-23 16:07:24 -05:00
|
|
|
n := Nod(OAS2, nil, nil)
|
2016-03-08 15:10:26 -08:00
|
|
|
n.List.Set(retargs)
|
2016-03-10 10:13:42 -08:00
|
|
|
n.Rlist.Set1(call)
|
2016-02-27 14:31:33 -08:00
|
|
|
body = append(body, n)
|
2015-02-13 14:40:36 -05:00
|
|
|
n = Nod(ORETURN, nil, nil)
|
2016-02-27 14:31:33 -08:00
|
|
|
body = append(body, n)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2016-02-27 14:31:33 -08:00
|
|
|
xfunc.Nbody.Set(body)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
xfunc = typecheck(xfunc, Etop)
|
2015-02-13 14:40:36 -05:00
|
|
|
sym.Def = xfunc
|
2016-03-09 20:29:21 -08:00
|
|
|
xtop = append(xtop, xfunc)
|
2015-02-13 14:40:36 -05:00
|
|
|
Curfn = savecurfn
|
|
|
|
|
|
|
|
return xfunc
|
|
|
|
}
|
|
|
|
|
2016-03-07 22:54:46 -08:00
|
|
|
func walkpartialcall(n *Node, init *Nodes) *Node {
|
2015-02-13 14:40:36 -05:00
|
|
|
// Create closure in the form of a composite literal.
|
|
|
|
// For x.M with receiver (x) type T, the generated code looks like:
|
|
|
|
//
|
|
|
|
// clos = &struct{F uintptr; R T}{M.T·f, x}
|
|
|
|
//
|
|
|
|
// Like walkclosure above.
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
if Isinter(n.Left.Type) {
|
2015-02-13 14:40:36 -05:00
|
|
|
// Trigger panic for method on nil interface now.
|
|
|
|
// Otherwise it happens in the wrapper and is confusing.
|
|
|
|
n.Left = cheapexpr(n.Left, init)
|
|
|
|
|
|
|
|
checknil(n.Left, init)
|
|
|
|
}
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
typ := Nod(OTSTRUCT, nil, nil)
|
2016-03-10 10:13:42 -08:00
|
|
|
typ.List.Set1(Nod(ODCLFIELD, newname(Lookup("F")), typenod(Types[TUINTPTR])))
|
2016-03-08 15:10:26 -08:00
|
|
|
typ.List.Append(Nod(ODCLFIELD, newname(Lookup("R")), typenod(n.Left.Type)))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
clos := Nod(OCOMPLIT, nil, Nod(OIND, typ, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
clos.Esc = n.Esc
|
2015-03-06 21:18:41 +11:00
|
|
|
clos.Right.Implicit = true
|
2016-03-10 10:13:42 -08:00
|
|
|
clos.List.Set1(Nod(OCFUNC, n.Func.Nname, nil))
|
2016-03-08 15:10:26 -08:00
|
|
|
clos.List.Append(n.Left)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
// Force type conversion from *struct to the func type.
|
|
|
|
clos = Nod(OCONVNOP, clos, nil)
|
|
|
|
|
|
|
|
clos.Type = n.Type
|
|
|
|
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
clos = typecheck(clos, Erv)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
// typecheck will insert a PTRLIT node under CONVNOP,
|
|
|
|
// tag it with escape analysis result.
|
|
|
|
clos.Left.Esc = n.Esc
|
|
|
|
|
|
|
|
// non-escaping temp to use, if any.
|
|
|
|
// orderexpr did not compute the type; fill it in now.
|
2015-05-26 23:05:35 -04:00
|
|
|
if x := prealloc[n]; x != nil {
|
|
|
|
x.Type = clos.Left.Left.Type
|
|
|
|
x.Orig.Type = x.Type
|
|
|
|
clos.Left.Right = x
|
|
|
|
delete(prealloc, n)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
2016-03-23 08:51:38 -07:00
|
|
|
return walkexpr(clos, init)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|