Skip to content

Commit

Permalink
go/types: report object path in trace mode
Browse files Browse the repository at this point in the history
For debugging only; disabled (dead code) by default
unless internal constant trace flag is set to true.

For #8699.

Change-Id: Ib7b272c6ac8efacccbbbe24650ef500c5a9ddcf5
Reviewed-on: https://go-review.googlesource.com/115457
Reviewed-by: Alan Donovan <[email protected]>
  • Loading branch information
griesemer committed May 31, 2018
1 parent 6dbaf03 commit e4259d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/go/types/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ func (check *Checker) pop() Object {
return obj
}

// pathString returns a string of the form a->b-> ... ->g for an object path [a, b, ... g].
func (check *Checker) pathString() string {
var s string
for i, p := range check.objPath {
if i > 0 {
s += "->"
}
s += p.Name()
}
return s
}

// NewChecker returns a new Checker instance for a given package.
// Package files may be added incrementally via checker.Files.
func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Checker {
Expand Down
4 changes: 2 additions & 2 deletions src/go/types/decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) {
}

if trace {
check.trace(obj.Pos(), "-- checking %s (path = %s)", obj, pathString(path))
check.trace(obj.Pos(), "-- checking %s (path = %s, objPath = %s)", obj, pathString(path), check.pathString())
check.indent++
defer func() {
check.indent--
Expand Down Expand Up @@ -208,7 +208,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) {
// to the next. For instance, for "type p *p" the object path contains
// p followed by indir, indicating that there's an indirection *p.
// Indirections are used to break type cycles.
var indir = new(TypeName)
var indir = NewTypeName(token.NoPos, nil, "*", nil)

// typeCycle checks if the cycle starting with obj is valid and
// reports an error if it is not.
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (check *Checker) infoFromTypeLit(scope *Scope, iface *ast.InterfaceType, tn
}

if trace {
check.trace(iface.Pos(), "-- collect methods for %v (path = %s)", iface, pathString(path))
check.trace(iface.Pos(), "-- collect methods for %v (path = %s, objPath = %s)", iface, pathString(path), check.pathString())
check.indent++
defer func() {
check.indent--
Expand Down

0 comments on commit e4259d6

Please sign in to comment.