mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/types2: don't export TypeSet
For now don't export TypeSet in the interest of keeping the types2 API surface small(er). This is a clean port of CL 341289 from go/types. Change-Id: I50c747629f25472f2ec5ba59d7f543ee3c1c423b Reviewed-on: https://go-review.googlesource.com/c/go/+/344610 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dan Scales <danscales@google.com>
This commit is contained in:
parent
d70c69d830
commit
bba460499c
5 changed files with 29 additions and 29 deletions
|
|
@ -17,11 +17,11 @@ type Interface struct {
|
||||||
embedPos *[]syntax.Pos // positions of embedded elements; or nil (for error messages) - use pointer to save space
|
embedPos *[]syntax.Pos // positions of embedded elements; or nil (for error messages) - use pointer to save space
|
||||||
complete bool // indicates that all fields (except for tset) are set up
|
complete bool // indicates that all fields (except for tset) are set up
|
||||||
|
|
||||||
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.
|
// typeSet returns the type set for interface t.
|
||||||
func (t *Interface) typeSet() *TypeSet { return computeInterfaceTypeSet(nil, nopos, t) }
|
func (t *Interface) typeSet() *_TypeSet { return computeInterfaceTypeSet(nil, nopos, t) }
|
||||||
|
|
||||||
// emptyInterface represents the empty interface
|
// emptyInterface represents the empty interface
|
||||||
var emptyInterface = Interface{complete: true, tset: &topTypeSet}
|
var emptyInterface = Interface{complete: true, tset: &topTypeSet}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ func TestSizeof(t *testing.T) {
|
||||||
// Misc
|
// Misc
|
||||||
{Scope{}, 60, 104},
|
{Scope{}, 60, 104},
|
||||||
{Package{}, 40, 80},
|
{Package{}, 40, 80},
|
||||||
{TypeSet{}, 28, 56},
|
{_TypeSet{}, 28, 56},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ import (
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// API
|
// API
|
||||||
|
|
||||||
// A TypeSet represents the type set of an interface.
|
// A _TypeSet represents the type set of an interface.
|
||||||
type TypeSet struct {
|
type _TypeSet struct {
|
||||||
comparable bool // if set, the interface is or embeds comparable
|
comparable bool // if set, the interface is or embeds comparable
|
||||||
// TODO(gri) consider using a set for the methods for faster lookup
|
// TODO(gri) consider using a set for the methods for faster lookup
|
||||||
methods []*Func // all methods of the interface; sorted by unique ID
|
methods []*Func // all methods of the interface; sorted by unique ID
|
||||||
|
|
@ -23,20 +23,20 @@ type TypeSet struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsEmpty reports whether type set s is the empty set.
|
// IsEmpty reports whether type set s is the empty set.
|
||||||
func (s *TypeSet) IsEmpty() bool { return s.terms.isEmpty() }
|
func (s *_TypeSet) IsEmpty() bool { return s.terms.isEmpty() }
|
||||||
|
|
||||||
// IsAll reports whether type set s is the set of all types (corresponding to the empty interface).
|
// IsAll reports whether type set s is the set of all types (corresponding to the empty interface).
|
||||||
func (s *TypeSet) IsAll() bool {
|
func (s *_TypeSet) IsAll() bool {
|
||||||
return !s.comparable && len(s.methods) == 0 && s.terms.isAll()
|
return !s.comparable && len(s.methods) == 0 && s.terms.isAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(gri) IsMethodSet is not a great name for this predicate. Find a better one.
|
// TODO(gri) IsMethodSet is not a great name for this predicate. Find a better one.
|
||||||
|
|
||||||
// IsMethodSet reports whether the type set s is described by a single set of methods.
|
// IsMethodSet reports whether the type set s is described by a single set of methods.
|
||||||
func (s *TypeSet) IsMethodSet() bool { return !s.comparable && s.terms.isAll() }
|
func (s *_TypeSet) IsMethodSet() bool { return !s.comparable && s.terms.isAll() }
|
||||||
|
|
||||||
// IsComparable reports whether each type in the set is comparable.
|
// IsComparable reports whether each type in the set is comparable.
|
||||||
func (s *TypeSet) IsComparable() bool {
|
func (s *_TypeSet) IsComparable() bool {
|
||||||
if s.terms.isAll() {
|
if s.terms.isAll() {
|
||||||
return s.comparable
|
return s.comparable
|
||||||
}
|
}
|
||||||
|
|
@ -48,24 +48,24 @@ func (s *TypeSet) IsComparable() bool {
|
||||||
// TODO(gri) IsTypeSet is not a great name for this predicate. Find a better one.
|
// TODO(gri) IsTypeSet is not a great name for this predicate. Find a better one.
|
||||||
|
|
||||||
// IsTypeSet reports whether the type set s is represented by a finite set of underlying types.
|
// 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
|
return !s.comparable && len(s.methods) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// NumMethods returns the number of methods available.
|
// 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().
|
// Method returns the i'th method of type set s for 0 <= i < s.NumMethods().
|
||||||
// The methods are ordered by their unique ID.
|
// 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).
|
// 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
|
// TODO(gri) s.methods is sorted - consider binary search
|
||||||
return lookupMethod(s.methods, pkg, name)
|
return lookupMethod(s.methods, pkg, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TypeSet) String() string {
|
func (s *_TypeSet) String() string {
|
||||||
switch {
|
switch {
|
||||||
case s.IsEmpty():
|
case s.IsEmpty():
|
||||||
return "∅"
|
return "∅"
|
||||||
|
|
@ -105,16 +105,16 @@ func (s *TypeSet) String() string {
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Implementation
|
// Implementation
|
||||||
|
|
||||||
func (s *TypeSet) hasTerms() bool { return !s.terms.isAll() }
|
func (s *_TypeSet) hasTerms() bool { return !s.terms.isAll() }
|
||||||
func (s *TypeSet) structuralType() Type { return s.terms.structuralType() }
|
func (s *_TypeSet) structuralType() Type { return s.terms.structuralType() }
|
||||||
func (s *TypeSet) includes(t Type) bool { return s.terms.includes(t) }
|
func (s *_TypeSet) includes(t Type) bool { return s.terms.includes(t) }
|
||||||
func (s1 *TypeSet) subsetOf(s2 *TypeSet) bool { return s1.terms.subsetOf(s2.terms) }
|
func (s1 *_TypeSet) subsetOf(s2 *_TypeSet) bool { return s1.terms.subsetOf(s2.terms) }
|
||||||
|
|
||||||
// TODO(gri) TypeSet.is and TypeSet.underIs should probably also go into termlist.go
|
// TODO(gri) TypeSet.is and TypeSet.underIs should probably also go into termlist.go
|
||||||
|
|
||||||
var topTerm = term{false, theTop}
|
var topTerm = term{false, theTop}
|
||||||
|
|
||||||
func (s *TypeSet) is(f func(*term) bool) bool {
|
func (s *_TypeSet) is(f func(*term) bool) bool {
|
||||||
if len(s.terms) == 0 {
|
if len(s.terms) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +133,7 @@ func (s *TypeSet) is(f func(*term) bool) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TypeSet) underIs(f func(Type) bool) bool {
|
func (s *_TypeSet) underIs(f func(Type) bool) bool {
|
||||||
if len(s.terms) == 0 {
|
if len(s.terms) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -158,10 +158,10 @@ func (s *TypeSet) underIs(f func(Type) bool) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// topTypeSet may be used as type set for the empty interface.
|
// topTypeSet may be used as type set for the empty interface.
|
||||||
var topTypeSet = TypeSet{terms: allTermlist}
|
var topTypeSet = _TypeSet{terms: allTermlist}
|
||||||
|
|
||||||
// computeInterfaceTypeSet may be called with check == nil.
|
// computeInterfaceTypeSet may be called with check == nil.
|
||||||
func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *TypeSet {
|
func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_TypeSet {
|
||||||
if ityp.tset != nil {
|
if ityp.tset != nil {
|
||||||
return ityp.tset
|
return ityp.tset
|
||||||
}
|
}
|
||||||
|
|
@ -197,7 +197,7 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *T
|
||||||
// have valid interfaces. Mark the interface as complete to avoid
|
// have valid interfaces. Mark the interface as complete to avoid
|
||||||
// infinite recursion if the validType check occurs later for some
|
// infinite recursion if the validType check occurs later for some
|
||||||
// reason.
|
// reason.
|
||||||
ityp.tset = &TypeSet{terms: allTermlist} // TODO(gri) is this sufficient?
|
ityp.tset = &_TypeSet{terms: allTermlist} // TODO(gri) is this sufficient?
|
||||||
|
|
||||||
// Methods of embedded interfaces are collected unchanged; i.e., the identity
|
// 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
|
// of a method I.m's Func Object of an interface I is the same as that of
|
||||||
|
|
@ -347,17 +347,17 @@ func (a byUniqueMethodName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
// invalidTypeSet is a singleton type set to signal an invalid type set
|
// invalidTypeSet is a singleton type set to signal an invalid type set
|
||||||
// due to an error. It's also a valid empty type set, so consumers of
|
// due to an error. It's also a valid empty type set, so consumers of
|
||||||
// type sets may choose to ignore it.
|
// type sets may choose to ignore it.
|
||||||
var invalidTypeSet TypeSet
|
var invalidTypeSet _TypeSet
|
||||||
|
|
||||||
// computeUnionTypeSet may be called with check == nil.
|
// computeUnionTypeSet may be called with check == nil.
|
||||||
// The result is &invalidTypeSet if the union overflows.
|
// The result is &invalidTypeSet if the union overflows.
|
||||||
func computeUnionTypeSet(check *Checker, pos syntax.Pos, utyp *Union) *TypeSet {
|
func computeUnionTypeSet(check *Checker, pos syntax.Pos, utyp *Union) *_TypeSet {
|
||||||
if utyp.tset != nil {
|
if utyp.tset != nil {
|
||||||
return utyp.tset
|
return utyp.tset
|
||||||
}
|
}
|
||||||
|
|
||||||
// avoid infinite recursion (see also computeInterfaceTypeSet)
|
// avoid infinite recursion (see also computeInterfaceTypeSet)
|
||||||
utyp.tset = new(TypeSet)
|
utyp.tset = new(_TypeSet)
|
||||||
|
|
||||||
var allTerms termlist
|
var allTerms termlist
|
||||||
for _, t := range utyp.terms {
|
for _, t := range utyp.terms {
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ import "cmd/compile/internal/syntax"
|
||||||
|
|
||||||
// A Union represents a union of terms embedded in an interface.
|
// A Union represents a union of terms embedded in an interface.
|
||||||
type Union struct {
|
type Union struct {
|
||||||
terms []*Term // list of syntactical terms (not a canonicalized termlist)
|
terms []*Term // list of syntactical terms (not a canonicalized termlist)
|
||||||
tset *TypeSet // type set described by this union, computed lazily
|
tset *_TypeSet // type set described by this union, computed lazily
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUnion returns a new Union type with the given terms.
|
// NewUnion returns a new Union type with the given terms.
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ func defPredeclaredTypes() {
|
||||||
{
|
{
|
||||||
obj := NewTypeName(nopos, nil, "comparable", nil)
|
obj := NewTypeName(nopos, nil, "comparable", nil)
|
||||||
obj.setColor(black)
|
obj.setColor(black)
|
||||||
ityp := &Interface{obj, nil, nil, nil, true, &TypeSet{true, nil, allTermlist}}
|
ityp := &Interface{obj, nil, nil, nil, true, &_TypeSet{true, nil, allTermlist}}
|
||||||
NewNamed(obj, ityp, nil)
|
NewNamed(obj, ityp, nil)
|
||||||
def(obj)
|
def(obj)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue