]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types, types2: improved tracing output throughout (debugging support)
authorRobert Griesemer <gri@golang.org>
Thu, 24 Feb 2022 21:10:34 +0000 (13:10 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 21 Mar 2022 19:10:30 +0000 (19:10 +0000)
This change fine-tunes tracing output and adds additional
descriptions for delayed actions that were missing tracing.

Change-Id: Ib5e70e8f40ef564194cdb0e8d12c38e15388b987
Reviewed-on: https://go-review.googlesource.com/c/go/+/387919
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
20 files changed:
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/check.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/instantiate.go
src/cmd/compile/internal/types2/named.go
src/cmd/compile/internal/types2/stmt.go
src/cmd/compile/internal/types2/typeset.go
src/cmd/compile/internal/types2/typexpr.go
src/cmd/compile/internal/types2/union.go
src/go/types/call.go
src/go/types/check.go
src/go/types/decl.go
src/go/types/expr.go
src/go/types/instantiate.go
src/go/types/named.go
src/go/types/stmt.go
src/go/types/typeset.go
src/go/types/typexpr.go
src/go/types/union.go

index 6cc30a7015c287281963c5fd0e2c3fd9f5d8820b..3ade147dfe2e4cdc5da61d62e30221b4aeeb0fbe 100644 (file)
@@ -64,7 +64,7 @@ func (check *Checker) instantiateSignature(pos syntax.Pos, typ *Signature, targs
        assert(len(targs) == typ.TypeParams().Len())
 
        if check.conf.Trace {
-               check.trace(pos, "-- instantiating %s with %s", typ, targs)
+               check.trace(pos, "-- instantiating signature %s with %s", typ, targs)
                check.indent++
                defer func() {
                        check.indent--
@@ -88,7 +88,7 @@ func (check *Checker) instantiateSignature(pos syntax.Pos, typ *Signature, targs
                } else {
                        check.mono.recordInstance(check.pkg, pos, tparams, targs, xlist)
                }
-       })
+       }).describef(pos, "verify instantiation")
 
        return inst
 }
index 4ec6a7b4fd398fc81c427e3fd536b7ffc509b9b3..5cf8454aa44049f21b917ea5d47ec425f3a94048 100644 (file)
@@ -373,11 +373,17 @@ func (check *Checker) processDelayed(top int) {
        // this is a sufficiently bounded process.
        for i := top; i < len(check.delayed); i++ {
                a := &check.delayed[i]
-               if check.conf.Trace && a.desc != nil {
-                       fmt.Println()
-                       check.trace(a.desc.pos.Pos(), "-- "+a.desc.format, a.desc.args...)
+               if check.conf.Trace {
+                       if a.desc != nil {
+                               check.trace(a.desc.pos.Pos(), "-- "+a.desc.format, a.desc.args...)
+                       } else {
+                               check.trace(nopos, "-- delayed %p", a.f)
+                       }
                }
                a.f() // may append to check.delayed
+               if check.conf.Trace {
+                       fmt.Println()
+               }
        }
        assert(top <= len(check.delayed)) // stack must not have shrunk
        check.delayed = check.delayed[:top]
index 01c47ee7c19dc39dd67b826ef6f5e8c7bea5d16a..95143cbed5e386d8383278ef2716deba1bf99f59 100644 (file)
@@ -716,7 +716,7 @@ func (check *Checker) funcDecl(obj *Func, decl *declInfo) {
        if !check.conf.IgnoreFuncBodies && fdecl.Body != nil {
                check.later(func() {
                        check.funcBody(decl, obj.name, sig, fdecl.Body, nil)
-               })
+               }).describef(obj, "func %s", obj.name)
        }
 }
 
index e59f0b74aca9e4a22f28492ff2f48d23ad7b5593..7d2a7ba46bc16f4b159bd55a055199a50a3cb48e 100644 (file)
@@ -1214,7 +1214,7 @@ const (
 //
 func (check *Checker) rawExpr(x *operand, e syntax.Expr, hint Type, allowGeneric bool) exprKind {
        if check.conf.Trace {
-               check.trace(e.Pos(), "expr %s", e)
+               check.trace(e.Pos(), "-- expr %s", e)
                check.indent++
                defer func() {
                        check.indent--
@@ -1328,7 +1328,7 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin
                                // but before the enclosing scope contents changes (#22992).
                                check.later(func() {
                                        check.funcBody(decl, "<function literal>", sig, e.Body, iota)
-                               })
+                               }).describef(e, "func literal")
                        }
                        x.mode = value
                        x.typ = sig
index 9eced489dcf114a190838f93258faa1c7a8cd707..a511538ccc6b3387c06b46b988912e517561266c 100644 (file)
@@ -61,7 +61,7 @@ func Instantiate(ctxt *Context, orig Type, targs []Type, validate bool) (Type, e
 
 // instance creates a type or function instance using the given original type
 // typ and arguments targs. For Named types the resulting instance will be
-// unexpanded.
+// unexpanded. check may be nil.
 func (check *Checker) instance(pos syntax.Pos, orig Type, targs []Type, ctxt *Context) (res Type) {
        var h string
        if ctxt != nil {
@@ -103,6 +103,7 @@ func (check *Checker) instance(pos syntax.Pos, orig Type, targs []Type, ctxt *Co
                // anymore; we need to set tparams to nil.
                sig.tparams = nil
                res = sig
+
        default:
                // only types and functions can be generic
                panic(fmt.Sprintf("%v: cannot instantiate %v", pos, orig))
index daf8fdc986103b4f3cb081dad24db92aa4d7cc5b..8dd9fb6bc40c6c469a88eb2ac556c8e1c9505f07 100644 (file)
@@ -354,11 +354,19 @@ func (check *Checker) bestContext(ctxt *Context) *Context {
 // expandNamed ensures that the underlying type of n is instantiated.
 // The underlying type will be Typ[Invalid] if there was an error.
 func expandNamed(ctxt *Context, n *Named, instPos syntax.Pos) (tparams *TypeParamList, underlying Type, methods *methodList) {
+       check := n.check
+       if check != nil && check.conf.Trace {
+               check.trace(instPos, "-- expandNamed %s", n)
+               check.indent++
+               defer func() {
+                       check.indent--
+                       check.trace(instPos, "=> %s (tparams = %s, under = %s)", n, tparams.list(), underlying)
+               }()
+       }
+
        n.orig.resolve(ctxt)
        assert(n.orig.underlying != nil)
 
-       check := n.check
-
        if _, unexpanded := n.orig.underlying.(*Named); unexpanded {
                // We should only get an unexpanded underlying here during type checking
                // (for example, in recursive type declarations).
index 819b7c2463d6bbb39c4db30dc37d492d323dd7d0..2b6abbde7e2224c0663f81392001ff878371fd5a 100644 (file)
@@ -18,10 +18,7 @@ func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body
        }
 
        if check.conf.Trace {
-               check.trace(body.Pos(), "--- %s: %s", name, sig)
-               defer func() {
-                       check.trace(syntax.EndPos(body), "--- <end>")
-               }()
+               check.trace(body.Pos(), "-- %s: %s", name, sig)
        }
 
        // set function scope extent
index 646b436685c7fdc60904ceeef65c82d7e54411c7..328c5029e748e3485ea9cc52670b80a2be273c92 100644 (file)
@@ -173,7 +173,7 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
                        pos = ityp.methods[0].pos
                }
 
-               check.trace(pos, "type set for %s", ityp)
+               check.trace(pos, "-- type set for %s", ityp)
                check.indent++
                defer func() {
                        check.indent--
@@ -248,7 +248,7 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
                                        err.errorf(mpos[other.(*Func)], "other declaration of %s", m.name)
                                        check.report(&err)
                                }
-                       })
+                       }).describef(pos, "duplicate method check for %s", m.name)
                }
        }
 
index 40333fd77f904e913da0890ad278565265dcee3f..afbea060329d839956b78762c63fcb2b106f6301 100644 (file)
@@ -174,7 +174,7 @@ func (check *Checker) validVarType(e syntax.Expr, typ Type) {
                                }
                        }
                }
-       })
+       }).describef(e, "check var type %s", typ)
 }
 
 // definedType is like typ but also accepts a type name def.
@@ -372,7 +372,7 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *Named) (T Type) {
                                }
                                check.errorf(e.Key, "invalid map key type %s%s", typ.key, why)
                        }
-               })
+               }).describef(e.Key, "check map key %s", typ.key)
 
                return typ
 
@@ -409,7 +409,7 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *Named) (T Type) {
 
 func (check *Checker) instantiatedType(x syntax.Expr, xlist []syntax.Expr, def *Named) (res Type) {
        if check.conf.Trace {
-               check.trace(x.Pos(), "-- instantiating %s with %s", x, xlist)
+               check.trace(x.Pos(), "-- instantiating type %s with %s", x, xlist)
                check.indent++
                defer func() {
                        check.indent--
@@ -498,7 +498,7 @@ func (check *Checker) instantiatedType(x syntax.Expr, xlist []syntax.Expr, def *
                }
 
                check.validType(inst)
-       })
+       }).describef(x, "resolve instance %s", inst)
 
        return inst
 }
index e317b9cced4c0dbc6e9e53b814bf3186fb27ca12..132e73098a7c612c18a4aef36987549c4448742f 100644 (file)
@@ -129,7 +129,7 @@ func parseUnion(check *Checker, uexpr syntax.Expr) Type {
                                check.softErrorf(tlist[i], "overlapping terms %s and %s", t, terms[j])
                        }
                }
-       })
+       }).describef(uexpr, "check term validity %s", uexpr)
 
        return u
 }
index 5d1f60d43263b0a1440dd64147ff68e2e7875265..51603170a6041e127e56b22a8cdf3224a0d5551d 100644 (file)
@@ -65,7 +65,7 @@ func (check *Checker) instantiateSignature(pos token.Pos, typ *Signature, targs
        assert(len(targs) == typ.TypeParams().Len())
 
        if trace {
-               check.trace(pos, "-- instantiating %s with %s", typ, targs)
+               check.trace(pos, "-- instantiating signature %s with %s", typ, targs)
                check.indent++
                defer func() {
                        check.indent--
@@ -89,7 +89,7 @@ func (check *Checker) instantiateSignature(pos token.Pos, typ *Signature, targs
                } else {
                        check.mono.recordInstance(check.pkg, pos, tparams, targs, xlist)
                }
-       })
+       }).describef(atPos(pos), "verify instantiation")
 
        return inst
 }
index 23136377c82dd36e59500f45c1f0c5c4db8305cf..d920d9c0804364c9ec000ada5c07e02f92ee4f69 100644 (file)
@@ -381,11 +381,17 @@ func (check *Checker) processDelayed(top int) {
        // this is a sufficiently bounded process.
        for i := top; i < len(check.delayed); i++ {
                a := &check.delayed[i]
-               if trace && a.desc != nil {
-                       fmt.Println()
-                       check.trace(a.desc.pos.Pos(), "-- "+a.desc.format, a.desc.args...)
+               if trace {
+                       if a.desc != nil {
+                               check.trace(a.desc.pos.Pos(), "-- "+a.desc.format, a.desc.args...)
+                       } else {
+                               check.trace(token.NoPos, "-- delayed %p", a.f)
+                       }
                }
                a.f() // may append to check.delayed
+               if trace {
+                       fmt.Println()
+               }
        }
        assert(top <= len(check.delayed)) // stack must not have shrunk
        check.delayed = check.delayed[:top]
index c3d43d93f6b10bed0c5677d89c6ed97b9f056942..a20b56c9502f6334ea476b3a1f37c5013302262f 100644 (file)
@@ -786,7 +786,7 @@ func (check *Checker) funcDecl(obj *Func, decl *declInfo) {
        if !check.conf.IgnoreFuncBodies && fdecl.Body != nil {
                check.later(func() {
                        check.funcBody(decl, obj.name, sig, fdecl.Body, nil)
-               })
+               }).describef(obj, "func %s", obj.name)
        }
 }
 
index 596bcef9c1401caf8defe7ad55123ccdb08e2e4c..160dcc35d01b2583112824548b4774406cb3bda6 100644 (file)
@@ -1197,7 +1197,7 @@ const (
 //
 func (check *Checker) rawExpr(x *operand, e ast.Expr, hint Type, allowGeneric bool) exprKind {
        if trace {
-               check.trace(e.Pos(), "expr %s", e)
+               check.trace(e.Pos(), "-- expr %s", e)
                check.indent++
                defer func() {
                        check.indent--
@@ -1305,7 +1305,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
                                // but before the enclosing scope contents changes (#22992).
                                check.later(func() {
                                        check.funcBody(decl, "<function literal>", sig, e.Body, iota)
-                               })
+                               }).describef(e, "func literal")
                        }
                        x.mode = value
                        x.typ = sig
index a48174665739f8206504b17a8e93024c708be83e..d7045ff23c0fef11decc8aca46034f1ec52726e6 100644 (file)
@@ -61,7 +61,7 @@ func Instantiate(ctxt *Context, orig Type, targs []Type, validate bool) (Type, e
 
 // instance creates a type or function instance using the given original type
 // typ and arguments targs. For Named types the resulting instance will be
-// unexpanded.
+// unexpanded. check may be nil.
 func (check *Checker) instance(pos token.Pos, orig Type, targs []Type, ctxt *Context) (res Type) {
        var h string
        if ctxt != nil {
@@ -103,6 +103,7 @@ func (check *Checker) instance(pos token.Pos, orig Type, targs []Type, ctxt *Con
                // anymore; we need to set tparams to nil.
                sig.tparams = nil
                res = sig
+
        default:
                // only types and functions can be generic
                panic(fmt.Sprintf("%v: cannot instantiate %v", pos, orig))
index 876f7e8551fbf3e4e035b2ae3f3dc05364ace1f1..b8760efc5e0c84129041959ee6b8dc336c28d256 100644 (file)
@@ -356,11 +356,19 @@ func (check *Checker) bestContext(ctxt *Context) *Context {
 // expandNamed ensures that the underlying type of n is instantiated.
 // The underlying type will be Typ[Invalid] if there was an error.
 func expandNamed(ctxt *Context, n *Named, instPos token.Pos) (tparams *TypeParamList, underlying Type, methods *methodList) {
+       check := n.check
+       if check != nil && trace {
+               check.trace(instPos, "-- expandNamed %s", n)
+               check.indent++
+               defer func() {
+                       check.indent--
+                       check.trace(instPos, "=> %s (tparams = %s, under = %s)", n, tparams.list(), underlying)
+               }()
+       }
+
        n.orig.resolve(ctxt)
        assert(n.orig.underlying != nil)
 
-       check := n.check
-
        if _, unexpanded := n.orig.underlying.(*Named); unexpanded {
                // We should only get an unexpanded underlying here during type checking
                // (for example, in recursive type declarations).
index 2aa65a6e36eea15ea22a5f001ee9449c631ea1f8..d7f6a486ca95371512d56dca8b0400145dc2aca0 100644 (file)
@@ -19,10 +19,7 @@ func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body
        }
 
        if trace {
-               check.trace(body.Pos(), "--- %s: %s", name, sig)
-               defer func() {
-                       check.trace(body.End(), "--- <end>")
-               }()
+               check.trace(body.Pos(), "-- %s: %s", name, sig)
        }
 
        // set function scope extent
index b33141ec3270390081ecf56b731e3f949ca24aa3..08ff191f2e3f404810c0c9ba1c7aafbcb280c4e8 100644 (file)
@@ -177,7 +177,7 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T
                        pos = ityp.methods[0].pos
                }
 
-               check.trace(pos, "type set for %s", ityp)
+               check.trace(pos, "-- type set for %s", ityp)
                check.indent++
                defer func() {
                        check.indent--
@@ -248,7 +248,7 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T
                                        check.errorf(atPos(pos), _DuplicateDecl, "duplicate method %s", m.name)
                                        check.errorf(atPos(mpos[other.(*Func)]), _DuplicateDecl, "\tother declaration of %s", m.name) // secondary error, \t indented
                                }
-                       })
+                       }).describef(atPos(pos), "duplicate method check for %s", m.name)
                }
        }
 
index d72b48185ad3ca774c038f8113eb44b6f18f6a0e..bae9dc816c7fe233e88c14ef5443f6c66cb10737 100644 (file)
@@ -170,7 +170,7 @@ func (check *Checker) validVarType(e ast.Expr, typ Type) {
                                }
                        }
                }
-       })
+       }).describef(e, "check var type %s", typ)
 }
 
 // definedType is like typ but also accepts a type name def.
@@ -353,7 +353,7 @@ func (check *Checker) typInternal(e0 ast.Expr, def *Named) (T Type) {
                                }
                                check.errorf(e.Key, _IncomparableMapKey, "incomparable map key type %s%s", typ.key, why)
                        }
-               })
+               }).describef(e.Key, "check map key %s", typ.key)
 
                return typ
 
@@ -390,7 +390,7 @@ func (check *Checker) typInternal(e0 ast.Expr, def *Named) (T Type) {
 func (check *Checker) instantiatedType(ix *typeparams.IndexExpr, def *Named) (res Type) {
        pos := ix.X.Pos()
        if trace {
-               check.trace(pos, "-- instantiating %s with %s", ix.X, ix.Indices)
+               check.trace(pos, "-- instantiating type %s with %s", ix.X, ix.Indices)
                check.indent++
                defer func() {
                        check.indent--
@@ -483,7 +483,7 @@ func (check *Checker) instantiatedType(ix *typeparams.IndexExpr, def *Named) (re
                }
 
                check.validType(inst)
-       })
+       }).describef(ix, "resolve instance %s", inst)
 
        return inst
 }
index 8397d65af0113e93b9dc76bafb77169b76c5af03..1a8825fcab0928d4d0e746d1423c060a0bfb1fd1 100644 (file)
@@ -132,7 +132,7 @@ func parseUnion(check *Checker, uexpr ast.Expr) Type {
                                check.softErrorf(tlist[i], _InvalidUnion, "overlapping terms %s and %s", t, terms[j])
                        }
                }
-       })
+       }).describef(uexpr, "check term validity %s", uexpr)
 
        return u
 }