Skip to content

Commit ee361ce

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: more readable inference trace
Print the unification mode in human-readable form. Use a tab and // instead of ()'s to show unification mode and whether operands where swapped. These changes only affect inference trace output, which is disabled by default. For easier debugging. For #60933. Change-Id: I95299c6e09b90670fc45addc4f9196b6cdd3b59f Reviewed-on: https://go-review.googlesource.com/c/go/+/505395 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 9f6e87f commit ee361ce

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/cmd/compile/internal/types2/unify.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,20 @@ const (
124124
exact
125125
)
126126

127+
func (m unifyMode) String() string {
128+
switch m {
129+
case 0:
130+
return "inexact"
131+
case assign:
132+
return "assign"
133+
case exact:
134+
return "exact"
135+
case assign | exact:
136+
return "assign, exact"
137+
}
138+
return fmt.Sprintf("mode %d", m)
139+
}
140+
127141
// unify attempts to unify x and y and reports whether it succeeded.
128142
// As a side-effect, types may be inferred for type parameters.
129143
// The mode parameter controls how types are compared.
@@ -263,7 +277,7 @@ func (u *unifier) inferred(tparams []*TypeParam) []Type {
263277
func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
264278
u.depth++
265279
if traceInference {
266-
u.tracef("%s ≡ %s (mode %d)", x, y, mode)
280+
u.tracef("%s ≡ %s\t// %s", x, y, mode)
267281
}
268282
defer func() {
269283
if traceInference && !result {
@@ -294,7 +308,7 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
294308
// - type parameter recorded with u, make sure one is in x
295309
if _, ok := x.(*Named); ok || u.asTypeParam(y) != nil {
296310
if traceInference {
297-
u.tracef("%s ≡ %s (swap)", y, x)
311+
u.tracef("%s ≡ %s\t// swap", y, x)
298312
}
299313
x, y = y, x
300314
}
@@ -492,7 +506,7 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
492506
// TODO(gri) Factor out type parameter handling from the switch.
493507
if isTypeParam(y) {
494508
if traceInference {
495-
u.tracef("%s ≡ %s (swap)", y, x)
509+
u.tracef("%s ≡ %s\t// swap", y, x)
496510
}
497511
x, y = y, x
498512
}

src/go/types/unify.go

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)