]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: always rename type parameters during inference
authorRobert Findley <rfindley@google.com>
Thu, 8 Dec 2022 15:03:03 +0000 (10:03 -0500)
committerRobert Findley <rfindley@google.com>
Thu, 8 Dec 2022 23:06:18 +0000 (23:06 +0000)
commite738a2f19b0375662abc8a9f293b003b6a46019b
tree495c953f2b80dc07fdaac363aef3cb89f9400af8
parent8247b9f17aa28bbd9382b8204b9befa8ceb875e8
go/types, types2: always rename type parameters during inference

Type inference uses a trick of "renaming" type parameters in the type
parameter list to avoid cycles during unification. This separates the
identity of type parameters from type arguments. When this trick was
introduced in CL 385494, we restricted its application to scenarios
where inference is truly self-recursive: the type parameter list being
inferred was the same as the type parameter list of the outer function
declaration. Unfortunately, the heuristic used to determine
self-recursiveness was flawed: type-checking function literals clobbers
the type-checker environment, losing information about the outer
signature.

We could fix this by introducing yet more state into the type-checker
(e.g. a 'declSig' field that would hold the signature of the active
function declaration), but it is simpler to just avoid this optimization
and always perform type parameter renaming. We can always optimize
later.

This CL removes the check for true self-recursion, always performing the
renaming.

Fixes golang/go#57155

Change-Id: I34c7617005c1f0ccfe2192da0e5ed104be6b92c9
Reviewed-on: https://go-review.googlesource.com/c/go/+/456236
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/compile/internal/types2/infer.go
src/go/types/infer.go
src/internal/types/testdata/fixedbugs/issue57155.go [new file with mode: 0644]