]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: remove Config.EnableReverseTypeInference flag
authorRobert Griesemer <gri@golang.org>
Thu, 4 May 2023 05:05:27 +0000 (22:05 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 4 May 2023 17:35:44 +0000 (17:35 +0000)
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>

22 files changed:
src/cmd/compile/internal/noder/irgen.go
src/cmd/compile/internal/types2/api.go
src/cmd/compile/internal/types2/api_test.go
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/check_test.go
src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/infer.go
src/cmd/compile/internal/types2/stdlib_test.go
src/go/types/api.go
src/go/types/api_test.go
src/go/types/call.go
src/go/types/check_test.go
src/go/types/expr.go
src/go/types/infer.go
src/go/types/stdlib_test.go
src/internal/types/testdata/examples/inference.go
src/internal/types/testdata/examples/inference2.go
src/internal/types/testdata/fixedbugs/issue59338a.go
src/internal/types/testdata/fixedbugs/issue59338b.go
src/internal/types/testdata/fixedbugs/issue59639.go
src/internal/types/testdata/fixedbugs/issue59953.go
src/internal/types/testdata/fixedbugs/issue59956.go

index 8f31687e9ff6a55b03c17935862c660e73aa243e..3adf9e5d11d82bd4278d8c5d8ea4a2eb2e99dbd1 100644 (file)
@@ -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,
index 0ee9a4bd06c62e0c398b616df8ff62d66c757296..b798f2c888e8f31ad30dc28a5bb5e0349659b001 100644 (file)
@@ -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) {
index 8a11dd9a49177054aac22c33ee157b79eb2589cf..3fa8782930e8c66adc116bd16fd693795cda36ce 100644 (file)
@@ -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 {
index bd8ca953ef47421e7c191dbe39deda6c2182310a..ac5efad93d255b81afa56edf906639b1d56fe1a4 100644 (file)
@@ -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 {
index 382d1ad19e66af8a3418b845c77d0ac3963dbcc0..26bb1aed9e6e8c5eaed271fbc6af2336a1dce87e 100644 (file)
@@ -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)
        }
index 295c497054b0a8de8102a4679c1226f71e8ac3b3..19e3b9bc98c6b54d39fd698cc1b6427226d27d8b 100644 (file)
@@ -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)
index 1028924c3234db16f7c7bfc50813228f464a8019..ce6bb91e9623eba80f54c9a11dab2d5790d67f75 100644 (file)
@@ -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
index d9db545dc669e4de7e9efe185949a9d4fef2c864..404e1636aec480bf9f97607903fb441c58beefde 100644 (file)
@@ -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)
index e202d6dea8eea26780f97c7b49ca99cbcb41620f..05773d134a703880f53a206d66736b4775389e97 100644 (file)
@@ -170,13 +170,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) {
index 8f9ef023892679f86a5d43b929a6d1fad0666043..86ed4b1165924bab87aa75800f8b243194e3462d 100644 (file)
@@ -594,12 +594,7 @@ type T[P any] []P
 
        for _, test := range tests {
                imports := make(testImporter)
-               conf := Config{
-                       Importer: imports,
-                       // Unexported field: set below with boolFieldAddr
-                       // _EnableReverseTypeInference: true,
-               }
-               *boolFieldAddr(&conf, "_EnableReverseTypeInference") = true
+               conf := Config{Importer: imports}
                instMap := make(map[*ast.Ident]Instance)
                useMap := make(map[*ast.Ident]Object)
                makePkg := func(src string) *Package {
index 6e94156d3e04d23dd3c4d7772d5ff4bfac0ee3ec..4ee84c2f73f2d8113a6e4f620a67bc158619a8c5 100644 (file)
@@ -499,7 +499,7 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
 
        // 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 {
index cda052f4d39de929a0432d167ffa0835f211a7d7..d53aaeadc5e4dc547ec41048cd3bf88f5126239c 100644 (file)
@@ -146,7 +146,6 @@ func testFiles(t *testing.T, sizes Sizes, filenames []string, srcs [][]byte, man
        flags := flag.NewFlagSet("", flag.PanicOnError)
        flags.StringVar(&conf.GoVersion, "lang", "", "")
        flags.BoolVar(&conf.FakeImportC, "fakeImportC", false, "")
-       flags.BoolVar(boolFieldAddr(&conf, "_EnableReverseTypeInference"), "reverseTypeInference", false, "")
        if err := parseFlags(filenames[0], srcs[0], flags); err != nil {
                t.Fatal(err)
        }
index 0e4e6667d8063568598d24631d8763b2fd9c887c..27f3c45ac62225f1e8ce0a2ba635c2d96a5290c4 100644 (file)
@@ -1276,7 +1276,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
@@ -1600,7 +1600,7 @@ func (check *Checker) exprInternal(T Type, x *operand, e ast.Expr, hint Type) ex
                ix := typeparams.UnpackIndexExpr(e)
                if check.indexExpr(x, ix) {
                        var tsig *Signature
-                       if check.conf._EnableReverseTypeInference && T != nil {
+                       if enableReverseTypeInference && T != nil {
                                tsig, _ = under(T).(*Signature)
                        }
                        check.funcInst(tsig, e.Pos(), x, ix)
index 3db10e0010656f2745057aa6977276db8398a37e..9810c95c9b3e17795b0d9db8d979c851a8800e22 100644 (file)
@@ -15,6 +15,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
index 88338cc2bdacbc216134206915a1139f3affc66a..82f22de8362d7d0b23c69ba9847a2def2be6d379 100644 (file)
@@ -143,7 +143,6 @@ func testTestDir(t *testing.T, path string, ignore ...string) {
                                GoVersion: goVersion,
                                Importer:  stdLibImporter,
                        }
-                       *boolFieldAddr(&conf, "_EnableReverseTypeInference") = true
                        _, err = conf.Check(filename, fset, []*ast.File{file}, nil)
                }
 
@@ -271,7 +270,6 @@ func typecheckFiles(t *testing.T, path string, filenames []string) {
                },
                Importer: stdLibImporter,
        }
-       *boolFieldAddr(&conf, "_EnableReverseTypeInference") = true
        info := Info{Uses: make(map[*ast.Ident]Object)}
        conf.Check(path, fset, files, &info)
 
index 2dc122c41368a7f5e2a04acf87569f59cff3b5ea..b6f735263e89b7d6b548451bfaf5af2a09e60e37 100644 (file)
@@ -1,3 +1,5 @@
+// -lang=go1.20
+
 // Copyright 2021 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.
@@ -154,4 +156,4 @@ func _() {
 func f[P any](P) {}
 
 // This must not crash.
-var _ func(int) = f // ERROR "cannot use generic function f without instantiation"
+var _ func(int) = f // ERROR "implicitly instantiated function in assignment requires go1.21 or later"
index 7b86266d5ee03e5b1f028baed29fa108ac6dbd00..4eeb6d1b0593179314b46436b815e8be63bce203 100644 (file)
@@ -1,5 +1,3 @@
-// -reverseTypeInference
-
 // Copyright 2023 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.
index f927813e102ddba784239463d4c600c519f85c38..34864dcd30bbcd718375e5da99fcfb8fdc68fc20 100644 (file)
@@ -1,4 +1,4 @@
-// -reverseTypeInference -lang=go1.20
+// -lang=go1.20
 
 // Copyright 2023 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index ea321bcd17dd227f8c4ee5d5716d098355053aab..1a5530aeaefd5bda5741313552acd1bd631ad408 100644 (file)
@@ -1,5 +1,3 @@
-// -reverseTypeInference
-
 // Copyright 2023 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.
index c82d5b10fa4eb28cf301b60238d483f88c9d9001..1117668e98852c90e895cde7bed499b15590dc8f 100644 (file)
@@ -1,4 +1,4 @@
-// -reverseTypeInference -lang=go1.17
+// -lang=go1.17
 
 // Copyright 2023 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index 40d97378a21af52182d7ebd915265ea6de2b3f7d..b10ced749b4a6a580ee925dfc7d6aa73921bcfd4 100644 (file)
@@ -1,5 +1,3 @@
-// -reverseTypeInference
-
 // Copyright 2023 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.
index 33b05d72c125816fd94b36de48361d66e35d2d99..646b50e7716e7b06689cb3bd4a91d729d97def6e 100644 (file)
@@ -1,5 +1,3 @@
-// -reverseTypeInference
-
 // Copyright 2023 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.