Skip to content

Commit c80b991

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: fine-tune inference tracing output (debugging support)
No changes to non-tracing related code. Change-Id: I3d004528281111a4479a02543a3e5443485182cf Reviewed-on: https://go-review.googlesource.com/c/go/+/474135 Reviewed-by: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Robert Griesemer <[email protected]>
1 parent 74a9d28 commit c80b991

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
3030
}
3131

3232
if traceInference {
33-
check.dump("-- infer %s%s ➞ %s", tparams, params, targs)
33+
check.dump("== infer : %s%s ➞ %s", tparams, params, targs) // aligned with rename print below
3434
defer func() {
3535
check.dump("=> %s ➞ %s\n", tparams, inferred)
3636
}()
@@ -53,7 +53,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
5353
tparams, params = check.renameTParams(pos, tparams, params)
5454

5555
if traceInference {
56-
check.dump("after rename: %s%s ➞ %s\n", tparams, params, targs)
56+
check.dump("-- rename: %s%s ➞ %s\n", tparams, params, targs)
5757
}
5858

5959
// Make sure we have a "full" list of type arguments, some of which may
@@ -142,8 +142,8 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
142142
// use information from function arguments
143143

144144
if traceInference {
145-
u.tracef("parameters: %s", params)
146-
u.tracef("arguments : %s", args)
145+
u.tracef("== function parameters: %s", params)
146+
u.tracef("-- function arguments : %s", args)
147147
}
148148

149149
for i, arg := range args {
@@ -183,7 +183,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
183183
// use information from type parameter constraints
184184

185185
if traceInference {
186-
u.tracef("type parameters: %s", tparams)
186+
u.tracef("== type parameters: %s", tparams)
187187
}
188188

189189
// Unify type parameters with their constraints as long
@@ -201,21 +201,25 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
201201
// here could handle the respective type parameters only,
202202
// but that will come at a cost of extra complexity which
203203
// may not be worth it.)
204-
for {
204+
for i := 0; ; i++ {
205205
nn := u.unknowns()
206+
if traceInference {
207+
if i > 0 {
208+
fmt.Println()
209+
}
210+
u.tracef("-- iteration %d", i)
211+
}
206212

207213
for _, tpar := range tparams {
208214
tx := u.at(tpar)
209-
if traceInference && tx != nil {
210-
u.tracef("%s = %s", tpar, tx)
215+
core, single := coreTerm(tpar)
216+
if traceInference {
217+
u.tracef("-- type parameter %s = %s: core(%s) = %s, single = %v", tpar, tx, tpar, core, single)
211218
}
212219

213220
// If there is a core term (i.e., a core type with tilde information)
214221
// unify the type parameter with the core type.
215-
if core, single := coreTerm(tpar); core != nil {
216-
if traceInference {
217-
u.tracef("core(%s) = %s (single = %v)", tpar, core, single)
218-
}
222+
if core != nil {
219223
// A type parameter can be unified with its core type in two cases.
220224
switch {
221225
case tx != nil:
@@ -240,9 +244,6 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
240244
u.set(tpar, core.typ)
241245
}
242246
} else {
243-
if traceInference {
244-
u.tracef("core(%s) = nil", tpar)
245-
}
246247
if tx != nil {
247248
// We don't have a core type, but the type argument tx is known.
248249
// It must have (at least) all the methods of the type constraint,
@@ -272,7 +273,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
272273
// use information from untyped contants
273274

274275
if traceInference {
275-
u.tracef("untyped: %v", untyped)
276+
u.tracef("== untyped arguments: %v", untyped)
276277
}
277278

278279
// Some generic parameters with untyped arguments may have been given a type by now.

src/go/types/infer.go

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

0 commit comments

Comments
 (0)