]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] go/types: don't expose the TypeSet API for 1.18
authorRob Findley <rfindley@google.com>
Wed, 4 Aug 2021 14:45:16 +0000 (10:45 -0400)
committerRobert Findley <rfindley@google.com>
Tue, 10 Aug 2021 21:49:07 +0000 (21:49 +0000)
The TypeSet API is very new and probably not necessary to expose outside
of go/types, at least for 1.18. Users can check whether a type is
contained within a type set via Implements, and can access the
representation of the type set via the embedded Unions.

Change-Id: Icc7355285785bee5aa7a8fe74052bcb0fedcd0a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/341289
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/builtins.go
src/go/types/interface.go
src/go/types/sizeof_test.go
src/go/types/typeset.go
src/go/types/universe.go

index aae05438cd3cd54c425bbbf7dac0cea2fbd02132..c73d94658ab263678920d902e47c48faefdb42e2 100644 (file)
@@ -844,7 +844,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x Type) Type {
                ptyp := check.NewTypeParam(tpar, &emptyInterface) // assigns type to tpar as a side-effect
                ptyp.index = tp.index
                tsum := newUnion(rtypes, tildes)
-               ptyp.bound = &Interface{complete: true, tset: &TypeSet{types: tsum}}
+               ptyp.bound = &Interface{complete: true, tset: &_TypeSet{types: tsum}}
 
                return ptyp
        }
index e98e40179caf4cc406cc60774bcff80f67265fdd..d8f967185713295e005faadc83d520384c08ed05 100644 (file)
@@ -21,11 +21,11 @@ type Interface struct {
        embedPos  *[]token.Pos // positions of embedded elements; or nil (for error messages) - use pointer to save space
        complete  bool         // indicates that obj, methods, and embeddeds are set and type set can be computed
 
-       tset *TypeSet // type set described by this interface, computed lazily
+       tset *_TypeSet // type set described by this interface, computed lazily
 }
 
 // typeSet returns the type set for interface t.
-func (t *Interface) typeSet() *TypeSet { return computeTypeSet(nil, token.NoPos, t) }
+func (t *Interface) typeSet() *_TypeSet { return computeTypeSet(nil, token.NoPos, t) }
 
 // is reports whether interface t represents types that all satisfy f.
 func (t *Interface) is(f func(Type, bool) bool) bool {
index 75122b027357fc03e3eafc563a5f336db934f534..67a9b39558e8da5b99736ff1ab6c825ec37b0770 100644 (file)
@@ -48,7 +48,7 @@ func TestSizeof(t *testing.T) {
                // Misc
                {Scope{}, 44, 88},
                {Package{}, 40, 80},
-               {TypeSet{}, 24, 48},
+               {_TypeSet{}, 24, 48},
        }
        for _, test := range tests {
                got := reflect.TypeOf(test.val).Size()
index cbd867dd953fe2edb9ce761cc4436eda1e5c4e48..836f93047a237d5cad0adaccbb53b964da4b145d 100644 (file)
@@ -14,8 +14,8 @@ import (
 // ----------------------------------------------------------------------------
 // API
 
-// A TypeSet represents the type set of an interface.
-type TypeSet struct {
+// A _TypeSet represents the type set of an interface.
+type _TypeSet struct {
        comparable bool // if set, the interface is or embeds comparable
        // TODO(gri) consider using a set for the methods for faster lookup
        methods []*Func // all methods of the interface; sorted by unique ID
@@ -23,14 +23,14 @@ type TypeSet struct {
 }
 
 // IsTop reports whether type set s is the top type set (corresponding to the empty interface).
-func (s *TypeSet) IsTop() bool { return !s.comparable && len(s.methods) == 0 && s.types == nil }
+func (s *_TypeSet) IsTop() bool { return !s.comparable && len(s.methods) == 0 && s.types == nil }
 
 // IsMethodSet reports whether the type set s is described by a single set of methods.
-func (s *TypeSet) IsMethodSet() bool { return !s.comparable && s.types == nil }
+func (s *_TypeSet) IsMethodSet() bool { return !s.comparable && s.types == nil }
 
 // IsComparable reports whether each type in the set is comparable.
 // TODO(gri) this is not correct - there may be s.types values containing non-comparable types
-func (s *TypeSet) IsComparable() bool {
+func (s *_TypeSet) IsComparable() bool {
        if s.types == nil {
                return s.comparable
        }
@@ -46,24 +46,24 @@ func (s *TypeSet) IsComparable() bool {
 // TODO(gri) IsTypeSet is not a great name. Find a better one.
 
 // IsTypeSet reports whether the type set s is represented by a finite set of underlying types.
-func (s *TypeSet) IsTypeSet() bool {
+func (s *_TypeSet) IsTypeSet() bool {
        return !s.comparable && len(s.methods) == 0
 }
 
 // NumMethods returns the number of methods available.
-func (s *TypeSet) NumMethods() int { return len(s.methods) }
+func (s *_TypeSet) NumMethods() int { return len(s.methods) }
 
 // Method returns the i'th method of type set s for 0 <= i < s.NumMethods().
 // The methods are ordered by their unique ID.
-func (s *TypeSet) Method(i int) *Func { return s.methods[i] }
+func (s *_TypeSet) Method(i int) *Func { return s.methods[i] }
 
 // LookupMethod returns the index of and method with matching package and name, or (-1, nil).
-func (s *TypeSet) LookupMethod(pkg *Package, name string) (int, *Func) {
+func (s *_TypeSet) LookupMethod(pkg *Package, name string) (int, *Func) {
        // TODO(gri) s.methods is sorted - consider binary search
        return lookupMethod(s.methods, pkg, name)
 }
 
-func (s *TypeSet) String() string {
+func (s *_TypeSet) String() string {
        if s.IsTop() {
                return "⊤"
        }
@@ -102,7 +102,7 @@ func (s *TypeSet) String() string {
 // enumerable types in the type set s. If the type set comprises all types
 // f is called once with the top type; if the type set is empty, the result
 // is false.
-func (s *TypeSet) underIs(f func(Type) bool) bool {
+func (s *_TypeSet) underIs(f func(Type) bool) bool {
        switch t := s.types.(type) {
        case nil:
                return f(theTop)
@@ -114,10 +114,10 @@ func (s *TypeSet) underIs(f func(Type) bool) bool {
 }
 
 // topTypeSet may be used as type set for the empty interface.
-var topTypeSet TypeSet
+var topTypeSet _TypeSet
 
 // computeTypeSet may be called with check == nil.
-func computeTypeSet(check *Checker, pos token.Pos, ityp *Interface) *TypeSet {
+func computeTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_TypeSet {
        if ityp.tset != nil {
                return ityp.tset
        }
@@ -157,7 +157,7 @@ func computeTypeSet(check *Checker, pos token.Pos, ityp *Interface) *TypeSet {
        // have valid interfaces. Mark the interface as complete to avoid
        // infinite recursion if the validType check occurs later for some
        // reason.
-       ityp.tset = new(TypeSet) // TODO(gri) is this sufficient?
+       ityp.tset = new(_TypeSet) // TODO(gri) is this sufficient?
 
        // Methods of embedded interfaces are collected unchanged; i.e., the identity
        // of a method I.m's Func Object of an interface I is the same as that of
index e2b3bd7c187b4acdc0b83f393ada64b3c9abfbe5..83c54c8cd33577c04f2172e99a117add241fd043 100644 (file)
@@ -100,7 +100,7 @@ func defPredeclaredTypes() {
        {
                obj := NewTypeName(token.NoPos, nil, "comparable", nil)
                obj.setColor(black)
-               ityp := &Interface{obj, nil, nil, nil, true, &TypeSet{true, nil, nil}}
+               ityp := &Interface{obj, nil, nil, nil, true, &_TypeSet{true, nil, nil}}
                NewNamed(obj, ityp, nil)
                def(obj)
        }