]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/loopvar: adjust logging messages
authorDavid Chase <drchase@google.com>
Fri, 5 May 2023 20:29:37 +0000 (16:29 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 9 May 2023 12:49:49 +0000 (12:49 +0000)
Michael Stapelberg thought the former messages had
upside potential, Russ and I agreed.

Also slightly tweaked the json logging, not sure if
anyone will use it but it should at least be okay.

Change-Id: Iaab75114dd5f5d8f011fab22d32b57abc0272815
Reviewed-on: https://go-review.googlesource.com/c/go/+/493135
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: David Chase <drchase@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
src/cmd/compile/internal/loopvar/loopvar.go
src/cmd/compile/internal/loopvar/loopvar_test.go

index 44ff449689379b1b04a0cde0d9597931ff839950..0d8a6d2d6e7c23110a5bc253b91ec1f160886af5 100644 (file)
@@ -545,29 +545,35 @@ func LogTransformations(transformed []VarAndLoop) {
                                loops = append(loops, loopPos{l, lv.LastPos, n.Curfn})
                        }
                        pos := n.Pos()
+
+                       inner := base.Ctxt.InnermostPos(pos)
+                       outer := base.Ctxt.OutermostPos(pos)
+
                        if logopt.Enabled() {
                                // For automated checking of coverage of this transformation, include this in the JSON information.
+                               var nString interface{} = n
+                               if inner != outer {
+                                       nString = fmt.Sprintf("%v (from inline)", n)
+                               }
                                if n.Esc() == ir.EscHeap {
-                                       logopt.LogOpt(pos, "transform-escape", "loopvar", ir.FuncName(n.Curfn))
+                                       logopt.LogOpt(pos, "iteration-variable-to-heap", "loopvar", ir.FuncName(n.Curfn), nString)
                                } else {
-                                       logopt.LogOpt(pos, "transform-noescape", "loopvar", ir.FuncName(n.Curfn))
+                                       logopt.LogOpt(pos, "iteration-variable-to-stack", "loopvar", ir.FuncName(n.Curfn), nString)
                                }
                        }
                        if print {
-                               inner := base.Ctxt.InnermostPos(pos)
-                               outer := base.Ctxt.OutermostPos(pos)
                                if inner == outer {
                                        if n.Esc() == ir.EscHeap {
-                                               base.WarnfAt(pos, "transformed loop variable %v escapes", n)
+                                               base.WarnfAt(pos, "loop variable %v now per-iteration, heap-allocated", n)
                                        } else {
-                                               base.WarnfAt(pos, "transformed loop variable %v does not escape", n)
+                                               base.WarnfAt(pos, "loop variable %v now per-iteration, stack-allocated", n)
                                        }
                                } else {
                                        innerXPos := trueInlinedPos(inner)
                                        if n.Esc() == ir.EscHeap {
-                                               base.WarnfAt(innerXPos, "transformed loop variable %v escapes (loop inlined into %s:%d)", n, outer.Filename(), outer.Line())
+                                               base.WarnfAt(innerXPos, "loop variable %v now per-iteration, heap-allocated (loop inlined into %s:%d)", n, outer.Filename(), outer.Line())
                                        } else {
-                                               base.WarnfAt(innerXPos, "transformed loop variable %v does not escape (loop inlined into %s:%d)", n, outer.Filename(), outer.Line())
+                                               base.WarnfAt(innerXPos, "loop variable %v now per-iteration, stack-allocated (loop inlined into %s:%d)", n, outer.Filename(), outer.Line())
                                        }
                                }
                        }
@@ -577,18 +583,18 @@ func LogTransformations(transformed []VarAndLoop) {
                        last := l.last
                        if logopt.Enabled() {
                                // Intended to
-                               logopt.LogOptRange(pos, last, "transform-loop", "loopvar", ir.FuncName(l.curfn))
+                               logopt.LogOptRange(pos, last, "loop-modified", "loopvar", ir.FuncName(l.curfn))
                        }
                        if print && 3 <= base.Debug.LoopVar {
                                // TODO decide if we want to keep this, or not.  It was helpful for validating logopt, otherwise, eh.
                                inner := base.Ctxt.InnermostPos(pos)
                                outer := base.Ctxt.OutermostPos(pos)
                                if inner == outer {
-                                       base.WarnfAt(pos, "loop ending at %d:%d was transformed", last.Line(), last.Col())
+                                       base.WarnfAt(pos, "loop ending at %d:%d was modified", last.Line(), last.Col())
                                } else {
                                        pos = trueInlinedPos(inner)
                                        last = trueInlinedPos(base.Ctxt.InnermostPos(last))
-                                       base.WarnfAt(pos, "loop ending at %d:%d was transformed (loop inlined into %s:%d)", last.Line(), last.Col(), outer.Filename(), outer.Line())
+                                       base.WarnfAt(pos, "loop ending at %d:%d was modified (loop inlined into %s:%d)", last.Line(), last.Col(), outer.Filename(), outer.Line())
                                }
                        }
                }
index 22ff15ee8be622b7dd92a7507f39a804db80d98c..1a13f0e30cb187fa070ae6672240913e51d517b3 100644 (file)
@@ -39,12 +39,12 @@ var cases = []testcase{
        {"-1", "", 11, for_files[:1]},
        {"0", "", 0, for_files[:1]},
        {"1", "", 0, for_files[:1]},
-       {"2", "transformed loop variable i ", 0, for_files},
+       {"2", "loop variable i now per-iteration,", 0, for_files},
 
        {"-1", "", 11, range_files[:1]},
        {"0", "", 0, range_files[:1]},
        {"1", "", 0, range_files[:1]},
-       {"2", "transformed loop variable i ", 0, range_files},
+       {"2", "loop variable i now per-iteration,", 0, range_files},
 
        {"1", "", 0, []string{"for_nested.go"}},
 }
@@ -230,7 +230,7 @@ func TestLoopVarOpt(t *testing.T) {
 
        t.Logf(m)
 
-       yCount := strings.Count(m, "opt.go:16:6: transformed loop variable private escapes (loop inlined into ./opt.go:30)")
+       yCount := strings.Count(m, "opt.go:16:6: loop variable private now per-iteration, heap-allocated (loop inlined into ./opt.go:30)")
        nCount := strings.Count(m, "shared")
 
        if yCount != 1 {