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/typestring.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/typestring.go')
-rw-r--r-- | src/cmd/compile/internal/types2/typestring.go | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/types2/typestring.go b/src/cmd/compile/internal/types2/typestring.go index b7e32c9860..558da50528 100644 --- a/src/cmd/compile/internal/types2/typestring.go +++ b/src/cmd/compile/internal/types2/typestring.go @@ -158,9 +158,10 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) { writeSignature(buf, t, qf, visited) case *Union: - if t.IsEmpty() { - buf.WriteString("⊥") - break + // Unions only appear as (syntactic) embedded elements + // in interfaces and syntactically cannot be empty. + if t.NumTerms() == 0 { + panic("internal error: empty union") } for i, t := range t.terms { if i > 0 { @@ -198,13 +199,21 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) { writeSignature(buf, m.typ.(*Signature), qf, visited) empty = false } - if !empty && tset.types != nil { + if !empty && tset.hasTerms() { buf.WriteString("; ") } - if tset.types != nil { - buf.WriteString("type ") - writeType(buf, tset.types, qf, visited) - } + first := true + tset.is(func(t *term) bool { + if !first { + buf.WriteByte('|') + } + first = false + if t.tilde { + buf.WriteByte('~') + } + writeType(buf, t.typ, qf, visited) + return true + }) } else { // print explicit interface methods and embedded types for i, m := range t.methods { |