From 1524bd1c781463be642a7c0c6012cbdf4e91fff2 Mon Sep 17 00:00:00 2001 From: David Chase Date: Fri, 19 May 2023 14:55:56 -0400 Subject: [PATCH] cmd/compile: tweaks to loopvar logging 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 Reviewed-by: Matthew Dempsky TryBot-Result: Gopher Robot --- src/cmd/compile/internal/loopvar/loopvar.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cmd/compile/internal/loopvar/loopvar.go b/src/cmd/compile/internal/loopvar/loopvar.go index e5fedd2fce..43f081c10a 100644 --- a/src/cmd/compile/internal/loopvar/loopvar.go +++ b/src/cmd/compile/internal/loopvar/loopvar.go @@ -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()) } } } -- 2.48.1