1
0
mirror of https://github.com/golang/go synced 2024-11-26 08:27:56 -07:00

cmd/compile/internal/types2: remove Config.InferFromConstraints flag

Constraint type inference is part of the proposed language.
Use an internal flag to control the feayure for debugging.

Change-Id: I7a9eaee92b5ffc23c25d9e68a729acc0d705e879
Reviewed-on: https://go-review.googlesource.com/c/go/+/306770
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Griesemer 2021-04-01 18:39:39 -07:00
parent bce85b7011
commit 7d5c54eee4
6 changed files with 6 additions and 11 deletions

View File

@ -36,7 +36,6 @@ func check2(noders []*noder) {
// typechecking // typechecking
conf := types2.Config{ conf := types2.Config{
GoVersion: base.Flag.Lang, GoVersion: base.Flag.Lang,
InferFromConstraints: true,
IgnoreLabels: true, // parser already checked via syntax.CheckBranches mode IgnoreLabels: true, // parser already checked via syntax.CheckBranches mode
CompilerErrorMessages: true, // use error strings matching existing compiler errors CompilerErrorMessages: true, // use error strings matching existing compiler errors
Error: func(err error) { Error: func(err error) {

View File

@ -110,10 +110,6 @@ type Config struct {
// If AcceptMethodTypeParams is set, methods may have type parameters. // If AcceptMethodTypeParams is set, methods may have type parameters.
AcceptMethodTypeParams bool AcceptMethodTypeParams bool
// If InferFromConstraints is set, constraint type inference is used
// if some function type arguments are missing.
InferFromConstraints bool
// If FakeImportC is set, `import "C"` (for packages requiring Cgo) // If FakeImportC is set, `import "C"` (for packages requiring Cgo)
// declares an empty "C" package and errors are omitted for qualified // declares an empty "C" package and errors are omitted for qualified
// identifiers referring to package C (which won't find an object). // identifiers referring to package C (which won't find an object).

View File

@ -66,7 +66,6 @@ func mayTypecheck(t *testing.T, path, source string, info *Info) (string, error)
} }
conf := Config{ conf := Config{
AcceptMethodTypeParams: true, AcceptMethodTypeParams: true,
InferFromConstraints: true,
Error: func(err error) {}, Error: func(err error) {},
Importer: defaultImporter(), Importer: defaultImporter(),
} }

View File

@ -27,7 +27,7 @@ func (check *Checker) funcInst(x *operand, inst *syntax.IndexExpr) {
// check number of type arguments (got) vs number of type parameters (want) // check number of type arguments (got) vs number of type parameters (want)
sig := x.typ.(*Signature) sig := x.typ.(*Signature)
got, want := len(targs), len(sig.tparams) got, want := len(targs), len(sig.tparams)
if !check.conf.InferFromConstraints && got != want || got > want { if !useConstraintTypeInference && got != want || got > want {
check.errorf(xlist[got-1], "got %d type arguments but want %d", got, want) check.errorf(xlist[got-1], "got %d type arguments but want %d", got, want)
x.mode = invalid x.mode = invalid
x.expr = inst x.expr = inst

View File

@ -129,7 +129,6 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin
var conf Config var conf Config
conf.GoVersion = goVersion conf.GoVersion = goVersion
conf.AcceptMethodTypeParams = true conf.AcceptMethodTypeParams = true
conf.InferFromConstraints = true
// special case for importC.src // special case for importC.src
if len(filenames) == 1 && strings.HasSuffix(filenames[0], "importC.src") { if len(filenames) == 1 && strings.HasSuffix(filenames[0], "importC.src") {
conf.FakeImportC = true conf.FakeImportC = true

View File

@ -11,6 +11,8 @@ import (
"cmd/compile/internal/syntax" "cmd/compile/internal/syntax"
) )
const useConstraintTypeInference = true
// infer attempts to infer the complete set of type arguments for generic function instantiation/call // 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 // 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 // function arguments args, if any. There must be at least one type parameter, no more type arguments
@ -56,7 +58,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeName, targs []Type, p
// and types inferred via constraint type inference take precedence over types // and types inferred via constraint type inference take precedence over types
// inferred from function arguments. // inferred from function arguments.
// If we have type arguments, see how far we get with constraint type inference. // If we have type arguments, see how far we get with constraint type inference.
if len(targs) > 0 && check.conf.InferFromConstraints { if len(targs) > 0 && useConstraintTypeInference {
var index int var index int
targs, index = check.inferB(tparams, targs, report) targs, index = check.inferB(tparams, targs, report)
if targs == nil || index < 0 { if targs == nil || index < 0 {
@ -171,7 +173,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeName, targs []Type, p
// See how far we get with constraint type inference. // See how far we get with constraint type inference.
// Note that even if we don't have any type arguments, constraint type inference // Note that even if we don't have any type arguments, constraint type inference
// may produce results for constraints that explicitly specify a type. // may produce results for constraints that explicitly specify a type.
if check.conf.InferFromConstraints { if useConstraintTypeInference {
targs, index = check.inferB(tparams, targs, report) targs, index = check.inferB(tparams, targs, report)
if targs == nil || index < 0 { if targs == nil || index < 0 {
return targs return targs
@ -219,7 +221,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeName, targs []Type, p
} }
// Again, follow up with constraint type inference. // Again, follow up with constraint type inference.
if check.conf.InferFromConstraints { if useConstraintTypeInference {
targs, index = check.inferB(tparams, targs, report) targs, index = check.inferB(tparams, targs, report)
if targs == nil || index < 0 { if targs == nil || index < 0 {
return targs return targs