]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: tweaks to loopvar logging
authorDavid Chase <drchase@google.com>
Fri, 19 May 2023 18:55:56 +0000 (14:55 -0400)
committerDavid Chase <drchase@google.com>
Fri, 19 May 2023 20:55:53 +0000 (20:55 +0000)
This adds the loop type to the json/LSP logging, to help with
studies of how many loops of which kind were modified.

Change-Id: I637a630cd275b413259601c0070b963f3c6d2185
Reviewed-on: https://go-review.googlesource.com/c/go/+/496515
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/loopvar/loopvar.go

index e5fedd2fceaf0ace1ad27aadc1acd2275206c273..43f081c10a12debb4647232f387f15585d1fe7c5 100644 (file)
@@ -18,7 +18,7 @@ import (
 
 type VarAndLoop struct {
        Name    *ir.Name
-       Loop    ir.Node  // the *ir.ForStmt or *ir.ForStmt. Used for identity and position
+       Loop    ir.Node  // the *ir.RangeStmt or *ir.ForStmt. Used for identity and position
        LastPos src.XPos // the last position observed within Loop
 }
 
@@ -597,20 +597,25 @@ func LogTransformations(transformed []VarAndLoop) {
                for _, l := range loops {
                        pos := l.loop.Pos()
                        last := l.last
+                       loopKind := "range"
+                       if _, ok := l.loop.(*ir.ForStmt); ok {
+                               loopKind = "for"
+                       }
                        if logopt.Enabled() {
-                               // Intended to
-                               logopt.LogOptRange(pos, last, "loop-modified", "loopvar", ir.FuncName(l.curfn))
+                               // Intended to help with performance debugging, we record whole loop ranges
+                               logopt.LogOptRange(pos, last, "loop-modified-"+loopKind, "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 modified", last.Line(), last.Col())
+                                       base.WarnfAt(pos, "%s loop ending at %d:%d was modified", loopKind, last.Line(), last.Col())
                                } else {
                                        pos = trueInlinedPos(inner)
                                        last = trueInlinedPos(base.Ctxt.InnermostPos(last))
-                                       base.WarnfAt(pos, "loop ending at %d:%d was modified (loop inlined into %s:%d)", last.Line(), last.Col(), outer.Filename(), outer.Line())
+                                       base.WarnfAt(pos, "%s loop ending at %d:%d was modified (loop inlined into %s:%d)", loopKind, last.Line(), last.Col(), outer.Filename(), outer.Line())
                                }
                        }
                }