]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: add additional tracing output in type inference
authorRobert Griesemer <gri@golang.org>
Thu, 3 Oct 2024 19:29:40 +0000 (12:29 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 3 Oct 2024 22:23:53 +0000 (22:23 +0000)
To support analyzing type inference failures.

Change-Id: I47882f6b634d5fcf1834923ec372313323d31a9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/617895
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

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

index 45ff6233ca9091226b9e58abb5e336be1e20fbea..025b64d9fc26b0683f2de1620f8f86ac49522af6 100644 (file)
@@ -242,6 +242,9 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
                                // A type parameter can be unified with its core type in two cases.
                                switch {
                                case tx != nil:
+                                       if traceInference {
+                                               u.tracef("-> unify type parameter %s (type %s) with constraint core type %s", tpar, tx, core.typ)
+                                       }
                                        // The corresponding type argument tx is known. There are 2 cases:
                                        // 1) If the core type has a tilde, per spec requirement for tilde
                                        //    elements, the core type is an underlying (literal) type.
@@ -260,6 +263,9 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
                                                return nil
                                        }
                                case single && !core.tilde:
+                                       if traceInference {
+                                               u.tracef("-> set type parameter %s to constraint core type %s", tpar, core.typ)
+                                       }
                                        // The corresponding type argument tx is unknown and there's a single
                                        // specific type and no tilde.
                                        // In this case the type argument must be that single type; set it.
@@ -267,6 +273,9 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
                                }
                        } else {
                                if tx != nil {
+                                       if traceInference {
+                                               u.tracef("-> unify type parameter %s (type %s) methods with constraint methods", tpar, tx)
+                                       }
                                        // 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,
                                        // and the method signatures must unify; otherwise tx cannot satisfy
index 9a64bd0a7170b9ca47a47645dfc141574f001d8a..b0094a6991012fff7059dfb47e0a764c8c99ba54 100644 (file)
@@ -245,6 +245,9 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
                                // A type parameter can be unified with its core type in two cases.
                                switch {
                                case tx != nil:
+                                       if traceInference {
+                                               u.tracef("-> unify type parameter %s (type %s) with constraint core type %s", tpar, tx, core.typ)
+                                       }
                                        // The corresponding type argument tx is known. There are 2 cases:
                                        // 1) If the core type has a tilde, per spec requirement for tilde
                                        //    elements, the core type is an underlying (literal) type.
@@ -263,6 +266,9 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
                                                return nil
                                        }
                                case single && !core.tilde:
+                                       if traceInference {
+                                               u.tracef("-> set type parameter %s to constraint core type %s", tpar, core.typ)
+                                       }
                                        // The corresponding type argument tx is unknown and there's a single
                                        // specific type and no tilde.
                                        // In this case the type argument must be that single type; set it.
@@ -270,6 +276,9 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
                                }
                        } else {
                                if tx != nil {
+                                       if traceInference {
+                                               u.tracef("-> unify type parameter %s (type %s) methods with constraint methods", tpar, tx)
+                                       }
                                        // 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,
                                        // and the method signatures must unify; otherwise tx cannot satisfy