aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2023-05-03 22:05:27 -0700
committerGopher Robot <gobot@golang.org>2023-05-04 17:35:44 +0000
commitfc106b016cc4ba5dc5a1a44eda7524fdce4463bb (patch)
tree6cdd94bda1231af741cda692507d1f832625fcbb /src/cmd
parent13201d57283e3684ab46ccb5ee0bb6b3fe67c221 (diff)
downloadgo-fc106b016cc4ba5dc5a1a44eda7524fdce4463bb.tar.xz
go/types, types2: remove Config.EnableReverseTypeInference flag
Proposal #59338 has been accepted and we expect this feature to be available starting with Go 1.21. Remove the flag to explicitly enable it through the API and enable by default. For now keep an internal constant enableReverseTypeInference to guard and mark the respective code, so we can disable it for debugging purposes. For #59338. Change-Id: Ia1bf3032483ae603017a0f459417ec73837e2891 Reviewed-on: https://go-review.googlesource.com/c/go/+/491798 Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compile/internal/noder/irgen.go5
-rw-r--r--src/cmd/compile/internal/types2/api.go7
-rw-r--r--src/cmd/compile/internal/types2/api_test.go5
-rw-r--r--src/cmd/compile/internal/types2/call.go2
-rw-r--r--src/cmd/compile/internal/types2/check_test.go1
-rw-r--r--src/cmd/compile/internal/types2/expr.go4
-rw-r--r--src/cmd/compile/internal/types2/infer.go7
-rw-r--r--src/cmd/compile/internal/types2/stdlib_test.go10
8 files changed, 17 insertions, 24 deletions
diff --git a/src/cmd/compile/internal/noder/irgen.go b/src/cmd/compile/internal/noder/irgen.go
index 8f31687e9f..3adf9e5d11 100644
--- a/src/cmd/compile/internal/noder/irgen.go
+++ b/src/cmd/compile/internal/noder/irgen.go
@@ -50,9 +50,8 @@ func checkFiles(m posMap, noders []*noder) (*types2.Package, *types2.Info) {
}
base.ErrorfAt(m.makeXPos(terr.Pos), terr.Code, "%s", msg)
},
- Importer: &importer,
- Sizes: &gcSizes{},
- EnableReverseTypeInference: true,
+ Importer: &importer,
+ Sizes: &gcSizes{},
}
info := &types2.Info{
StoreTypesInSyntax: true,
diff --git a/src/cmd/compile/internal/types2/api.go b/src/cmd/compile/internal/types2/api.go
index 0ee9a4bd06..b798f2c888 100644
--- a/src/cmd/compile/internal/types2/api.go
+++ b/src/cmd/compile/internal/types2/api.go
@@ -169,13 +169,6 @@ type Config struct {
// If DisableUnusedImportCheck is set, packages are not checked
// for unused imports.
DisableUnusedImportCheck bool
-
- // If EnableReverseTypeInference is set, uninstantiated and
- // partially instantiated generic functions may be assigned
- // (incl. returned) to variables of function type and type
- // inference will attempt to infer the missing type arguments.
- // See proposal go.dev/issue/59338.
- EnableReverseTypeInference bool
}
func srcimporter_setUsesCgo(conf *Config) {
diff --git a/src/cmd/compile/internal/types2/api_test.go b/src/cmd/compile/internal/types2/api_test.go
index 8a11dd9a49..3fa8782930 100644
--- a/src/cmd/compile/internal/types2/api_test.go
+++ b/src/cmd/compile/internal/types2/api_test.go
@@ -594,10 +594,7 @@ type T[P any] []P
for _, test := range tests {
imports := make(testImporter)
- conf := Config{
- Importer: imports,
- EnableReverseTypeInference: true,
- }
+ conf := Config{Importer: imports}
instMap := make(map[*syntax.Name]Instance)
useMap := make(map[*syntax.Name]Object)
makePkg := func(src string) *Package {
diff --git a/src/cmd/compile/internal/types2/call.go b/src/cmd/compile/internal/types2/call.go
index bd8ca953ef..ac5efad93d 100644
--- a/src/cmd/compile/internal/types2/call.go
+++ b/src/cmd/compile/internal/types2/call.go
@@ -496,7 +496,7 @@ func (check *Checker) arguments(call *syntax.CallExpr, sig *Signature, targs []T
// collect type parameters from generic function arguments
var genericArgs []int // indices of generic function arguments
- if check.conf.EnableReverseTypeInference {
+ if enableReverseTypeInference {
for i, arg := range args {
// generic arguments cannot have a defined (*Named) type - no need for underlying type below
if asig, _ := arg.typ.(*Signature); asig != nil && asig.TypeParams().Len() > 0 {
diff --git a/src/cmd/compile/internal/types2/check_test.go b/src/cmd/compile/internal/types2/check_test.go
index 382d1ad19e..26bb1aed9e 100644
--- a/src/cmd/compile/internal/types2/check_test.go
+++ b/src/cmd/compile/internal/types2/check_test.go
@@ -133,7 +133,6 @@ func testFiles(t *testing.T, filenames []string, colDelta uint, manual bool) {
flags := flag.NewFlagSet("", flag.PanicOnError)
flags.StringVar(&conf.GoVersion, "lang", "", "")
flags.BoolVar(&conf.FakeImportC, "fakeImportC", false, "")
- flags.BoolVar(&conf.EnableReverseTypeInference, "reverseTypeInference", false, "")
if err := parseFlags(filenames[0], nil, flags); err != nil {
t.Fatal(err)
}
diff --git a/src/cmd/compile/internal/types2/expr.go b/src/cmd/compile/internal/types2/expr.go
index 295c497054..19e3b9bc98 100644
--- a/src/cmd/compile/internal/types2/expr.go
+++ b/src/cmd/compile/internal/types2/expr.go
@@ -1291,7 +1291,7 @@ func (check *Checker) nonGeneric(T Type, x *operand) {
}
case *Signature:
if t.tparams != nil {
- if check.conf.EnableReverseTypeInference && T != nil {
+ if enableReverseTypeInference && T != nil {
if tsig, _ := under(T).(*Signature); tsig != nil {
check.funcInst(tsig, x.Pos(), x, nil)
return
@@ -1617,7 +1617,7 @@ func (check *Checker) exprInternal(T Type, x *operand, e syntax.Expr, hint Type)
case *syntax.IndexExpr:
if check.indexExpr(x, e) {
var tsig *Signature
- if check.conf.EnableReverseTypeInference && T != nil {
+ if enableReverseTypeInference && T != nil {
tsig, _ = under(T).(*Signature)
}
check.funcInst(tsig, e.Pos(), x, e)
diff --git a/src/cmd/compile/internal/types2/infer.go b/src/cmd/compile/internal/types2/infer.go
index 1028924c32..ce6bb91e96 100644
--- a/src/cmd/compile/internal/types2/infer.go
+++ b/src/cmd/compile/internal/types2/infer.go
@@ -13,6 +13,13 @@ import (
"strings"
)
+// If enableReverseTypeInference is set, uninstantiated and
+// partially instantiated generic functions may be assigned
+// (incl. returned) to variables of function type and type
+// inference will attempt to infer the missing type arguments.
+// Available with go1.21.
+const enableReverseTypeInference = true // disable for debugging
+
// infer attempts to infer the complete set of type arguments for generic function instantiation/call
// based on the given type parameters tparams, type arguments targs, function parameters params, and
// function arguments args, if any. There must be at least one type parameter, no more type arguments
diff --git a/src/cmd/compile/internal/types2/stdlib_test.go b/src/cmd/compile/internal/types2/stdlib_test.go
index d9db545dc6..404e1636ae 100644
--- a/src/cmd/compile/internal/types2/stdlib_test.go
+++ b/src/cmd/compile/internal/types2/stdlib_test.go
@@ -139,9 +139,8 @@ func testTestDir(t *testing.T, path string, ignore ...string) {
file, err := syntax.ParseFile(filename, nil, nil, 0)
if err == nil {
conf := Config{
- GoVersion: goVersion,
- Importer: stdLibImporter,
- EnableReverseTypeInference: true,
+ GoVersion: goVersion,
+ Importer: stdLibImporter,
}
_, err = conf.Check(filename, []*syntax.File{file}, nil)
}
@@ -254,9 +253,8 @@ func typecheckFiles(t *testing.T, path string, filenames []string) {
// typecheck package files
conf := Config{
- Error: func(err error) { t.Error(err) },
- Importer: stdLibImporter,
- EnableReverseTypeInference: true,
+ Error: func(err error) { t.Error(err) },
+ Importer: stdLibImporter,
}
info := Info{Uses: make(map[*syntax.Name]Object)}
conf.Check(path, files, &info)