]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: (TypeParam) SetBound -> SetConstraint
authorRobert Griesemer <gri@golang.org>
Wed, 28 Jul 2021 23:58:57 +0000 (16:58 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 29 Jul 2021 21:05:49 +0000 (21:05 +0000)
This matches the accessor named Constraint, and any documentation we have so far.
Use iface instead of Bound internally to types2; keep Bound because of two external
uses but mark it as deprecated. Adjust clients.

Change-Id: Id1a2c2f28259a16082e875eee0534d46cf157336
Reviewed-on: https://go-review.googlesource.com/c/go/+/338196
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/importer/iimport.go
src/cmd/compile/internal/noder/reader2.go
src/cmd/compile/internal/types2/builtins.go
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/instantiate.go
src/cmd/compile/internal/types2/lookup.go
src/cmd/compile/internal/types2/predicates.go
src/cmd/compile/internal/types2/type.go
src/cmd/compile/internal/types2/typeparam.go

index 999b2aa1dc12304022998dcb7c9a10106b7c592e..3dd28033a1a5d096dfa4261afeda156e39b2c4a9 100644 (file)
@@ -384,7 +384,7 @@ func (r *importReader) obj(name string) {
                id := ident{r.currPkg.Name(), name}
                r.p.tparamIndex[id] = t
 
-               t.SetBound(r.typ())
+               t.SetConstraint(r.typ())
 
        case 'V':
                typ := r.typ()
index 3e310e26c432edc5eeee0c04b177cad251a38710..d183934900216bd8939cda827f77abf5ed2902e5 100644 (file)
@@ -485,7 +485,7 @@ func (r *reader2) typeParamNames() []*types2.TypeName {
        }
 
        for i, bound := range r.dict.bounds {
-               r.dict.tparams[i].SetBound(r.p.typIdx(bound, r.dict))
+               r.dict.tparams[i].SetConstraint(r.p.typIdx(bound, r.dict))
        }
 
        return names
index 7ef9e7be6390f63c5a06744771c930e100327e23..7b2c92bfa864d68a30c7280d0f86b60d05341303 100644 (file)
@@ -817,7 +817,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x Type) Type {
                // type and collect possible result types at the same time.
                var rtypes []Type
                var tildes []bool
-               if !tp.Bound().is(func(typ Type, tilde bool) bool {
+               if !tp.iface().is(func(typ Type, tilde bool) bool {
                        if r := f(typ); r != nil {
                                rtypes = append(rtypes, r)
                                tildes = append(tildes, tilde)
index e1acf50213a8efad6e4398aef5f3f9c8b479e5f3..049d80dd9e7358110117f151bd052e7a50fda6ce 100644 (file)
@@ -479,7 +479,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr) {
                        var why string
                        if tpar := asTypeParam(x.typ); tpar != nil {
                                // Type parameter bounds don't specify fields, so don't mention "field".
-                               if tname := tpar.Bound().obj; tname != nil {
+                               if tname := tpar.iface().obj; tname != nil {
                                        why = check.sprintf("interface %s has no method %s", tname.name, sel)
                                } else {
                                        why = check.sprintf("type bound for %s has no method %s", x.typ, sel)
index 9f9f8a7f5d31bba4fc939c40608c066c96b46907..357f041c466bf509a45e4ce3371bf82ae0213cb6 100644 (file)
@@ -160,7 +160,7 @@ func (check *Checker) verify(pos syntax.Pos, tparams []*TypeName, targs []Type,
 // A suitable error is reported if the result is false.
 // TODO(gri) This should be a method of interfaces or type sets.
 func (check *Checker) satisfies(pos syntax.Pos, targ Type, tpar *TypeParam, smap *substMap) bool {
-       iface := tpar.Bound()
+       iface := tpar.iface()
        if iface.Empty() {
                return true // no type bound
        }
@@ -174,7 +174,7 @@ func (check *Checker) satisfies(pos syntax.Pos, targ Type, tpar *TypeParam, smap
        // if iface is comparable, targ must be comparable
        // TODO(gri) the error messages needs to be better, here
        if iface.IsComparable() && !Comparable(targ) {
-               if tpar := asTypeParam(targ); tpar != nil && tpar.Bound().typeSet().IsTop() {
+               if tpar := asTypeParam(targ); tpar != nil && tpar.iface().typeSet().IsTop() {
                        check.softErrorf(pos, "%s has no constraints", targ)
                        return false
                }
@@ -219,7 +219,7 @@ func (check *Checker) satisfies(pos syntax.Pos, targ Type, tpar *TypeParam, smap
        // If targ is itself a type parameter, each of its possible types, but at least one, must be in the
        // list of iface types (i.e., the targ type list must be a non-empty subset of the iface types).
        if targ := asTypeParam(targ); targ != nil {
-               targBound := targ.Bound()
+               targBound := targ.iface()
                if targBound.typeSet().types == nil {
                        check.softErrorf(pos, "%s does not satisfy %s (%s has no type constraints)", targ, tpar.bound, targ)
                        return false
index 3819a9ffb86d99a3019e03602c2307582ce811f0..41e5bc7811a34054358f6e5f3475ba557b24be7d 100644 (file)
@@ -186,7 +186,7 @@ func lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (o
                                }
 
                        case *TypeParam:
-                               if i, m := t.Bound().typeSet().LookupMethod(pkg, name); m != nil {
+                               if i, m := t.iface().typeSet().LookupMethod(pkg, name); m != nil {
                                        assert(m.typ != nil)
                                        index = concat(e.index, i)
                                        if obj != nil || e.multiples {
index f3aeafcbb709eefa2fd81c4bcc79a7ab5ec02361..84342b2796a7956205cfe4bb9ec4e1c502501721 100644 (file)
@@ -113,7 +113,7 @@ func comparable(T Type, seen map[Type]bool) bool {
        case *Array:
                return comparable(t.elem, seen)
        case *TypeParam:
-               return t.Bound().IsComparable()
+               return t.iface().IsComparable()
        }
        return false
 }
index 80054372bccb08fee4b0505cd1628f52920a786d..a9439261899484f0b660e95c6ac9a69fbeda221b 100644 (file)
@@ -56,7 +56,7 @@ func optype(typ Type) Type {
                // for a type parameter list of the form:
                // (type T interface { type T }).
                // See also issue #39680.
-               if a := t.Bound().typeSet().types; a != nil {
+               if a := t.iface().typeSet().types; a != nil {
                        // If we have a union with a single entry, ignore
                        // any tilde because under(~t) == under(t).
                        if u, _ := a.(*Union); u != nil && u.NumTerms() == 1 {
index aff03a5f042fb06eb76e12bd88461f7f2f03c4a4..9f8c921bf175a4fc8b0b0db9d1bd661db53ab665 100644 (file)
@@ -72,21 +72,27 @@ func (t *TypeParam) Constraint() Type {
        return t.bound
 }
 
-// Bound returns the underlying type of the type parameter's
-// constraint.
-// Deprecated for external use. Use Constraint instead.
-func (t *TypeParam) Bound() *Interface {
+// SetConstraint sets the type constraint for t.
+func (t *TypeParam) SetConstraint(bound Type) {
+       if bound == nil {
+               panic("types2.TypeParam.SetConstraint: bound must not be nil")
+       }
+       t.bound = bound
+}
+
+// iface returns the constraint interface of t.
+func (t *TypeParam) iface() *Interface {
        if iface, _ := under(t.Constraint()).(*Interface); iface != nil {
                return iface
        }
        return &emptyInterface
 }
 
-func (t *TypeParam) SetBound(bound Type) {
-       if bound == nil {
-               panic("types2.TypeParam.SetBound: bound must not be nil")
-       }
-       t.bound = bound
+// Bound returns the constraint interface of t.
+// Deprecated. Only here for the compiler.
+// TODO(gri) remove in favor of uses of Constraint.
+func (t *TypeParam) Bound() *Interface {
+       return t.iface()
 }
 
 func (t *TypeParam) Underlying() Type { return t }
@@ -132,5 +138,5 @@ func bindTParams(list []*TypeName) *TypeParams {
 // Implementation
 
 func (t *TypeParam) underIs(f func(Type) bool) bool {
-       return t.Bound().typeSet().underIs(f)
+       return t.iface().typeSet().underIs(f)
 }