]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: rewrite stale format strings
authorRuss Cox <rsc@golang.org>
Sun, 6 Dec 2020 19:53:38 +0000 (14:53 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 7 Dec 2020 20:41:29 +0000 (20:41 +0000)
On ir.Node, ir.Nodes, and ir.Op, # is ignored, so %#v is %v.
On ir.Node, %S is the same as %v.

On types.Type, # is ignored, so %#L is %L, %#v is %v.
On types.Type, 0 is ignored, so %0S is %S.

Rewrite all these using go test cmd/compile -r, plus a
few multiline formats mentioning %0S on types updated by hand.

Now the formats used in the compiler match the documentation
for the format methods, a minor miracle.

Passes buildall w/ toolstash -cmp.

Change-Id: I3d4a3fae543145a68da13eede91166632c5b1ceb
Reviewed-on: https://go-review.googlesource.com/c/go/+/275782
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/fmtmap_test.go
src/cmd/compile/internal/gc/closure.go
src/cmd/compile/internal/gc/escape.go
src/cmd/compile/internal/gc/iimport.go
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/pgen_test.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/unsafe.go
src/cmd/compile/internal/gc/walk.go
src/cmd/compile/internal/ir/fmt.go

index ca6f1c302e0916758b8e71e4f43926fa4744722e..756320285ca998a010dc02352685b41742118a04 100644 (file)
@@ -27,11 +27,8 @@ var knownFormats = map[string]string{
        "*cmd/compile/internal/ssa.Value %s":           "",
        "*cmd/compile/internal/types.Sym %+v":          "",
        "*cmd/compile/internal/types.Sym %S":           "",
-       "*cmd/compile/internal/types.Type %#L":         "",
-       "*cmd/compile/internal/types.Type %#v":         "",
        "*cmd/compile/internal/types.Type %+v":         "",
        "*cmd/compile/internal/types.Type %-S":         "",
-       "*cmd/compile/internal/types.Type %0S":         "",
        "*cmd/compile/internal/types.Type %L":          "",
        "*cmd/compile/internal/types.Type %S":          "",
        "*cmd/compile/internal/types.Type %s":          "",
@@ -41,14 +38,10 @@ var knownFormats = map[string]string{
        "cmd/compile/internal/arm.shift %d":            "",
        "cmd/compile/internal/gc.initKind %d":          "",
        "cmd/compile/internal/ir.Class %d":             "",
-       "cmd/compile/internal/ir.Node %#v":             "",
        "cmd/compile/internal/ir.Node %+v":             "",
        "cmd/compile/internal/ir.Node %L":              "",
-       "cmd/compile/internal/ir.Node %S":              "",
-       "cmd/compile/internal/ir.Nodes %#v":            "",
        "cmd/compile/internal/ir.Nodes %+v":            "",
        "cmd/compile/internal/ir.Nodes %.v":            "",
-       "cmd/compile/internal/ir.Op %#v":               "",
        "cmd/compile/internal/ir.Op %+v":               "",
        "cmd/compile/internal/ssa.BranchPrediction %d": "",
        "cmd/compile/internal/ssa.ID %d":               "",
index 01e5a953de8d52f894cbe85b648b07992c8c75f8..b56e255d10a3f9b677b77f50fdb7713c26fe4365 100644 (file)
@@ -100,7 +100,7 @@ func typecheckclosure(clo ir.Node, top int) {
                if !n.Name().Captured() {
                        n.Name().SetCaptured(true)
                        if n.Name().Decldepth == 0 {
-                               base.Fatalf("typecheckclosure: var %S does not have decldepth assigned", n)
+                               base.Fatalf("typecheckclosure: var %v does not have decldepth assigned", n)
                        }
 
                        // Ignore assignments to the variable in straightline code
index a7458ab733fb27cc4db29ec89fc2f01e72600deb..f317e9999cc536e89fc87c7a28e3f0d6170e1733 100644 (file)
@@ -757,7 +757,7 @@ func (e *Escape) assign(dst, src ir.Node, why string, where ir.Node) {
        // Filter out some no-op assignments for escape analysis.
        ignore := dst != nil && src != nil && isSelfAssign(dst, src)
        if ignore && base.Flag.LowerM != 0 {
-               base.WarnfAt(where.Pos(), "%v ignoring self-assignment in %S", funcSym(e.curfn), where)
+               base.WarnfAt(where.Pos(), "%v ignoring self-assignment in %v", funcSym(e.curfn), where)
        }
 
        k := e.addr(dst)
@@ -1454,7 +1454,7 @@ func (e *Escape) finish(fns []*ir.Func) {
                if loc.escapes {
                        if n.Op() != ir.ONAME {
                                if base.Flag.LowerM != 0 {
-                                       base.WarnfAt(n.Pos(), "%S escapes to heap", n)
+                                       base.WarnfAt(n.Pos(), "%v escapes to heap", n)
                                }
                                if logopt.Enabled() {
                                        logopt.LogOpt(n.Pos(), "escape", "escape", ir.FuncName(e.curfn))
@@ -1464,7 +1464,7 @@ func (e *Escape) finish(fns []*ir.Func) {
                        addrescapes(n)
                } else {
                        if base.Flag.LowerM != 0 && n.Op() != ir.ONAME {
-                               base.WarnfAt(n.Pos(), "%S does not escape", n)
+                               base.WarnfAt(n.Pos(), "%v does not escape", n)
                        }
                        n.SetEsc(EscNone)
                        if loc.transient {
index 859263c83f33786c4015cb0700fa413d56f8efe0..1f75393b3e1e5f94e0fd2a7a809a0ab84f43b321 100644 (file)
@@ -713,9 +713,9 @@ func (r *importReader) doInline(fn *ir.Func) {
 
        if base.Flag.E > 0 && base.Flag.LowerM > 2 {
                if base.Flag.LowerM > 3 {
-                       fmt.Printf("inl body for %v %#v: %+v\n", fn, fn.Type(), ir.AsNodes(fn.Inl.Body))
+                       fmt.Printf("inl body for %v %v: %+v\n", fn, fn.Type(), ir.AsNodes(fn.Inl.Body))
                } else {
-                       fmt.Printf("inl body for %v %#v: %v\n", fn, fn.Type(), ir.AsNodes(fn.Inl.Body))
+                       fmt.Printf("inl body for %v %v: %v\n", fn, fn.Type(), ir.AsNodes(fn.Inl.Body))
                }
        }
 }
index 77fbf7c80270078f9e74ee51fc2b4443a7931fa3..f965fa6325a5a2a90f2ee913c049457b09332d75 100644 (file)
@@ -90,7 +90,7 @@ func typecheckinl(fn *ir.Func) {
        }
 
        if base.Flag.LowerM > 2 || base.Debug.Export != 0 {
-               fmt.Printf("typecheck import [%v] %L { %#v }\n", fn.Sym(), fn, ir.AsNodes(fn.Inl.Body))
+               fmt.Printf("typecheck import [%v] %L { %v }\n", fn.Sym(), fn, ir.AsNodes(fn.Inl.Body))
        }
 
        savefn := Curfn
@@ -219,7 +219,7 @@ func caninl(fn *ir.Func) {
        }
 
        if base.Flag.LowerM > 1 {
-               fmt.Printf("%v: can inline %#v with cost %d as: %#v { %#v }\n", ir.Line(fn), n, inlineMaxBudget-visitor.budget, fn.Type(), ir.AsNodes(n.Func().Inl.Body))
+               fmt.Printf("%v: can inline %v with cost %d as: %v { %v }\n", ir.Line(fn), n, inlineMaxBudget-visitor.budget, fn.Type(), ir.AsNodes(n.Func().Inl.Body))
        } else if base.Flag.LowerM != 0 {
                fmt.Printf("%v: can inline %v\n", ir.Line(fn), n)
        }
@@ -816,7 +816,7 @@ func mkinlcall(n ir.Node, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]bool,
 
        // We have a function node, and it has an inlineable body.
        if base.Flag.LowerM > 1 {
-               fmt.Printf("%v: inlining call to %v %#v { %#v }\n", ir.Line(n), fn.Sym(), fn.Type(), ir.AsNodes(fn.Inl.Body))
+               fmt.Printf("%v: inlining call to %v %v { %v }\n", ir.Line(n), fn.Sym(), fn.Type(), ir.AsNodes(fn.Inl.Body))
        } else if base.Flag.LowerM != 0 {
                fmt.Printf("%v: inlining call to %v\n", ir.Line(n), fn)
        }
index 473df82a0d7096083f723e37e1dcff3e896cf763..ad8b87c6f539fde4853be993f3cdb1af5b362717 100644 (file)
@@ -145,11 +145,11 @@ func TestCmpstackvar(t *testing.T) {
        for _, d := range testdata {
                got := cmpstackvarlt(d.a, d.b)
                if got != d.lt {
-                       t.Errorf("want %#v < %#v", d.a, d.b)
+                       t.Errorf("want %v < %v", d.a, d.b)
                }
                // If we expect a < b to be true, check that b < a is false.
                if d.lt && cmpstackvarlt(d.b, d.a) {
-                       t.Errorf("unexpected %#v < %#v", d.b, d.a)
+                       t.Errorf("unexpected %v < %v", d.b, d.a)
                }
        }
 }
index dffebc58f2d1765dd2fe5b4e4aac75c7b217b5b1..e05a124b29cef69620e65c7bf46f5bca725f0084 100644 (file)
@@ -291,12 +291,12 @@ func assignop(src, dst *types.Type) (ir.Op, string) {
                        why = fmt.Sprintf(":\n\t%v does not implement %v (%v method is marked 'nointerface')", src, dst, missing.Sym)
                } else if have != nil && have.Sym == missing.Sym {
                        why = fmt.Sprintf(":\n\t%v does not implement %v (wrong type for %v method)\n"+
-                               "\t\thave %v%0S\n\t\twant %v%0S", src, dst, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
+                               "\t\thave %v%S\n\t\twant %v%S", src, dst, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
                } else if ptr != 0 {
                        why = fmt.Sprintf(":\n\t%v does not implement %v (%v method has pointer receiver)", src, dst, missing.Sym)
                } else if have != nil {
                        why = fmt.Sprintf(":\n\t%v does not implement %v (missing %v method)\n"+
-                               "\t\thave %v%0S\n\t\twant %v%0S", src, dst, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
+                               "\t\thave %v%S\n\t\twant %v%S", src, dst, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
                } else {
                        why = fmt.Sprintf(":\n\t%v does not implement %v (missing %v method)", src, dst, missing.Sym)
                }
index 85094dbebcad79af0bb48b525a8c298e97682a17..a7c05c6c0fa6244290a291a52381322828866306 100644 (file)
@@ -58,7 +58,7 @@ func tracePrint(title string, n ir.Node) func(np *ir.Node) {
 
                skipDowidthForTracing = true
                defer func() { skipDowidthForTracing = false }()
-               fmt.Printf("%s: %s=> %p %s %v tc=%d type=%#L\n", pos, indent, n, op, n, tc, typ)
+               fmt.Printf("%s: %s=> %p %s %v tc=%d type=%L\n", pos, indent, n, op, n, tc, typ)
        }
 }
 
@@ -1039,12 +1039,12 @@ func typecheck1(n ir.Node, top int) (res ir.Node) {
                        if !implements(n.Type(), t, &missing, &have, &ptr) {
                                if have != nil && have.Sym == missing.Sym {
                                        base.Errorf("impossible type assertion:\n\t%v does not implement %v (wrong type for %v method)\n"+
-                                               "\t\thave %v%0S\n\t\twant %v%0S", n.Type(), t, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
+                                               "\t\thave %v%S\n\t\twant %v%S", n.Type(), t, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
                                } else if ptr != 0 {
                                        base.Errorf("impossible type assertion:\n\t%v does not implement %v (%v method has pointer receiver)", n.Type(), t, missing.Sym)
                                } else if have != nil {
                                        base.Errorf("impossible type assertion:\n\t%v does not implement %v (missing %v method)\n"+
-                                               "\t\thave %v%0S\n\t\twant %v%0S", n.Type(), t, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
+                                               "\t\thave %v%S\n\t\twant %v%S", n.Type(), t, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
                                } else {
                                        base.Errorf("impossible type assertion:\n\t%v does not implement %v (missing %v method)", n.Type(), t, missing.Sym)
                                }
index 678924b22949536f3995e83ea838eed908c25da0..d7ae5d7aaa6964dbc61fff9b2f5ad31f88d622ea 100644 (file)
@@ -70,7 +70,7 @@ func evalunsafe(n ir.Node) int64 {
                                v += r.Offset()
                        default:
                                ir.Dump("unsafenmagic", n.Left())
-                               base.Fatalf("impossible %#v node after dot insertion", r.Op())
+                               base.Fatalf("impossible %v node after dot insertion", r.Op())
                        }
                }
                return v
index 346817e589fe58cb5f1ef646300dee98630a0e11..4189d1a721735cd20acd702af6fb4074fc8ec407 100644 (file)
@@ -2154,7 +2154,7 @@ func reorder3(all []ir.Node) []ir.Node {
 
                switch l.Op() {
                default:
-                       base.Fatalf("reorder3 unexpected lvalue %#v", l.Op())
+                       base.Fatalf("reorder3 unexpected lvalue %v", l.Op())
 
                case ir.ONAME:
                        break
index 85c6b218e2a327d80702c368ebc15a28b52978ff..68e425bdaa287f44e7a55a80f10c5aa76c40bdc6 100644 (file)
@@ -125,12 +125,6 @@ func (o Op) Format(s fmt.State, verb rune) {
 //     %+v     Debug syntax, as in Dump.
 //
 func FmtNode(n Node, s fmt.State, verb rune) {
-       // TODO(rsc): Remove uses of %#v, which behaves just like %v.
-       // TODO(rsc): Remove uses of %S, which behaves just like %v.
-       if verb == 'S' {
-               verb = 'v'
-       }
-
        // %+v prints Dump.
        // Otherwise we print Go syntax.
        if s.Flag('+') && verb == 'v' {
@@ -355,7 +349,7 @@ func stmtFmt(n Node, s fmt.State) {
                        break
                }
 
-               fmt.Fprintf(s, "%v %#v= %v", n.Left(), n.SubOp(), n.Right())
+               fmt.Fprintf(s, "%v %v= %v", n.Left(), n.SubOp(), n.Right())
 
        case OAS2, OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
                if n.Colas() && !complexinit {
@@ -446,7 +440,7 @@ func stmtFmt(n Node, s fmt.State) {
                        break
                }
 
-               fmt.Fprintf(s, "%#v", n.Op())
+               fmt.Fprintf(s, "%v", n.Op())
                if simpleinit {
                        fmt.Fprintf(s, " %v;", n.Init().First())
                }
@@ -466,9 +460,9 @@ func stmtFmt(n Node, s fmt.State) {
 
        case OBREAK, OCONTINUE, OGOTO, OFALL:
                if n.Sym() != nil {
-                       fmt.Fprintf(s, "%#v %v", n.Op(), n.Sym())
+                       fmt.Fprintf(s, "%v %v", n.Op(), n.Sym())
                } else {
-                       fmt.Fprintf(s, "%#v", n.Op())
+                       fmt.Fprintf(s, "%v", n.Op())
                }
 
        case OLABEL:
@@ -754,9 +748,9 @@ func exprFmt(n Node, s fmt.State, prec int) {
 
        case OCOMPLEX, OCOPY:
                if n.Left() != nil {
-                       fmt.Fprintf(s, "%#v(%v, %v)", n.Op(), n.Left(), n.Right())
+                       fmt.Fprintf(s, "%v(%v, %v)", n.Op(), n.Left(), n.Right())
                } else {
-                       fmt.Fprintf(s, "%#v(%.v)", n.Op(), n.List())
+                       fmt.Fprintf(s, "%v(%.v)", n.Op(), n.List())
                }
 
        case OCONV,
@@ -795,14 +789,14 @@ func exprFmt(n Node, s fmt.State, prec int) {
                OPRINT,
                OPRINTN:
                if n.Left() != nil {
-                       fmt.Fprintf(s, "%#v(%v)", n.Op(), n.Left())
+                       fmt.Fprintf(s, "%v(%v)", n.Op(), n.Left())
                        return
                }
                if n.IsDDD() {
-                       fmt.Fprintf(s, "%#v(%.v...)", n.Op(), n.List())
+                       fmt.Fprintf(s, "%v(%.v...)", n.Op(), n.List())
                        return
                }
-               fmt.Fprintf(s, "%#v(%.v)", n.Op(), n.List())
+               fmt.Fprintf(s, "%v(%.v)", n.Op(), n.List())
 
        case OCALL, OCALLFUNC, OCALLINTER, OCALLMETH, OGETG:
                exprFmt(n.Left(), s, nprec)
@@ -832,7 +826,7 @@ func exprFmt(n Node, s fmt.State, prec int) {
 
        case OPLUS, ONEG, OADDR, OBITNOT, ODEREF, ONOT, ORECV:
                // Unary
-               fmt.Fprintf(s, "%#v", n.Op())
+               fmt.Fprintf(s, "%v", n.Op())
                if n.Left() != nil && n.Left().Op() == n.Op() {
                        fmt.Fprint(s, " ")
                }
@@ -860,7 +854,7 @@ func exprFmt(n Node, s fmt.State, prec int) {
                OSUB,
                OXOR:
                exprFmt(n.Left(), s, nprec)
-               fmt.Fprintf(s, " %#v ", n.Op())
+               fmt.Fprintf(s, " %v ", n.Op())
                exprFmt(n.Right(), s, nprec+1)
 
        case OADDSTR: