Skip to content

Commit fced302

Browse files
committed
cmd/compile: change gc logging to report inline failure instead of success
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 83e288f commit fced302

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/cmd/compile/internal/gc/inl.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,10 @@ func inlnode(n *Node, maxCost int32, inlMap map[*Node]bool) *Node {
687687
if Debug['m'] > 1 {
688688
fmt.Printf("%v: cannot inline escaping closure variable %v\n", n.Line(), n.Left)
689689
}
690+
if logopt.Enabled() {
691+
logopt.LogOpt(n.Pos, "cannotInlineCall", "inline", Curfn.funcname(),
692+
fmt.Sprintf("%v cannot be inlined (escaping closure variable)", n.Left))
693+
}
690694
break
691695
}
692696

@@ -695,8 +699,16 @@ func inlnode(n *Node, maxCost int32, inlMap map[*Node]bool) *Node {
695699
if Debug['m'] > 1 {
696700
if a != nil {
697701
fmt.Printf("%v: cannot inline re-assigned closure variable at %v: %v\n", n.Line(), a.Line(), a)
702+
if logopt.Enabled() {
703+
logopt.LogOpt(n.Pos, "cannotInlineCall", "inline", Curfn.funcname(),
704+
fmt.Sprintf("%v cannot be inlined (re-assigned closure variable)", a))
705+
}
698706
} else {
699707
fmt.Printf("%v: cannot inline global closure variable %v\n", n.Line(), n.Left)
708+
if logopt.Enabled() {
709+
logopt.LogOpt(n.Pos, "cannotInlineCall", "inline", Curfn.funcname(),
710+
fmt.Sprintf("%v cannot be inlined (global closure variable)", n.Left))
711+
}
700712
}
701713
}
702714
break
@@ -842,7 +854,10 @@ var inlgen int
842854
// n.Left = mkinlcall(n.Left, fn, isddd)
843855
func mkinlcall(n, fn *Node, maxCost int32, inlMap map[*Node]bool) *Node {
844856
if fn.Func.Inl == nil {
845-
// No inlinable body.
857+
if logopt.Enabled() {
858+
logopt.LogOpt(n.Pos, "cannotInlineCall", "inline", Curfn.funcname(),
859+
fmt.Sprintf("%s cannot be inlined", fn.pkgFuncName()))
860+
}
846861
return n
847862
}
848863
if fn.Func.Inl.Cost > maxCost {
@@ -896,9 +911,6 @@ func mkinlcall(n, fn *Node, maxCost int32, inlMap map[*Node]bool) *Node {
896911
if Debug['m'] > 2 {
897912
fmt.Printf("%v: Before inlining: %+v\n", n.Line(), n)
898913
}
899-
if logopt.Enabled() {
900-
logopt.LogOpt(n.Pos, "inlineCall", "inline", Curfn.funcname(), fn.pkgFuncName())
901-
}
902914

903915
if ssaDump != "" && ssaDump == Curfn.funcname() {
904916
ssaDumpInlined = append(ssaDumpInlined, fn)

src/cmd/compile/internal/logopt/logopt_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ func foo(w, z *pair) *int {
3030
}
3131
return &a[0]
3232
}
33+
34+
// address taking prevents closure inlining
35+
func n() int {
36+
foo := func() int { return 1 }
37+
bar := &foo
38+
x := (*bar)() + foo()
39+
return x
40+
}
3341
`
3442

3543
func want(t *testing.T, out string, desired string) {
@@ -164,12 +172,13 @@ func s15a8(x *[15]int64) [15]int64 {
164172
// All this delicacy with uriIfy and filepath.Join is to get this test to work right on Windows.
165173
slogged := normalize(logged, string(uriIfy(dir)), string(uriIfy("tmpdir")))
166174
t.Logf("%s", slogged)
167-
// below shows proper inlining and nilcheck
168-
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"}]}`)
175+
// below shows proper nilcheck
176+
want(t, slogged, `{"range":{"start":{"line":9,"character":13},"end":{"line":9,"character":13}},"severity":3,"code":"nilcheck","source":"go compiler","message":"",`+
177+
`"relatedInformation":[{"location":{"uri":"file://tmpdir/file.go","range":{"start":{"line":4,"character":11},"end":{"line":4,"character":11}}},"message":"inlineLoc"}]}`)
169178
want(t, slogged, `{"range":{"start":{"line":11,"character":6},"end":{"line":11,"character":6}},"severity":3,"code":"isInBounds","source":"go compiler","message":""}`)
170179
want(t, slogged, `{"range":{"start":{"line":7,"character":6},"end":{"line":7,"character":6}},"severity":3,"code":"canInlineFunction","source":"go compiler","message":"cost: 35"}`)
171-
want(t, slogged, `{"range":{"start":{"line":9,"character":13},"end":{"line":9,"character":13}},"severity":3,"code":"inlineCall","source":"go compiler","message":"x.bar"}`)
172-
want(t, slogged, `{"range":{"start":{"line":8,"character":9},"end":{"line":8,"character":9}},"severity":3,"code":"inlineCall","source":"go compiler","message":"x.bar"}`)
180+
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)"}`)
181+
173182
})
174183
}
175184

0 commit comments

Comments
 (0)