]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: remove Config.InferFromConstraints flag
authorRobert Griesemer <gri@golang.org>
Fri, 2 Apr 2021 01:39:39 +0000 (18:39 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 7 Apr 2021 05:19:15 +0000 (05:19 +0000)
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>
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/infer.go

index 2de8c3fa60ac1e0dd222d3e41160e08271c8dc79..3e0d3285ab916ec0661ba9601149a3209138f02c 100644 (file)
@@ -36,7 +36,6 @@ func check2(noders []*noder) {
        // typechecking
        conf := types2.Config{
                GoVersion:             base.Flag.Lang,
-               InferFromConstraints:  true,
                IgnoreLabels:          true, // parser already checked via syntax.CheckBranches mode
                CompilerErrorMessages: true, // use error strings matching existing compiler errors
                Error: func(err error) {
index d356978d5e9f05fca4c68b9627449b88567de3cd..63008711bf90c9daa2dc3bbedba97c0708583221 100644 (file)
@@ -110,10 +110,6 @@ type Config struct {
        // If AcceptMethodTypeParams is set, methods may have type parameters.
        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)
        // declares an empty "C" package and errors are omitted for qualified
        // identifiers referring to package C (which won't find an object).
index 42135df1f6b7fc341abe89846cb1150920a177bb..b5990e5d46c52ede0c0f4d498a6029ba8762e0cc 100644 (file)
@@ -66,7 +66,6 @@ func mayTypecheck(t *testing.T, path, source string, info *Info) (string, error)
        }
        conf := Config{
                AcceptMethodTypeParams: true,
-               InferFromConstraints:   true,
                Error:                  func(err error) {},
                Importer:               defaultImporter(),
        }
index 3ffc8c1bef666ca561c60ac870c905c52273c51b..5ad8ea9f877214391486b9ab295203215f623a3c 100644 (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)
        sig := x.typ.(*Signature)
        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)
                x.mode = invalid
                x.expr = inst
index ac21c3458e2a7296d215d8d0c9c2be1f55bc43f9..a6baa71b2a90b3a116cb85ba3e02e6b3ddeab10a 100644 (file)
@@ -129,7 +129,6 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin
        var conf Config
        conf.GoVersion = goVersion
        conf.AcceptMethodTypeParams = true
-       conf.InferFromConstraints = true
        // special case for importC.src
        if len(filenames) == 1 && strings.HasSuffix(filenames[0], "importC.src") {
                conf.FakeImportC = true
index d267787816460175dd4cc2251c96aafa71e613a8..995ebd7ea0c348f25cebaeb86a34f14a33910b97 100644 (file)
@@ -11,6 +11,8 @@ import (
        "cmd/compile/internal/syntax"
 )
 
+const useConstraintTypeInference = true
+
 // 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
@@ -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
        // inferred from function arguments.
        // 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
                targs, index = check.inferB(tparams, targs, report)
                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.
        // Note that even if we don't have any type arguments, constraint type inference
        // may produce results for constraints that explicitly specify a type.
-       if check.conf.InferFromConstraints {
+       if useConstraintTypeInference {
                targs, index = check.inferB(tparams, targs, report)
                if targs == nil || index < 0 {
                        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.
-       if check.conf.InferFromConstraints {
+       if useConstraintTypeInference {
                targs, index = check.inferB(tparams, targs, report)
                if targs == nil || index < 0 {
                        return targs