]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: change gc logging to report inline failure instead of success
authorDavid Chase <drchase@google.com>
Wed, 4 Mar 2020 21:33:54 +0000 (16:33 -0500)
committerDavid Chase <drchase@google.com>
Fri, 10 Apr 2020 20:34:40 +0000 (20:34 +0000)
I've been experimenting with this, success is the wrong thing to report
even though it seems to log much less.

Change-Id: I7c25a45d2f41e82b6c8dd8b0a56ba848c63fb21a
Reviewed-on: https://go-review.googlesource.com/c/go/+/223298
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/logopt/logopt_test.go

index 29210ff8de389ccc78531030f8bf17c1756030dd..272d0bdab7b0d4ca0fb7b9a01b53b3721f38be31 100644 (file)
@@ -687,6 +687,10 @@ func inlnode(n *Node, maxCost int32, inlMap map[*Node]bool) *Node {
                                                if Debug['m'] > 1 {
                                                        fmt.Printf("%v: cannot inline escaping closure variable %v\n", n.Line(), n.Left)
                                                }
+                                               if logopt.Enabled() {
+                                                       logopt.LogOpt(n.Pos, "cannotInlineCall", "inline", Curfn.funcname(),
+                                                               fmt.Sprintf("%v cannot be inlined (escaping closure variable)", n.Left))
+                                               }
                                                break
                                        }
 
@@ -695,8 +699,16 @@ func inlnode(n *Node, maxCost int32, inlMap map[*Node]bool) *Node {
                                                if Debug['m'] > 1 {
                                                        if a != nil {
                                                                fmt.Printf("%v: cannot inline re-assigned closure variable at %v: %v\n", n.Line(), a.Line(), a)
+                                                               if logopt.Enabled() {
+                                                                       logopt.LogOpt(n.Pos, "cannotInlineCall", "inline", Curfn.funcname(),
+                                                                               fmt.Sprintf("%v cannot be inlined (re-assigned closure variable)", a))
+                                                               }
                                                        } else {
                                                                fmt.Printf("%v: cannot inline global closure variable %v\n", n.Line(), n.Left)
+                                                               if logopt.Enabled() {
+                                                                       logopt.LogOpt(n.Pos, "cannotInlineCall", "inline", Curfn.funcname(),
+                                                                               fmt.Sprintf("%v cannot be inlined (global closure variable)", n.Left))
+                                                               }
                                                        }
                                                }
                                                break
@@ -842,7 +854,10 @@ var inlgen int
 //     n.Left = mkinlcall(n.Left, fn, isddd)
 func mkinlcall(n, fn *Node, maxCost int32, inlMap map[*Node]bool) *Node {
        if fn.Func.Inl == nil {
-               // No inlinable body.
+               if logopt.Enabled() {
+                       logopt.LogOpt(n.Pos, "cannotInlineCall", "inline", Curfn.funcname(),
+                               fmt.Sprintf("%s cannot be inlined", fn.pkgFuncName()))
+               }
                return n
        }
        if fn.Func.Inl.Cost > maxCost {
@@ -896,9 +911,6 @@ func mkinlcall(n, fn *Node, maxCost int32, inlMap map[*Node]bool) *Node {
        if Debug['m'] > 2 {
                fmt.Printf("%v: Before inlining: %+v\n", n.Line(), n)
        }
-       if logopt.Enabled() {
-               logopt.LogOpt(n.Pos, "inlineCall", "inline", Curfn.funcname(), fn.pkgFuncName())
-       }
 
        if ssaDump != "" && ssaDump == Curfn.funcname() {
                ssaDumpInlined = append(ssaDumpInlined, fn)
index cc28536fd4a3ec2f77296e85d7e5d2b894020caf..9704bc79d5a04ab59e241bf23dde8c4a3d85ead5 100644 (file)
@@ -30,6 +30,14 @@ func foo(w, z *pair) *int {
        }
        return &a[0]
 }
+
+// address taking prevents closure inlining
+func n() int {
+       foo := func() int { return 1 }
+       bar := &foo
+       x := (*bar)() + foo()
+       return x
+}
 `
 
 func want(t *testing.T, out string, desired string) {
@@ -164,12 +172,13 @@ func s15a8(x *[15]int64) [15]int64 {
                // All this delicacy with uriIfy and filepath.Join is to get this test to work right on Windows.
                slogged := normalize(logged, string(uriIfy(dir)), string(uriIfy("tmpdir")))
                t.Logf("%s", slogged)
-               // below shows proper inlining and nilcheck
-               want(t, slogged, `{"range":{"start":{"line":9,"character":13},"end":{"line":9,"character":13}},"severity":3,"code":"nilcheck","source":"go compiler","message":"","relatedInformation":[{"location":{"uri":"file://tmpdir/file.go","range":{"start":{"line":4,"character":11},"end":{"line":4,"character":11}}},"message":"inlineLoc"}]}`)
+               // below shows proper nilcheck
+               want(t, slogged, `{"range":{"start":{"line":9,"character":13},"end":{"line":9,"character":13}},"severity":3,"code":"nilcheck","source":"go compiler","message":"",`+
+                       `"relatedInformation":[{"location":{"uri":"file://tmpdir/file.go","range":{"start":{"line":4,"character":11},"end":{"line":4,"character":11}}},"message":"inlineLoc"}]}`)
                want(t, slogged, `{"range":{"start":{"line":11,"character":6},"end":{"line":11,"character":6}},"severity":3,"code":"isInBounds","source":"go compiler","message":""}`)
                want(t, slogged, `{"range":{"start":{"line":7,"character":6},"end":{"line":7,"character":6}},"severity":3,"code":"canInlineFunction","source":"go compiler","message":"cost: 35"}`)
-               want(t, slogged, `{"range":{"start":{"line":9,"character":13},"end":{"line":9,"character":13}},"severity":3,"code":"inlineCall","source":"go compiler","message":"x.bar"}`)
-               want(t, slogged, `{"range":{"start":{"line":8,"character":9},"end":{"line":8,"character":9}},"severity":3,"code":"inlineCall","source":"go compiler","message":"x.bar"}`)
+               want(t, slogged, `{"range":{"start":{"line":21,"character":21},"end":{"line":21,"character":21}},"severity":3,"code":"cannotInlineCall","source":"go compiler","message":"foo cannot be inlined (escaping closure variable)"}`)
+
        })
 }