-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: use new type inference algorithm exclusively
The primary change is that type inference now always reports an error if a unification step fails (rather than ignoring that case, see infer2.go). This brings the implementation closely to the description in #58650; but the implementation is more direct by always maintaining a simple (type parameter => type) mapping. To make this work, there are two small but subtle changes in the unifier: 1) When deciding whether to proceed with the underlying type of a defined type, we also use the underlying type if the other type is a basic type (switch from !hasName(x) to isTypeLit(x) in unifier.go). This makes the case in issue #53650 work out. See the comment in the code for a detailed explanation of this change. 2) When we unify against an unbound type parameter, we always proceed with its core type (if any). Again, see the comment in the code for a detailed explanation of this change. The remaining changes are comment and test adjustments. Because the new logic now results in failing type inference where it succeeded before or vice versa, and then instatiation or parameter passing failed, a handful of error messages changed. As desired, we still have the same number of errors for the same programs. Also, because type inference now produces different results, we cannot easily compare against infer1 anymore (also infer1 won't work correctly anymore due to the changes in the unifier). This comparison (together with infer1) is now disabled. Because some errors and their positions have changed, we need a slightly larger error position tolerance for types2 (which produces less accurate error positions than go/types). Hence the change in types2/check_test.go. Finally, because type inference is now slightly more relaxed, issue #51139 doesn't produce a type unification failure anymore for a (previously correctly) inferred type argument. Fixes #51139. Change-Id: Id796eea42f1b706a248843ad855d9d429d077bd1 Reviewed-on: https://go-review.googlesource.com/c/go/+/470916 Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
- Loading branch information
Showing
11 changed files
with
192 additions
and
98 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.