Skip to content

Commit fc106b0

Browse files
griesemergopherbot
authored andcommitted
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>
1 parent 13201d5 commit fc106b0

File tree

22 files changed

+33
-54
lines changed

22 files changed

+33
-54
lines changed

src/cmd/compile/internal/noder/irgen.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ func checkFiles(m posMap, noders []*noder) (*types2.Package, *types2.Info) {
5050
}
5151
base.ErrorfAt(m.makeXPos(terr.Pos), terr.Code, "%s", msg)
5252
},
53-
Importer: &importer,
54-
Sizes: &gcSizes{},
55-
EnableReverseTypeInference: true,
53+
Importer: &importer,
54+
Sizes: &gcSizes{},
5655
}
5756
info := &types2.Info{
5857
StoreTypesInSyntax: true,

src/cmd/compile/internal/types2/api.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,6 @@ type Config struct {
169169
// If DisableUnusedImportCheck is set, packages are not checked
170170
// for unused imports.
171171
DisableUnusedImportCheck bool
172-
173-
// If EnableReverseTypeInference is set, uninstantiated and
174-
// partially instantiated generic functions may be assigned
175-
// (incl. returned) to variables of function type and type
176-
// inference will attempt to infer the missing type arguments.
177-
// See proposal go.dev/issue/59338.
178-
EnableReverseTypeInference bool
179172
}
180173

181174
func srcimporter_setUsesCgo(conf *Config) {

src/cmd/compile/internal/types2/api_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,7 @@ type T[P any] []P
594594

595595
for _, test := range tests {
596596
imports := make(testImporter)
597-
conf := Config{
598-
Importer: imports,
599-
EnableReverseTypeInference: true,
600-
}
597+
conf := Config{Importer: imports}
601598
instMap := make(map[*syntax.Name]Instance)
602599
useMap := make(map[*syntax.Name]Object)
603600
makePkg := func(src string) *Package {

src/cmd/compile/internal/types2/call.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ func (check *Checker) arguments(call *syntax.CallExpr, sig *Signature, targs []T
496496

497497
// collect type parameters from generic function arguments
498498
var genericArgs []int // indices of generic function arguments
499-
if check.conf.EnableReverseTypeInference {
499+
if enableReverseTypeInference {
500500
for i, arg := range args {
501501
// generic arguments cannot have a defined (*Named) type - no need for underlying type below
502502
if asig, _ := arg.typ.(*Signature); asig != nil && asig.TypeParams().Len() > 0 {

src/cmd/compile/internal/types2/check_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ func testFiles(t *testing.T, filenames []string, colDelta uint, manual bool) {
133133
flags := flag.NewFlagSet("", flag.PanicOnError)
134134
flags.StringVar(&conf.GoVersion, "lang", "", "")
135135
flags.BoolVar(&conf.FakeImportC, "fakeImportC", false, "")
136-
flags.BoolVar(&conf.EnableReverseTypeInference, "reverseTypeInference", false, "")
137136
if err := parseFlags(filenames[0], nil, flags); err != nil {
138137
t.Fatal(err)
139138
}

src/cmd/compile/internal/types2/expr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ func (check *Checker) nonGeneric(T Type, x *operand) {
12911291
}
12921292
case *Signature:
12931293
if t.tparams != nil {
1294-
if check.conf.EnableReverseTypeInference && T != nil {
1294+
if enableReverseTypeInference && T != nil {
12951295
if tsig, _ := under(T).(*Signature); tsig != nil {
12961296
check.funcInst(tsig, x.Pos(), x, nil)
12971297
return
@@ -1617,7 +1617,7 @@ func (check *Checker) exprInternal(T Type, x *operand, e syntax.Expr, hint Type)
16171617
case *syntax.IndexExpr:
16181618
if check.indexExpr(x, e) {
16191619
var tsig *Signature
1620-
if check.conf.EnableReverseTypeInference && T != nil {
1620+
if enableReverseTypeInference && T != nil {
16211621
tsig, _ = under(T).(*Signature)
16221622
}
16231623
check.funcInst(tsig, e.Pos(), x, e)

src/cmd/compile/internal/types2/infer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import (
1313
"strings"
1414
)
1515

16+
// If enableReverseTypeInference is set, uninstantiated and
17+
// partially instantiated generic functions may be assigned
18+
// (incl. returned) to variables of function type and type
19+
// inference will attempt to infer the missing type arguments.
20+
// Available with go1.21.
21+
const enableReverseTypeInference = true // disable for debugging
22+
1623
// infer attempts to infer the complete set of type arguments for generic function instantiation/call
1724
// based on the given type parameters tparams, type arguments targs, function parameters params, and
1825
// function arguments args, if any. There must be at least one type parameter, no more type arguments

src/cmd/compile/internal/types2/stdlib_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ func testTestDir(t *testing.T, path string, ignore ...string) {
139139
file, err := syntax.ParseFile(filename, nil, nil, 0)
140140
if err == nil {
141141
conf := Config{
142-
GoVersion: goVersion,
143-
Importer: stdLibImporter,
144-
EnableReverseTypeInference: true,
142+
GoVersion: goVersion,
143+
Importer: stdLibImporter,
145144
}
146145
_, err = conf.Check(filename, []*syntax.File{file}, nil)
147146
}
@@ -254,9 +253,8 @@ func typecheckFiles(t *testing.T, path string, filenames []string) {
254253

255254
// typecheck package files
256255
conf := Config{
257-
Error: func(err error) { t.Error(err) },
258-
Importer: stdLibImporter,
259-
EnableReverseTypeInference: true,
256+
Error: func(err error) { t.Error(err) },
257+
Importer: stdLibImporter,
260258
}
261259
info := Info{Uses: make(map[*syntax.Name]Object)}
262260
conf.Check(path, files, &info)

src/go/types/api.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,6 @@ type Config struct {
170170
// If DisableUnusedImportCheck is set, packages are not checked
171171
// for unused imports.
172172
DisableUnusedImportCheck bool
173-
174-
// If _EnableReverseTypeInference is set, uninstantiated and
175-
// partially instantiated generic functions may be assigned
176-
// (incl. returned) to variables of function type and type
177-
// inference will attempt to infer the missing type arguments.
178-
// See proposal go.dev/issue/59338.
179-
_EnableReverseTypeInference bool
180173
}
181174

182175
func srcimporter_setUsesCgo(conf *Config) {

src/go/types/api_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,7 @@ type T[P any] []P
594594

595595
for _, test := range tests {
596596
imports := make(testImporter)
597-
conf := Config{
598-
Importer: imports,
599-
// Unexported field: set below with boolFieldAddr
600-
// _EnableReverseTypeInference: true,
601-
}
602-
*boolFieldAddr(&conf, "_EnableReverseTypeInference") = true
597+
conf := Config{Importer: imports}
603598
instMap := make(map[*ast.Ident]Instance)
604599
useMap := make(map[*ast.Ident]Object)
605600
makePkg := func(src string) *Package {

0 commit comments

Comments
 (0)