-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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#57155 Change-Id: I34c7617005c1f0ccfe2192da0e5ed104be6b92c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/456236 Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
- Loading branch information
Showing
3 changed files
with
42 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package p | ||
|
||
func f[P *Q, Q any](p P, q Q) { | ||
func() { | ||
_ = f[P] | ||
f(p, q) | ||
f[P](p, q) | ||
f[P, Q](p, q) | ||
}() | ||
} |