]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: remove internal constant enableInterfaceInference
authorRobert Griesemer <gri@golang.org>
Tue, 1 Aug 2023 04:46:31 +0000 (21:46 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 1 Aug 2023 16:43:44 +0000 (16:43 +0000)
We're not going to disable this functionality as it would
invalidate code that now type-checks with type inference
based on this mechanism.

Change-Id: Ib11059e2f70a5a209693b06f754cba862e3650ec
Reviewed-on: https://go-review.googlesource.com/c/go/+/514715
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>

src/cmd/compile/internal/types2/unify.go
src/go/types/unify.go

index dfb5512753d7894e5cef31ef55a60f34960a1007..433d31b3029bd7af5756c32947ec92ef8dcb911c 100644 (file)
@@ -53,11 +53,6 @@ const (
        // the core types, if any, of non-local (unbound) type parameters.
        enableCoreTypeUnification = true
 
-       // If enableInterfaceInference is set, type inference uses
-       // shared methods for improved type inference involving
-       // interfaces.
-       enableInterfaceInference = true
-
        // If traceInference is set, unification will print a trace of its operation.
        // Interpretation of trace:
        //   x ≡ y    attempt to unify types x and y
@@ -339,7 +334,7 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
        // we will fail at function instantiation or argument assignment time.
        //
        // If we have at least one defined type, there is one in y.
-       if ny, _ := y.(*Named); mode&exact == 0 && ny != nil && isTypeLit(x) && !(enableInterfaceInference && IsInterface(x)) {
+       if ny, _ := y.(*Named); mode&exact == 0 && ny != nil && isTypeLit(x) && !IsInterface(x) {
                if traceInference {
                        u.tracef("%s ≡ under %s", x, ny)
                }
@@ -437,12 +432,12 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
                emode |= exact
        }
 
-       // If EnableInterfaceInference is set and we don't require exact unification,
-       // if both types are interfaces, one interface must have a subset of the
-       // methods of the other and corresponding method signatures must unify.
+       // If we don't require exact unification and both types are interfaces,
+       // one interface must have a subset of the methods of the other and
+       // corresponding method signatures must unify.
        // If only one type is an interface, all its methods must be present in the
        // other type and corresponding method signatures must unify.
-       if enableInterfaceInference && mode&exact == 0 {
+       if mode&exact == 0 {
                // One or both interfaces may be defined types.
                // Look under the name, but not under type parameters (go.dev/issue/60564).
                xi := asInterface(x)
@@ -632,7 +627,7 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
                }
 
        case *Interface:
-               assert(!enableInterfaceInference || mode&exact != 0) // handled before this switch
+               assert(mode&exact != 0) // inexact unification is handled before this switch
 
                // Two interface types unify if they have the same set of methods with
                // the same names, and corresponding function types unify.
index e4121413c5e18e8a645c692e60e03468cd85b344..4d97e119bfc82494f1b26287d807f10739efe76d 100644 (file)
@@ -55,11 +55,6 @@ const (
        // the core types, if any, of non-local (unbound) type parameters.
        enableCoreTypeUnification = true
 
-       // If enableInterfaceInference is set, type inference uses
-       // shared methods for improved type inference involving
-       // interfaces.
-       enableInterfaceInference = true
-
        // If traceInference is set, unification will print a trace of its operation.
        // Interpretation of trace:
        //   x ≡ y    attempt to unify types x and y
@@ -341,7 +336,7 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
        // we will fail at function instantiation or argument assignment time.
        //
        // If we have at least one defined type, there is one in y.
-       if ny, _ := y.(*Named); mode&exact == 0 && ny != nil && isTypeLit(x) && !(enableInterfaceInference && IsInterface(x)) {
+       if ny, _ := y.(*Named); mode&exact == 0 && ny != nil && isTypeLit(x) && !IsInterface(x) {
                if traceInference {
                        u.tracef("%s ≡ under %s", x, ny)
                }
@@ -439,12 +434,12 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
                emode |= exact
        }
 
-       // If EnableInterfaceInference is set and we don't require exact unification,
-       // if both types are interfaces, one interface must have a subset of the
-       // methods of the other and corresponding method signatures must unify.
+       // If we don't require exact unification and both types are interfaces,
+       // one interface must have a subset of the methods of the other and
+       // corresponding method signatures must unify.
        // If only one type is an interface, all its methods must be present in the
        // other type and corresponding method signatures must unify.
-       if enableInterfaceInference && mode&exact == 0 {
+       if mode&exact == 0 {
                // One or both interfaces may be defined types.
                // Look under the name, but not under type parameters (go.dev/issue/60564).
                xi := asInterface(x)
@@ -634,7 +629,7 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
                }
 
        case *Interface:
-               assert(!enableInterfaceInference || mode&exact != 0) // handled before this switch
+               assert(mode&exact != 0) // inexact unification is handled before this switch
 
                // Two interface types unify if they have the same set of methods with
                // the same names, and corresponding function types unify.