mirror of https://github.com/golang/go.git
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 <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
parent
74a9d283e4
commit
c80b9912e6
|
|
@ -30,7 +30,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
|
||||||
}
|
}
|
||||||
|
|
||||||
if traceInference {
|
if traceInference {
|
||||||
check.dump("-- infer %s%s ➞ %s", tparams, params, targs)
|
check.dump("== infer : %s%s ➞ %s", tparams, params, targs) // aligned with rename print below
|
||||||
defer func() {
|
defer func() {
|
||||||
check.dump("=> %s ➞ %s\n", tparams, inferred)
|
check.dump("=> %s ➞ %s\n", tparams, inferred)
|
||||||
}()
|
}()
|
||||||
|
|
@ -53,7 +53,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
|
||||||
tparams, params = check.renameTParams(pos, tparams, params)
|
tparams, params = check.renameTParams(pos, tparams, params)
|
||||||
|
|
||||||
if traceInference {
|
if traceInference {
|
||||||
check.dump("after rename: %s%s ➞ %s\n", tparams, params, targs)
|
check.dump("-- rename: %s%s ➞ %s\n", tparams, params, targs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we have a "full" list of type arguments, some of which may
|
// 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,
|
||||||
// use information from function arguments
|
// use information from function arguments
|
||||||
|
|
||||||
if traceInference {
|
if traceInference {
|
||||||
u.tracef("parameters: %s", params)
|
u.tracef("== function parameters: %s", params)
|
||||||
u.tracef("arguments : %s", args)
|
u.tracef("-- function arguments : %s", args)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, arg := range args {
|
for i, arg := range args {
|
||||||
|
|
@ -183,7 +183,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
|
||||||
// use information from type parameter constraints
|
// use information from type parameter constraints
|
||||||
|
|
||||||
if traceInference {
|
if traceInference {
|
||||||
u.tracef("type parameters: %s", tparams)
|
u.tracef("== type parameters: %s", tparams)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unify type parameters with their constraints as long
|
// Unify type parameters with their constraints as long
|
||||||
|
|
@ -201,21 +201,25 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
|
||||||
// here could handle the respective type parameters only,
|
// here could handle the respective type parameters only,
|
||||||
// but that will come at a cost of extra complexity which
|
// but that will come at a cost of extra complexity which
|
||||||
// may not be worth it.)
|
// may not be worth it.)
|
||||||
for {
|
for i := 0; ; i++ {
|
||||||
nn := u.unknowns()
|
nn := u.unknowns()
|
||||||
|
if traceInference {
|
||||||
|
if i > 0 {
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
u.tracef("-- iteration %d", i)
|
||||||
|
}
|
||||||
|
|
||||||
for _, tpar := range tparams {
|
for _, tpar := range tparams {
|
||||||
tx := u.at(tpar)
|
tx := u.at(tpar)
|
||||||
if traceInference && tx != nil {
|
core, single := coreTerm(tpar)
|
||||||
u.tracef("%s = %s", tpar, tx)
|
if traceInference {
|
||||||
|
u.tracef("-- type parameter %s = %s: core(%s) = %s, single = %v", tpar, tx, tpar, core, single)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is a core term (i.e., a core type with tilde information)
|
// If there is a core term (i.e., a core type with tilde information)
|
||||||
// unify the type parameter with the core type.
|
// unify the type parameter with the core type.
|
||||||
if core, single := coreTerm(tpar); core != nil {
|
if core != nil {
|
||||||
if traceInference {
|
|
||||||
u.tracef("core(%s) = %s (single = %v)", tpar, core, single)
|
|
||||||
}
|
|
||||||
// A type parameter can be unified with its core type in two cases.
|
// A type parameter can be unified with its core type in two cases.
|
||||||
switch {
|
switch {
|
||||||
case tx != nil:
|
case tx != nil:
|
||||||
|
|
@ -240,9 +244,6 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
|
||||||
u.set(tpar, core.typ)
|
u.set(tpar, core.typ)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if traceInference {
|
|
||||||
u.tracef("core(%s) = nil", tpar)
|
|
||||||
}
|
|
||||||
if tx != nil {
|
if tx != nil {
|
||||||
// We don't have a core type, but the type argument tx is known.
|
// We don't have a core type, but the type argument tx is known.
|
||||||
// It must have (at least) all the methods of the type constraint,
|
// 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,
|
||||||
// use information from untyped contants
|
// use information from untyped contants
|
||||||
|
|
||||||
if traceInference {
|
if traceInference {
|
||||||
u.tracef("untyped: %v", untyped)
|
u.tracef("== untyped arguments: %v", untyped)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some generic parameters with untyped arguments may have been given a type by now.
|
// Some generic parameters with untyped arguments may have been given a type by now.
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
|
||||||
}
|
}
|
||||||
|
|
||||||
if traceInference {
|
if traceInference {
|
||||||
check.dump("-- infer %s%s ➞ %s", tparams, params, targs)
|
check.dump("== infer : %s%s ➞ %s", tparams, params, targs) // aligned with rename print below
|
||||||
defer func() {
|
defer func() {
|
||||||
check.dump("=> %s ➞ %s\n", tparams, inferred)
|
check.dump("=> %s ➞ %s\n", tparams, inferred)
|
||||||
}()
|
}()
|
||||||
|
|
@ -55,7 +55,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
|
||||||
tparams, params = check.renameTParams(posn.Pos(), tparams, params)
|
tparams, params = check.renameTParams(posn.Pos(), tparams, params)
|
||||||
|
|
||||||
if traceInference {
|
if traceInference {
|
||||||
check.dump("after rename: %s%s ➞ %s\n", tparams, params, targs)
|
check.dump("-- rename: %s%s ➞ %s\n", tparams, params, targs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we have a "full" list of type arguments, some of which may
|
// Make sure we have a "full" list of type arguments, some of which may
|
||||||
|
|
@ -144,8 +144,8 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
|
||||||
// use information from function arguments
|
// use information from function arguments
|
||||||
|
|
||||||
if traceInference {
|
if traceInference {
|
||||||
u.tracef("parameters: %s", params)
|
u.tracef("== function parameters: %s", params)
|
||||||
u.tracef("arguments : %s", args)
|
u.tracef("-- function arguments : %s", args)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, arg := range args {
|
for i, arg := range args {
|
||||||
|
|
@ -185,7 +185,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
|
||||||
// use information from type parameter constraints
|
// use information from type parameter constraints
|
||||||
|
|
||||||
if traceInference {
|
if traceInference {
|
||||||
u.tracef("type parameters: %s", tparams)
|
u.tracef("== type parameters: %s", tparams)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unify type parameters with their constraints as long
|
// Unify type parameters with their constraints as long
|
||||||
|
|
@ -203,21 +203,25 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
|
||||||
// here could handle the respective type parameters only,
|
// here could handle the respective type parameters only,
|
||||||
// but that will come at a cost of extra complexity which
|
// but that will come at a cost of extra complexity which
|
||||||
// may not be worth it.)
|
// may not be worth it.)
|
||||||
for {
|
for i := 0; ; i++ {
|
||||||
nn := u.unknowns()
|
nn := u.unknowns()
|
||||||
|
if traceInference {
|
||||||
|
if i > 0 {
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
u.tracef("-- iteration %d", i)
|
||||||
|
}
|
||||||
|
|
||||||
for _, tpar := range tparams {
|
for _, tpar := range tparams {
|
||||||
tx := u.at(tpar)
|
tx := u.at(tpar)
|
||||||
if traceInference && tx != nil {
|
core, single := coreTerm(tpar)
|
||||||
u.tracef("%s = %s", tpar, tx)
|
if traceInference {
|
||||||
|
u.tracef("-- type parameter %s = %s: core(%s) = %s, single = %v", tpar, tx, tpar, core, single)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is a core term (i.e., a core type with tilde information)
|
// If there is a core term (i.e., a core type with tilde information)
|
||||||
// unify the type parameter with the core type.
|
// unify the type parameter with the core type.
|
||||||
if core, single := coreTerm(tpar); core != nil {
|
if core != nil {
|
||||||
if traceInference {
|
|
||||||
u.tracef("core(%s) = %s (single = %v)", tpar, core, single)
|
|
||||||
}
|
|
||||||
// A type parameter can be unified with its core type in two cases.
|
// A type parameter can be unified with its core type in two cases.
|
||||||
switch {
|
switch {
|
||||||
case tx != nil:
|
case tx != nil:
|
||||||
|
|
@ -242,9 +246,6 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
|
||||||
u.set(tpar, core.typ)
|
u.set(tpar, core.typ)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if traceInference {
|
|
||||||
u.tracef("core(%s) = nil", tpar)
|
|
||||||
}
|
|
||||||
if tx != nil {
|
if tx != nil {
|
||||||
// We don't have a core type, but the type argument tx is known.
|
// We don't have a core type, but the type argument tx is known.
|
||||||
// It must have (at least) all the methods of the type constraint,
|
// It must have (at least) all the methods of the type constraint,
|
||||||
|
|
@ -274,7 +275,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
|
||||||
// use information from untyped contants
|
// use information from untyped contants
|
||||||
|
|
||||||
if traceInference {
|
if traceInference {
|
||||||
u.tracef("untyped: %v", untyped)
|
u.tracef("== untyped arguments: %v", untyped)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some generic parameters with untyped arguments may have been given a type by now.
|
// Some generic parameters with untyped arguments may have been given a type by now.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue