diff options
author | Robert Griesemer <gri@golang.org> | 2021-07-29 11:10:04 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-08-05 19:36:47 +0000 |
commit | bb5608dd5d056519bd90666b815e0b2bf65e5ee8 (patch) | |
tree | ce15dcdb79b6a54969dda7ec002a630c71ff40fb /src/cmd/compile/internal/types2/interface.go | |
parent | 6dadee759c812961300c8d1a44959d14299fd9f8 (diff) | |
download | go-bb5608dd5d056519bd90666b815e0b2bf65e5ee8.tar.gz go-bb5608dd5d056519bd90666b815e0b2bf65e5ee8.zip |
[dev.typeparams] cmd/compile/internal/types2: implement type sets with term lists
This CL resolves several known issues and TODOs.
- Represent type sets with term lists and using term list abstractions.
- Represent Unions internally as a list of (syntactical) terms.
Use term operations to print terms and detect overlapping union
entries.
- Compute type sets corresponding to unions lazily, on demand.
- Adjust code throughout.
- Adjusted error check in test/typeparam/mincheck.dir/main.go
to make test pass.
Change-Id: Ib36fb7e1d343c2b6aec51d304f0f7d1ad415f999
Reviewed-on: https://go-review.googlesource.com/c/go/+/338310
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/interface.go')
-rw-r--r-- | src/cmd/compile/internal/types2/interface.go | 33 |
1 files changed, 2 insertions, 31 deletions
diff --git a/src/cmd/compile/internal/types2/interface.go b/src/cmd/compile/internal/types2/interface.go index fc1f5ffe00..aa7d0b05a0 100644 --- a/src/cmd/compile/internal/types2/interface.go +++ b/src/cmd/compile/internal/types2/interface.go @@ -21,20 +21,7 @@ type Interface struct { } // typeSet returns the type set for interface t. -func (t *Interface) typeSet() *TypeSet { return computeTypeSet(nil, nopos, t) } - -// is reports whether interface t represents types that all satisfy f. -func (t *Interface) is(f func(Type, bool) bool) bool { - switch t := t.typeSet().types.(type) { - case nil, *top: - // TODO(gri) should settle on top or nil to represent this case - return false // we must have at least one type! (was bug) - case *Union: - return t.is(func(t *term) bool { return f(t.typ, t.tilde) }) - default: - return f(t, false) - } -} +func (t *Interface) typeSet() *TypeSet { return computeInterfaceTypeSet(nil, nopos, t) } // emptyInterface represents the empty interface var emptyInterface = Interface{complete: true, tset: &topTypeSet} @@ -113,22 +100,6 @@ func (t *Interface) IsComparable() bool { return t.typeSet().IsComparable() } // IsConstraint reports whether interface t is not just a method set. func (t *Interface) IsConstraint() bool { return !t.typeSet().IsMethodSet() } -// isSatisfiedBy reports whether interface t's type list is satisfied by the type typ. -// If the type list is empty (absent), typ trivially satisfies the interface. -// TODO(gri) This is not a great name. Eventually, we should have a more comprehensive -// "implements" predicate. -func (t *Interface) isSatisfiedBy(typ Type) bool { - switch t := t.typeSet().types.(type) { - case nil: - return true // no type restrictions - case *Union: - r, _ := t.intersect(typ, false) - return r != nil - default: - return Identical(t, typ) - } -} - // Complete computes the interface's type set. It must be called by users of // NewInterfaceType and NewInterface after the interface's embedded types are // fully defined and before using the interface type in any way other than to @@ -262,7 +233,7 @@ func (check *Checker) interfaceType(ityp *Interface, iface *syntax.InterfaceType // Compute type set with a non-nil *Checker as soon as possible // to report any errors. Subsequent uses of type sets will use // this computed type set and won't need to pass in a *Checker. - check.later(func() { computeTypeSet(check, iface.Pos(), ityp) }) + check.later(func() { computeInterfaceTypeSet(check, iface.Pos(), ityp) }) } func flattenUnion(list []syntax.Expr, x syntax.Expr) []syntax.Expr { |